Receiving Direct Messages
Direct messages can be delivered to a client in a session when the event broker has matching topic subscriptions for that client. For the client to receive the messages, it must use a message receive interface or callback/delegate appropriate for the programming language used.
Solace JavaScript API and Solace Node.js API
Direct messages are received through a message listener defined for the session for the solace.SessionEventCode.MESSAGE event. The message receive callback is set using solace.Session.subscribe(...).
Message Discard Indications
A receiving client can use a message discard indication method or function to query whether the event broker has for any reason discarded any Direct messages previous to the current received message. If the call returns true, the event broker has discarded one or more messages prior to the current message; if the call returns false, no messages prior to the current message were lost.
When a client application detects a message discard has occurred, it should handle this event appropriately. For example, it can follow its regular session re‑initialization procedure.
- Message discards can occur if an event broker's egress per-client priority queues fill up with received messages. When this occurs, the oldest messages on the queues can be discarded to allow new incoming messages to be enqueued. Egress per-client priority queues could fill up in a situation where there are slow subscriber (that is, clients that are not consuming messages quickly enough). For more information on egress per-client priority queues and how to configure them, see Message Delivery Resources.
- It is recommended that consuming clients do not use discard indications when using message eliding. In a situation where an event broker's egress priority queue for a client fills up with received messages, the oldest messages on the egress queue are discarded to make room for newly arriving messages, and the message at the head of the queue is flagged with the discard indication. However, if eliding is enabled, that message could be elided, and the client would not receive the discard indication.
To query whether messages have been discarded, call solace.Message.isDiscardIndication().
Replying to Request Messages
To reply to an incoming request message, an application can call one of the methods listed below and provide the request message that is being replied to and the message contents to reply with. Typically, the ReplyTo address and a correlation ID for the reply message are provided by the received request message. The reply method or function automatically sets a single bit response attribute, and it uses a correlation ID that matches that of the incoming request message.
For information on sending request messages, see Publishing Messages that Request Replies.
To send reply messages, call solace.SessionsendReply(...).
Related Samples
For an example of how to send and receive request/reply messages, see the BasicRequestor and BasicReplier samples for the Solace JavaScript API and Solace Node.js API.