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 Java RTO, C, and .NET APIs, and the TopicSubscriber and TopicPublisher samples for the JavaScript and Node.js APIs.

Blocking and Non-blocking Network I/O

The Java RTO, C, and .NET APIs 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

PubSub+ Messaging API Use

Java RTO

SessionHandle.send(...)

C

solClient_session_sendMsg(...)

.NET

ISession.Send(...)

JavaScript and Node.js

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).

Java RTO, C, and .NET APIs

When using the Java RTO, C, or .NET APIs, 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 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

PubSub+ Messaging API Use

Java RTO

SessionHandle.send(...)

C

solClient_session_sendMultipleMsg(...)

.NET

ISession.Send(...)

JavaScript and Node.js

Not supported

Related Samples

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