The following example gives a brief demonstration for connecting, sending and receiving a message using NMS.

Sync NMS Example

Asynchronous consumption

You have the choice of synchronously pulling messages via the Receive() methods as shown above, or you can use the asynchronous approach demonstrated in the following example:

Async NMS Example

The above uses a C# delegate so that the OnMessage() method will be called whenever a message arrives.

Note that the threading contract is similar to that of JMS - messages are dispatched for a single session's consumers in one thread at once. Consumers in different sessions can process messages concurrently, but consumers in the same session are guarenteed to be called by only one thread at a time (e.g., if you have 3 consumers on a session, then only one of the consumers will be called concurrently).

© 2004-2011 The Apache Software Foundation.
Apache ActiveMQ, ActiveMQ, Apache, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram