A receiver can only read from one source, but many programs need to be able to read messages from many sources. In the Qpid Messaging API, a program can ask a session for the “next receiver”; that is, the receiver that is responsible for the next available message. The following examples show how this is done in C++, Python, and .NET C#.
Note that to use this pattern you must enable prefetching for each receiver of interest so that the broker will send messages before a fetch call is made. See Section 1.6, “Receiver Capacity (Prefetch)” for more on this.
Example 1.12. Receiving Messages from Multiple Sources
C++:
Receiver receiver1 = session.createReceiver(address1); receiver1.setCapacity(10); Receiver receiver2 = session.createReceiver(address2); receiver2.setCapacity(10); Message message = session.nextReceiver().fetch(); std::cout << message.getContent() << std::endl; session.acknowledge(); // acknowledge message receipt
Python:
receiver1 = session.receiver(address1) receiver1.capacity = 10 receiver2 = session.receiver(address) receiver2.capacity = 10 message = session.next_receiver().fetch() print message.content session.acknowledge()
.NET C#:
Receiver receiver1 = session.CreateReceiver(address1); receiver1.Capacity = 10; Receiver receiver2 = session.CreateReceiver(address2); receiver2.Capacity = 10; Message message = new Message(); message = session.NextReceiver().Fetch(); Console.WriteLine("{0}", message.GetContent()); session.Acknowledge();
Apache Qpid, Messaging built on AMQP; Copyright © 2015 The Apache Software Foundation; Licensed under the Apache License, Version 2.0; Apache Qpid, Qpid, Qpid Proton, Proton, Apache, the Apache feather logo, and the Apache Qpid project logo are trademarks of The Apache Software Foundation; All other marks mentioned may be trademarks or registered trademarks of their respective owners