Universal Messaging 10.3 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Messaging API | MyChannels.Nirvana API: Consumers
MyChannels.Nirvana API: Consumers
Consumers are the main means of consuming messages when using the MyChannels.Nirvana API. They allow simple consumption of messages from both Topics and Queues. A Consumer is created using the CreateConsumer() method in either Session.Queues or Session.Topics, depending upon which type of Consumer is desired.
The Consumer's MessageReceived event is fired whenever a message is received by the Topic or Queue being consumed. By attaching an appropriate handler, the message can be dealt with in whatever way is desired.

IConsumer consumer = session.Queues.CreateConsumer("Queue1");
consumer.MessageReceived += (s, e) => ProcessMessage(e.Message);

IConsumer consumer = session.Topics.CreateConsumer("Topic1");
consumer.MessageReceived += (s, e) => ProcessMessage(e.Message);
Consuming messages when using DataGroups is even simpler than when using Topics or Queues. The Session.DataGroups object itself has a MessageReceived event, which can be used in the same manner as above to handle incoming messages.

session.DataGroups += (s, e) => ProcessMessage(e.Message);