zeromq - messaging for many applications - p. hintjens (o'reilly, 2013) [ecv] ww

745 1.1K 0
zeromq - messaging for many applications - p. hintjens (o'reilly, 2013) [ecv] ww

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... Sebastopol, CA 95472 80 0-9 9 8-9 938 (in the United States or Canada) 70 7-8 2 9-0 515 (international or local) 70 7-8 2 9-0 104 (fax) We have a web page for this book, where we list errata, examples, and any additional information You can access this page at http://bit.ly /ZeroMQ- OReilly To comment or ask technical questions about this book, send email to bookquestions@oreilly.com For more information about our books,... the title, author, publisher, and ISBN For example: ZeroMQ by Pieter Hintjens (O’Reilly) Copyright 2013 Pieter Hintjens, 97 8-1 -4 4 9-3 340 6-2 .” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com Safari® Books Online NOTE Safari Books Online (www.safaribooksonline.com) is an on-demand digital library that delivers... 1950s-era cosmic rays, and put it into the hands of a drug-addled comic book author with a badly disguised fetish for bulging muscles clad in spandex (Figure 1-2 ) Yes, ØMQ sockets are the world-saving superheroes of the networking world Figure 1-2 There was a terrible accident You could throw thousands of clients at this server, all at once, and it would continue to work happily and quickly For fun,... website at http://www.oreilly.com Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Acknowledgments Thanks to Andy Oram for making this happen at O’Reilly and editing the book Thanks to Bill Desmarais, Brian Dorsey, Daniel Lin, Eric Desgranges, Gonzalo Diethelm, Guido Goldstein, Hunter Ford, Kamil... the request-reply pattern, probably the simplest way to use ØMQ It maps to RPC (remote procedure calls) and the classic client/server model A Minor Note on Strings ØMQ doesn’t know anything about the data you send except its size in bytes That means you are responsible for formatting it safely so that applications can read it back Doing this for objects and complex data types is a job for specialized... (215) - 80; relhumidity = randof (50) + 10; // Send message to all subscribers char update [20]; sprintf (update, "%05d %d %d", zipcode, temperature, relhumidity); s_send (publisher, update); } zmq_close (publisher); zmq_ctx_destroy (context); return 0; } There’s no start and no end to this stream of updates; it’s like a never-ending broadcast (Figure 1-4 ) Figure 1-4 Publish-subscribe Example 1-7 shows... connecting applications using raw UDP and TCP, proprietary protocols, HTTP, and WebSockets It remains painful, slow, hard to scale, and essentially centralized Distributed peer-to-peer architectures are mostly for play, not work How many applications use Skype or BitTorrent to exchange data? Which brings us back to the science of programming To fix the world, we needed to do two things One, to solve the general... Palli, and Zed Shaw for their contributions to this work Thanks to Martin Sustrik for his years of incredible work on ZeroMQ Thanks to Stathis Sideris for Ditaa Part I Learning to Work with ØMQ In the first part of this book, you’ll learn how to use ØMQ We’ll cover the basics, the API, the different socket types and how they work, reliability, and a host of patterns you can use in your applications You’ll... we end zmq_close (responder); zmq_ctx_destroy (context); return 0; } Figure 1-1 Request-reply The REQ-REP socket pair is in lockstep The client issues zmq_msg_send() and then zmq_msg_recv(), in a loop (or once if that’s all it needs) Any other sequence (e.g., sending two messages in a row) will result in a return code of -1 from the send or recv call Similarly, the server issues zmq_msg_recv() and... as it needs to ØMQ uses C as its reference language, and this is the main language we’ll use for examples If you’re reading this online, the link below the example takes you to translations into other programming languages For print readers, Example 1-2 shows what the same server looks like in C++ Example 1-2 Hello World server (hwserver.cpp) // // Hello World server in C++ // Binds REP socket to tcp://*:5555 . across various transports, like in-process, inter-process, TCP, and multicast. You can connect sock- ets N-to-N with patterns like fan-out, pub-sub, task distribution, and request-reply. It’s fast enough. the title, author, publisher, and ISBN. For example: ZeroMQ by Pieter Hintjens (O’Reilly). Copyright 2013 Pieter Hintjens, 97 8-1 -4 4 9-3 340 6-2 .” If you feel your use of code examples falls outside. big servers and thin, stupid clients. So today people are still connecting applications using raw UDP and TCP, proprietary proto- cols, HTTP, and WebSockets. It remains painful, slow, hard to scale,

Ngày đăng: 03/05/2014, 18:50

Từ khóa liên quan

Mục lục

  • ZeroMQ

    • Pieter Hintjens

    • Special Upgrade Offer

    • Preface

    • ØMQ in a Hundred Words

    • The Zen of Zero

    • How This Book Came to Be

    • Audience

    • Conventions Used in This Book

      • Tip

      • Using the Code Examples

      • Safari® Books Online

        • Note

        • How to Contact Us

        • Acknowledgments

        • Part I. Learning to Work with ØMQ

        • Chapter 1. Basics

        • Fixing the World

        • Audience for This Book

        • Getting the Examples

        • Ask and Ye Shall Receive

        • A Minor Note on Strings

        • Version Reporting

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan