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 C API.

Blocking and Non-blocking Network I/O

The Solace C 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, use the solClient_session_sendMsg(...) function.

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 C API

When using the Solace C 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 C 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 parameter. The application can reattempt to send the messages that were not accepted or take another action.

To publish a group of messages, use the solClient_session_sendMultipleMsg(...) function.

Related Samples

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