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

Functions

NATS_EXTERN natsStatus natsConnection_Subscribe (natsSubscription **sub, natsConnection *nc, const char *subject, natsMsgHandler cb, void *cbClosure)
 Creates an asynchronous subscription. More...
 
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. More...
 
NATS_EXTERN natsStatus natsConnection_SubscribeSync (natsSubscription **sub, natsConnection *nc, const char *subject)
 Creates a synchronous subcription. More...
 
NATS_EXTERN natsStatus natsConnection_QueueSubscribe (natsSubscription **sub, natsConnection *nc, const char *subject, const char *queueGroup, natsMsgHandler cb, void *cbClosure)
 Creates an asynchronous queue subscriber. More...
 
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. More...
 
NATS_EXTERN natsStatus natsConnection_QueueSubscribeSync (natsSubscription **sub, natsConnection *nc, const char *subject, const char *queueGroup)
 Creates a synchronous queue subscriber. More...
 

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
subthe location where to store the pointer to the newly created natsSubscription object.
ncthe pointer to the natsConnection object.
subjectthe subject this subscription is created for.
cbthe natsMsgHandler callback.
cbClosurea 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
subthe location where to store the pointer to the newly created natsSubscription object.
ncthe pointer to the natsConnection object.
subjectthe subject this subscription is created for.
timeoutthe interval (in milliseconds) after which, if no message is received, the message handler is invoked with a NULL message.
cbthe natsMsgHandler callback.
cbClosurea 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
subthe location where to store the pointer to the newly created natsSubscription object.
ncthe pointer to the natsConnection object.
subjectthe 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
subthe location where to store the pointer to the newly created natsSubscription object.
ncthe pointer to the natsConnection object.
subjectthe subject this subscription is created for.
queueGroupthe name of the group.
cbthe natsMsgHandler callback.
cbClosurea 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
subthe location where to store the pointer to the newly created natsSubscription object.
ncthe pointer to the natsConnection object.
subjectthe subject this subscription is created for.
queueGroupthe name of the group.
timeoutthe interval (in milliseconds) after which, if no message is received, the message handler is invoked with a NULL message.
cbthe natsMsgHandler callback.
cbClosurea 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
subthe location where to store the pointer to the newly created natsSubscription object.
ncthe pointer to the natsConnection object.
subjectthe subject this subscription is created for.
queueGroupthe name of the group.