Threading When Receiving Messages

When receiving published messages, the context uses a processing thread to read messages off the socket, parse them, and then, depending on the messaging API and whether a synchronous or asynchronous mode is used, enqueue the messages for delivery or consumption, or perform customer notification and message dispatch.

Client applications can use one of the following modes to receive published messages:

  • Synchronous

    The Java RTO, C, and .NET APIs can only receive messages asynchronously. Client applications can use the PubSub+ JCSMP APIto receive published messages synchronously. See Receiving Messages Synchronously.

Receiving Messages Asynchronously

A client application can use the Java RTO, C, and .NET APIs to receive messages in an asynchronous manner. That is, when messages are available, they are automatically sent (“pushed”) to a message callback or message delegate interface from the API to the client application.

When receiving messages asynchronously, the context uses a processing thread for consumer notification and dispatching the queued messages to consumers; all callbacks from the API to the application, such as message receive callbacks, event callbacks, and timer callbacks, run from a context thread.

When a client application is using asynchronous transacted sessions, messages are dispatched from one or more transacted session dispatcher threads. Either a single transacted session dispatcher thread that is bound to the context (this is the default) or separate transacted session dispatcher threads that are that are bound to each transacted session can be used. For more information, see Using Local Transactions.

Java RTO, C, and .NET APIs

Contexts used by the Java RTO, C, and .NET APIs asynchronously receive messages in a way similar to that used by JCSMP when the MESSAGE_CALLBACK_ON_REACTOR session property is enabled. The Java RTO, C, and .NET APIs only use one processing thread for the context. This thread reads messages off the socket, parses them, and then performs consumer notification and dispatches the messages to consuming applications.

For the C API, the required context thread can optionally be supplied by the client application instead of relying on the internal API thread. See C API Best Practices.

The figure below shows shows the context thread that is used to receive messages asynchronously through the Java RTO, C, and .NET APIs.

Receiving Messages Asynchronously With the Java RTO, C, and .NET APIs

Receiving Messages Synchronously

The Java RTO, C, and .NET APIs can only receive messages asynchronously.