6. Receiving Messages from Multiple Sources

A receiver can only read from one source, but many programs need to be able to read messages from many sources, preserving the original sequence of the messages. 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 example shows how this is done in C++, Python, and .NET C#.

Example 2.12. Receiving Messages from Multiple Sources

C++:

Receiver receiver1 = session.createReceiver(address1);
Receiver receiver2 = session.createReceiver(address2);

Message message =  session.nextReceiver().fetch();
session.acknowledge(); // acknowledge message receipt
std::cout << message.getContent() << std::endl;
	  

Python:

receiver1 = session.receiver(address1)
receiver2 = session.receiver(address)
message = session.next_receiver().fetch()
print message.content
	  

.NET C#:

Receiver receiver1 = session.CreateReceiver(address1);
Receiver receiver2 = session.CreateReceiver(address2);

Message message = new Message();
message =  session.NextReceiver().Fetch();
session.Acknowledge();
Console.WriteLine("{0}", message.GetContent());