NATS C Client with JetStream and Streaming support  3.9.1
The nats.io C Client, Supported by Synadia Communications Inc.
Publishing

Functions

NATS_EXTERN natsStatus natsConnection_Publish (natsConnection *nc, const char *subj, const void *data, int dataLen)
 Publishes data on a subject. More...
 
NATS_EXTERN natsStatus natsConnection_PublishString (natsConnection *nc, const char *subj, const char *str)
 Publishes a string on a subject. More...
 
NATS_EXTERN natsStatus natsConnection_PublishMsg (natsConnection *nc, natsMsg *msg)
 Publishes a message on a subject. More...
 
NATS_EXTERN natsStatus natsConnection_PublishRequest (natsConnection *nc, const char *subj, const char *reply, const void *data, int dataLen)
 Publishes data on a subject expecting replies on the given reply. More...
 
NATS_EXTERN natsStatus natsConnection_PublishRequestString (natsConnection *nc, const char *subj, const char *reply, const char *str)
 Publishes a string on a subject expecting replies on the given reply. More...
 
NATS_EXTERN natsStatus natsConnection_Request (natsMsg **replyMsg, natsConnection *nc, const char *subj, const void *data, int dataLen, int64_t timeout)
 Sends a request and waits for a reply. More...
 
NATS_EXTERN natsStatus natsConnection_RequestString (natsMsg **replyMsg, natsConnection *nc, const char *subj, const char *str, int64_t timeout)
 Sends a request (as a string) and waits for a reply. More...
 
NATS_EXTERN natsStatus natsConnection_RequestMsg (natsMsg **replyMsg, natsConnection *nc, natsMsg *requestMsg, int64_t timeout)
 Sends a request based on the given requestMsg and waits for a reply. More...
 

Detailed Description

Publishing functions

Function Documentation

◆ natsConnection_Publish()

NATS_EXTERN natsStatus natsConnection_Publish ( natsConnection nc,
const char *  subj,
const void *  data,
int  dataLen 
)

Publishes the data argument to the given subject. The data argument is left untouched and needs to be correctly interpreted on the receiver.

Parameters
ncthe pointer to the natsConnection object.
subjthe subject the data is sent to.
datathe data to be sent, can be NULL.
dataLenthe length of the data to be sent.

◆ natsConnection_PublishString()

NATS_EXTERN natsStatus natsConnection_PublishString ( natsConnection nc,
const char *  subj,
const char *  str 
)

Convenient function to publish a string. This call is equivalent to:

const char* myString = "hello";
natsConnection_Publish(nc, subj, (const void*) myString, (int) strlen(myString));
NATS_EXTERN natsStatus natsConnection_Publish(natsConnection *nc, const char *subj, const void *data, int dataLen)
Publishes data on a subject.
Parameters
ncthe pointer to the natsConnection object.
subjthe subject the data is sent to.
strthe string to be sent.

◆ natsConnection_PublishMsg()

NATS_EXTERN natsStatus natsConnection_PublishMsg ( natsConnection nc,
natsMsg msg 
)

Publishes the natsMsg, which includes the subject, an optional reply and optional data.

See also
natsMsg_Create()
Parameters
ncthe pointer to the natsConnection object.
msgthe pointer to the natsMsg object to send.

◆ natsConnection_PublishRequest()

NATS_EXTERN natsStatus natsConnection_PublishRequest ( natsConnection nc,
const char *  subj,
const char *  reply,
const void *  data,
int  dataLen 
)

Publishes the data argument to the given subject expecting a response on the reply subject. Use natsConnection_Request() for automatically waiting for a response inline.

Parameters
ncthe pointer to the natsConnection object.
subjthe subject the request is sent to.
replythe reply on which resonses are expected.
datathe data to be sent, can be NULL.
dataLenthe length of the data to be sent.

◆ natsConnection_PublishRequestString()

NATS_EXTERN natsStatus natsConnection_PublishRequestString ( natsConnection nc,
const char *  subj,
const char *  reply,
const char *  str 
)

Convenient function to publish a request as a string. This call is equivalent to:

const char* myString = "hello";
natsPublishRequest(nc, subj, reply, (const void*) myString, (int) strlen(myString));
Parameters
ncthe pointer to the natsConnection object.
subjthe subject the request is sent to.
replythe reply on which resonses are expected.
strthe string to send.

◆ natsConnection_Request()

NATS_EXTERN natsStatus natsConnection_Request ( natsMsg **  replyMsg,
natsConnection nc,
const char *  subj,
const void *  data,
int  dataLen,
int64_t  timeout 
)

Sends a request payload and delivers the first response message, or an error, including a timeout if no message was received properly.

Warning
If connected to a NATS Server v2.2.0+ with no responder running when the request is received, this call will return a NATS_NO_RESPONDERS error.
Parameters
replyMsgthe location where to store the pointer to the received natsMsg reply.
ncthe pointer to the natsConnection object.
subjthe subject the request is sent to.
datathe data of the request, can be NULL.
dataLenthe length of the data to send.
timeoutin milliseconds, before this call returns NATS_TIMEOUT if no response is received in this alloted time.

◆ natsConnection_RequestString()

NATS_EXTERN natsStatus natsConnection_RequestString ( natsMsg **  replyMsg,
natsConnection nc,
const char *  subj,
const char *  str,
int64_t  timeout 
)

Convenient function to send a request as a string. This call is equivalent to:

const char* myString = "hello";
natsConnection_Request(replyMsg, nc, subj, (const void*) myString, (int) strlen(myString));
NATS_EXTERN natsStatus natsConnection_Request(natsMsg **replyMsg, natsConnection *nc, const char *subj, const void *data, int dataLen, int64_t timeout)
Sends a request and waits for a reply.
Warning
See warning about no responders in natsConnection_Request().
Parameters
replyMsgthe location where to store the pointer to the received natsMsg reply.
ncthe pointer to the natsConnection object.
subjthe subject the request is sent to.
strthe string to send.
timeoutin milliseconds, before this call returns NATS_TIMEOUT if no response is received in this alloted time.

◆ natsConnection_RequestMsg()

NATS_EXTERN natsStatus natsConnection_RequestMsg ( natsMsg **  replyMsg,
natsConnection nc,
natsMsg requestMsg,
int64_t  timeout 
)

Similar to natsConnection_Request but uses requestMsg to extract subject, and payload to send.

Warning
See warning about no responders in natsConnection_Request().
Parameters
replyMsgthe location where to store the pointer to the received natsMsg reply.
ncthe pointer to the natsConnection object.
requestMsgthe message used for the request.
timeoutin milliseconds, before this call returns NATS_TIMEOUT if no response is received in this alloted time.