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

Loading...
Searching...
No Matches
Functions
Publishing
Functions » Connection

## Functions
NATS_EXTERN natsStatus | natsConnection_Publish (natsConnection *nc, const char *subj, const void *data, int dataLen)
| Publishes data on a subject.
NATS_EXTERN natsStatus | natsConnection_PublishString (natsConnection *nc, const char *subj, const char *str)
| Publishes a string on a subject.
NATS_EXTERN natsStatus | natsConnection_PublishMsg (natsConnection *nc, natsMsg *msg)
| Publishes a message on a subject.
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.
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.
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.
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.
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.

## 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

  nc | the pointer to the natsConnection object.
  subj | the subject the data is sent to.
  data | the data to be sent, can be `NULL`.
  dataLen | the 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));
natsConnection_Publish
NATS_EXTERN natsStatus natsConnection_Publish(natsConnection *nc, const char *subj, const void *data, int dataLen)
Publishes data on a subject.

Parameters

  nc | the pointer to the natsConnection object.
  subj | the subject the data is sent to.
  str | the 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

  nc | the pointer to the natsConnection object.
  msg | the 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

  nc | the pointer to the natsConnection object.
  subj | the subject the request is sent to.
  reply | the reply on which resonses are expected.
  data | the data to be sent, can be `NULL`.
  dataLen | the 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

  nc | the pointer to the natsConnection object.
  subj | the subject the request is sent to.
  reply | the reply on which resonses are expected.
  str | the 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

  replyMsg | the location where to store the pointer to the received natsMsg reply.
  nc | the pointer to the natsConnection object.
  subj | the subject the request is sent to.
  data | the data of the request, can be `NULL`.
  dataLen | the length of the data to send.
  timeout | in 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));
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 and waits for a reply.

Warning
  See warning about no responders in natsConnection_Request().

Parameters

  replyMsg | the location where to store the pointer to the received natsMsg reply.
  nc | the pointer to the natsConnection object.
  subj | the subject the request is sent to.
  str | the string to send.
  timeout | in 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

  replyMsg | the location where to store the pointer to the received natsMsg reply.
  nc | the pointer to the natsConnection object.
  requestMsg | the message used for the request.
  timeout | in milliseconds, before this call returns NATS_TIMEOUT if no response is received in this alloted time.