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
Subscribing
Functions » Connection

## Functions
NATS_EXTERN natsStatus | natsConnection_Subscribe (natsSubscription **sub, natsConnection *nc, const char *subject, natsMsgHandler cb, void *cbClosure)
| Creates an asynchronous subscription.
NATS_EXTERN natsStatus | natsConnection_SubscribeTimeout (natsSubscription **sub, natsConnection *nc, const char *subject, int64_t timeout, natsMsgHandler cb, void *cbClosure)
| Creates an asynchronous subscription with a timeout.
NATS_EXTERN natsStatus | natsConnection_SubscribeSync (natsSubscription **sub, natsConnection *nc, const char *subject)
| Creates a synchronous subcription.
NATS_EXTERN natsStatus | natsConnection_QueueSubscribe (natsSubscription **sub, natsConnection *nc, const char *subject, const char *queueGroup, natsMsgHandler cb, void *cbClosure)
| Creates an asynchronous queue subscriber.
NATS_EXTERN natsStatus | natsConnection_QueueSubscribeTimeout (natsSubscription **sub, natsConnection *nc, const char *subject, const char *queueGroup, int64_t timeout, natsMsgHandler cb, void *cbClosure)
| Creates an asynchronous queue subscriber with a timeout.
NATS_EXTERN natsStatus | natsConnection_QueueSubscribeSync (natsSubscription **sub, natsConnection *nc, const char *subject, const char *queueGroup)
| Creates a synchronous queue subscriber.

## Detailed Description

Subscribing functions.

## Function Documentation

## ◆ natsConnection_Subscribe()

NATS_EXTERN natsStatus natsConnection_Subscribe | ( | natsSubscription ** | sub,
|  | natsConnection * | nc,
|  | const char * | subject,
|  | natsMsgHandler | cb,
|  | void * | cbClosure
| ) |  |

Expresses interest in the given subject. The subject can have wildcards (see Wildcards). Messages will be delivered to the associated natsMsgHandler.

Parameters

  sub | the location where to store the pointer to the newly created natsSubscription object.
  nc | the pointer to the natsConnection object.
  subject | the subject this subscription is created for.
  cb | the natsMsgHandler callback.
  cbClosure | a pointer to an user defined object (can be `NULL`). See the natsMsgHandler prototype.

## ◆ natsConnection_SubscribeTimeout()

NATS_EXTERN natsStatus natsConnection_SubscribeTimeout | ( | natsSubscription ** | sub,
|  | natsConnection * | nc,
|  | const char * | subject,
|  | int64_t | timeout,
|  | natsMsgHandler | cb,
|  | void * | cbClosure
| ) |  |

Expresses interest in the given subject. The subject can have wildcards (see Wildcards). Messages will be delivered to the associated natsMsgHandler.

If no message is received by the given timeout (in milliseconds), the message handler is invoked with a `NULL` message.
You can then destroy the subscription in the callback, or simply return, in which case, the message handler will fire again when a message is received or the subscription times-out again.

Note
  Receiving a message reset the timeout. Until all pending messages are processed, no timeout will occur. The timeout starts when the message handler for the last pending message returns.

Warning
  If you re-use message handler code between subscriptions with and without timeouts, keep in mind that the message passed in the message handler may be `NULL`.

Parameters

  sub | the location where to store the pointer to the newly created natsSubscription object.
  nc | the pointer to the natsConnection object.
  subject | the subject this subscription is created for.
  timeout | the interval (in milliseconds) after which, if no message is received, the message handler is invoked with a `NULL` message.
  cb | the natsMsgHandler callback.
  cbClosure | a pointer to an user defined object (can be `NULL`). See the natsMsgHandler prototype.

## ◆ natsConnection_SubscribeSync()

NATS_EXTERN natsStatus natsConnection_SubscribeSync | ( | natsSubscription ** | sub,
|  | natsConnection * | nc,
|  | const char * | subject
| ) |  |

Similar to natsConnection_Subscribe, but creates a synchronous subscription that can be polled via natsSubscription_NextMsg().

Parameters

  sub | the location where to store the pointer to the newly created natsSubscription object.
  nc | the pointer to the natsConnection object.
  subject | the subject this subscription is created for.

## ◆ natsConnection_QueueSubscribe()

NATS_EXTERN natsStatus natsConnection_QueueSubscribe | ( | natsSubscription ** | sub,
|  | natsConnection * | nc,
|  | const char * | subject,
|  | const char * | queueGroup,
|  | natsMsgHandler | cb,
|  | void * | cbClosure
| ) |  |

Creates an asynchronous queue subscriber on the given subject. All subscribers with the same queue name will form the queue group and only one member of the group will be selected to receive any given message asynchronously.

Parameters

  sub | the location where to store the pointer to the newly created natsSubscription object.
  nc | the pointer to the natsConnection object.
  subject | the subject this subscription is created for.
  queueGroup | the name of the group.
  cb | the natsMsgHandler callback.
  cbClosure | a pointer to an user defined object (can be `NULL`). See the natsMsgHandler prototype.

## ◆ natsConnection_QueueSubscribeTimeout()

NATS_EXTERN natsStatus natsConnection_QueueSubscribeTimeout | ( | natsSubscription ** | sub,
|  | natsConnection * | nc,
|  | const char * | subject,
|  | const char * | queueGroup,
|  | int64_t | timeout,
|  | natsMsgHandler | cb,
|  | void * | cbClosure
| ) |  |

Creates an asynchronous queue subscriber on the given subject. All subscribers with the same queue name will form the queue group and only one member of the group will be selected to receive any given message asynchronously.

If no message is received by the given timeout (in milliseconds), the message handler is invoked with a `NULL` message.
You can then destroy the subscription in the callback, or simply return, in which case, the message handler will fire again when a message is received or the subscription times-out again.

Note
  Receiving a message reset the timeout. Until all pending messages are processed, no timeout will occur. The timeout starts when the message handler for the last pending message returns.

Warning
  If you re-use message handler code between subscriptions with and without timeouts, keep in mind that the message passed in the message handler may be `NULL`.

Parameters

  sub | the location where to store the pointer to the newly created natsSubscription object.
  nc | the pointer to the natsConnection object.
  subject | the subject this subscription is created for.
  queueGroup | the name of the group.
  timeout | the interval (in milliseconds) after which, if no message is received, the message handler is invoked with a `NULL` message.
  cb | the natsMsgHandler callback.
  cbClosure | a pointer to an user defined object (can be `NULL`). See the natsMsgHandler prototype.

## ◆ natsConnection_QueueSubscribeSync()

NATS_EXTERN natsStatus natsConnection_QueueSubscribeSync | ( | natsSubscription ** | sub,
|  | natsConnection * | nc,
|  | const char * | subject,
|  | const char * | queueGroup
| ) |  |

Similar to natsConnection_QueueSubscribe, but creates a synchronous subscription that can be polled via natsSubscription_NextMsg().

Parameters

  sub | the location where to store the pointer to the newly created natsSubscription object.
  nc | the pointer to the natsConnection object.
  subject | the subject this subscription is created for.
  queueGroup | the name of the group.