Sending Direct Messages

When sending a Direct message, client applications must consider the following factors:

Related Samples

For examples of how to publish and receive Direct messages, see the DirectPubSub sample for the Solace Java RTO API, Solace C API, and Solace .NET API, and the TopicSubscriber and TopicPublisher samples for the Solace JavaScript API and Solace Node.js API.

Blocking and Non-blocking Network I/O

The Solace Java RTO API, Solace C API, and Solace .NET API can use a blocking or non‑blocking network I/O model for send operations. This is controlled by the send blocking session property. By default, this property is set to true, so that a blocking mode is used.

When the send blocking session property is set to false, a non-blocking mode is used. If the OS/network cannot send the whole message without blocking the calling thread until more buffer space is available, the client application gets a WOULD_BLOCK return code. When a WOULD_BLOCK return code is received, the message is not sent and the client application must wait for a CAN_SEND Session event, which indicates that the network is then ready for the send.

Sending One Message at a Time

To publish a single message per API call, call one of the send methods or functions listed below.

To Publish Messages

Solace Messaging API Use

Solace Java RTO API

SessionHandle.send(...)

Solace C API

solClient_session_sendMsg(...)

Solace .NET API

ISession.Send(...)

Solace JavaScript API and Solace Node.js API

solace.Session.send(...)

Sending Multiple Messages at a Time

A group of Direct messages can be sent through a single API call. This allows messages to be sent in a batch or a vector. The messages to be sent are specified as an array; up to fifty messages can be sent through the call.

When batch sending messages, a Direct delivery mode should be set for all of the messages (see Delivery Mode).

Solace Java RTO API, Solace C API, and Solace .NET API

When using the Solace Java RTO API, Solace C API, or Solace .NET API, an array of messages must be passed in. Message destinations are not set through a send method; rather, they are set as a property for each message.

When a blocking mode is configured for the session through the session properties, the call blocks until all messages can be accepted by the Solace Messaging API. If a non‑blocking mode is configured, and the API cannot accept all messages to publish, SOLCLIENT_WOULD_BLOCK is returned, and the number of messages that were accepted is returned in the in_out_howManySent, numberOfMessagesWritten, or messagesSent parameter. The application can reattempt to send the messages that were not accepted or take another action.

To Publish a Group of Messages

Solace Messaging API Use

Solace Java RTO API

SessionHandle.send(...)

Solace C API

solClient_session_sendMultipleMsg(...)

Solace .NET API

ISession.Send(...)

Solace JavaScript API and Solace Node.js API

Not supported

Related Samples

For examples of how to publish a group of messages, see the PerfTest sample for the appropriate Solace Messaging API.