NATS C Client with JetStream and Streaming support
3.9.1
The nats.io C Client, Supported by Synadia Communications Inc.
|
Functions | |
NATS_EXTERN void | natsMsgList_Destroy (natsMsgList *list) |
Destroys this list of messages. More... | |
NATS_EXTERN natsStatus | natsMsg_Create (natsMsg **newMsg, const char *subj, const char *reply, const char *data, int dataLen) |
Creates a natsMsg object. More... | |
NATS_EXTERN const char * | natsMsg_GetSubject (const natsMsg *msg) |
Returns the subject set in this message. More... | |
NATS_EXTERN const char * | natsMsg_GetReply (const natsMsg *msg) |
Returns the reply set in this message. More... | |
NATS_EXTERN const char * | natsMsg_GetData (const natsMsg *msg) |
Returns the message payload. More... | |
NATS_EXTERN int | natsMsg_GetDataLength (const natsMsg *msg) |
Returns the message length. More... | |
NATS_EXTERN natsStatus | natsMsgHeader_Set (natsMsg *msg, const char *key, const char *value) |
Set the header entries associated with key to the single element value . More... | |
NATS_EXTERN natsStatus | natsMsgHeader_Add (natsMsg *msg, const char *key, const char *value) |
Add value to the header associated with key . More... | |
NATS_EXTERN natsStatus | natsMsgHeader_Get (natsMsg *msg, const char *key, const char **value) |
Get the header entry associated with key . More... | |
NATS_EXTERN natsStatus | natsMsgHeader_Values (natsMsg *msg, const char *key, const char ***values, int *count) |
Get all header values associated with key . More... | |
NATS_EXTERN natsStatus | natsMsgHeader_Keys (natsMsg *msg, const char ***keys, int *count) |
Get all header keys. More... | |
NATS_EXTERN natsStatus | natsMsgHeader_Delete (natsMsg *msg, const char *key) |
Delete the value(s) associated with key . More... | |
NATS_EXTERN bool | natsMsg_IsNoResponders (natsMsg *msg) |
Indicates if this message is a "no responders" message from the server. More... | |
NATS_EXTERN void | natsMsg_Destroy (natsMsg *msg) |
Destroys the message object. More... | |
NATS Message.
NATS_EXTERN void natsMsgList_Destroy | ( | natsMsgList * | list | ) |
This function iterates through the list of all messages and call natsMsg_Destroy for each valid (not set to NULL
) message. It then frees the array that was allocated to hold pointers to those messages.
list | the natsMsgList list of natsMsg objects to destroy. |
NATS_EXTERN natsStatus natsMsg_Create | ( | natsMsg ** | newMsg, |
const char * | subj, | ||
const char * | reply, | ||
const char * | data, | ||
int | dataLen | ||
) |
Creates a natsMsg object. This is used by the subscription related calls and by natsConnection_PublishMsg().
newMsg | the location where to store the pointer to the newly created natsMsg object. |
subj | the subject this message will be sent to. Cannot be NULL . |
reply | the optional reply for this message. |
data | the optional message payload. |
dataLen | the size of the payload. |
NATS_EXTERN const char* natsMsg_GetSubject | ( | const natsMsg * | msg | ) |
Returns the subject set on that message.
msg | the pointer to the natsMsg object. |
NATS_EXTERN const char* natsMsg_GetReply | ( | const natsMsg * | msg | ) |
Returns the reply, possibly NULL
.
msg | the pointer to the natsMsg object. |
NATS_EXTERN const char* natsMsg_GetData | ( | const natsMsg * | msg | ) |
Returns the message payload, possibly NULL
.
Note that although the data sent and received from the server is not NULL
terminated, the NATS C Client does add a NULL
byte to the received payload. If you expect the received data to be a "string", then this conveniently allows you to call natsMsg_GetData() without having to copy the returned data to a buffer to add the NULL
byte at the end.
msg | the pointer to the natsMsg object. |
NATS_EXTERN int natsMsg_GetDataLength | ( | const natsMsg * | msg | ) |
Returns the message's payload length, possibly 0.
msg | the pointer to the natsMsg object. |
NATS_EXTERN natsStatus natsMsgHeader_Set | ( | natsMsg * | msg, |
const char * | key, | ||
const char * | value | ||
) |
It will replace any existing value associated with key
.
key
was stored in its canonical form, this is no longer the case. Header keys are now case sensitive.natsMsg
may possible be altered during this call.msg | the pointer to the natsMsg object. |
key | the key under which the value will be stored. It can't ne NULL or empty. |
value | the string to store under the given key . The value can be NULL or empty string. |
NATS_EXTERN natsStatus natsMsgHeader_Add | ( | natsMsg * | msg, |
const char * | key, | ||
const char * | value | ||
) |
It will append to any existing values associated with key
.
key
was stored in its canonical form, this is no longer the case. Header keys are now case sensitive.natsMsg
may possible be altered during this call.msg | the pointer to the natsMsg object. |
key | the key under which the value will be stored. It can't ne NULL or empty. |
value | the string to add to the values associated with the given key . The value can be NULL or empty string. |
NATS_EXTERN natsStatus natsMsgHeader_Get | ( | natsMsg * | msg, |
const char * | key, | ||
const char ** | value | ||
) |
If more than one entry for the key
is available, the first is returned. The returned value is owned by the library and MUST not be freed or altered.
key
was stored in its canonical form, this is no longer the case. Header keys are now case sensitive.natsMsg
may possible be altered during this call.msg | the pointer to the natsMsg object. |
key | the key for which the value is requested. |
value | the memory location where the library will store the pointer to the first value (if more than one is found) associated with the key . |
key
is not present in the headers. NATS_EXTERN natsStatus natsMsgHeader_Values | ( | natsMsg * | msg, |
const char * | key, | ||
const char *** | values, | ||
int * | count | ||
) |
The returned strings are own by the library and MUST not be freed or altered. However, the returned array values
MUST be freed by the user.
key
was stored in its canonical form, this is no longer the case. Header keys are now case sensitive.natsMsg
may possible be altered during this call.msg | the pointer to the natsMsg object. |
key | the key for which the values are requested. |
values | the memory location where the library will store the pointer to the array of values. |
count | the memory location where the library will store the number of values returned. |
key
is not present in the headers. NATS_EXTERN natsStatus natsMsgHeader_Keys | ( | natsMsg * | msg, |
const char *** | keys, | ||
int * | count | ||
) |
The returned strings are own by the library and MUST not be freed or altered. However, the returned array keys
MUST be freed by the user.
natsMsg
may possible be altered during this call.msg | the pointer to the natsMsg object. |
keys | the memory location where the library will store the pointer to the array of keys. |
count | the memory location where the library will store the number of keys returned. |
NATS_EXTERN natsStatus natsMsgHeader_Delete | ( | natsMsg * | msg, |
const char * | key | ||
) |
key
was stored in its canonical form, this is no longer the case. Header keys are now case sensitive.natsMsg
may possible be altered during this call.msg | the pointer to the natsMsg object. |
key | the key to delete from the headers map. |
key
is not present in the headers. NATS_EXTERN bool natsMsg_IsNoResponders | ( | natsMsg * | msg | ) |
Starting with the NATS Server v2.2.0+ and the C client v2.2.0+ releases, which introduced support for message headers and the "no responders" feature, if a request is received by the server and there are no subscriptions on the request's subject, the server sends a message with no payload but with a header "Status" with value "503".
The call natsConnection_Request() and its variants intercept this special message and instead of returning it to the user, they return NATS_NO_RESPONDERS.
If a synchronous subscription is created on a subject used as a reply subject to a natsConnection_PublishRequest call (and its variants), natsSubscription_NextMsg also detects this message and returns NATS_NO_RESPONDERS (but it was not from release v2.2.0 to v2.4.1).
For asynchronous subscriptions, the user may want to know that the request failed because there are no responders. For that reason, the message is passed to the message callback, and this function can be used to detect that this is a "no responders" message from the server and act accordingly.
msg | the pointer to the natsMsg object. |
true
if this message is a "no responders" message from the server, that is, has no payload and the "Status" header with "503" as the value. NATS_EXTERN void natsMsg_Destroy | ( | natsMsg * | msg | ) |
Destroys the message, freeing memory.
msg | the pointer to the natsMsg object to destroy. |