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

## Functions

NATS_EXTERN natsStatus | stanConnection_Publish (stanConnection *sc, const char *channel, const void *data, int dataLen)
| Publishes data on a channel.
NATS_EXTERN natsStatus | stanConnection_PublishAsync (stanConnection *sc, const char *channel, const void *data, int dataLen, stanPubAckHandler ah, void *ahClosure)
| Asynchronously publishes data on a channel.

## Detailed Description

Publishing functions

## Function Documentation

## stanConnection_Publish()

NATS_EXTERN natsStatus stanConnection_Publish | ( | stanConnection * | sc,
|  | const char * | channel,
|  | const void * | data,
|  | int | dataLen
| ) |  |

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

Parameters

  sc | the pointer to the stanConnection object.
  channel | the channel name the data is sent to.
  data | the data to be sent, can be `NULL`.
  dataLen | the length of the data to be sent.

## stanConnection_PublishAsync()

NATS_EXTERN natsStatus stanConnection_PublishAsync | ( | stanConnection * | sc,
|  | const char * | channel,
|  | const void * | data,
|  | int | dataLen,
|  | stanPubAckHandler | ah,
|  | void * | ahClosure
| ) |  |

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

This function does not wait for an acknowledgment back from the server. Instead, the library will invoke the provided callback when that acknowledgment comes.

In order to correlate the acknowledgment with the published message, you can use the `ahClosure` since this will be passed to the stanPubAckHandler on every invocation. In other words, you should use a unique closure for each published message.

Parameters

  sc | the pointer to the natsConnection object.
  channel | the channel name the data is sent to.
  data | the data to be sent, can be `NULL`.
  dataLen | the length of the data to be sent.
  ah | the publish acknowledgment callback. If `NULL` the user will not be notified of the publish result.
  ahClosure | the closure the library will pass to the `ah` callback if one has been set.