Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to js_PublishAsync #538

Closed
pramodsri opened this issue Apr 28, 2022 · 0 comments · Fixed by #551
Closed

Enhancements to js_PublishAsync #538

pramodsri opened this issue Apr 28, 2022 · 0 comments · Fixed by #551

Comments

@pramodsri
Copy link

/** \brief Publishes data to JetStream but does not wait for a #jsPubAck.
 *
 * See #js_PublishMsgAsync for details.
 *
 * @param js the pointer to the #jsCtx object.
 * @param subj the subject the data is sent to.
 * @param data the data to be sent, can be `NULL`.
 * @param dataLen the length of the data to be sent.
 * @param opts the publish options, possibly `NULL`.
 */
NATS_EXTERN natsStatus
js_PublishAsync(jsCtx *js, const char *subj, const void *data, int dataLen,
                jsPubOptions *opts);

The current signature of js_PublishAsync does not provide a mechanism for a positive ack and does not call the jsOpts.PublishAsync.ErrHandler in the following scenario

>> natsConnection_Connect
>> natsConnection_JetStream
>> sleep (shutdown the server from another shell)
>> js_PublishAsync return NATS_OK
>> jsOpts.PublishAsync.ErrHandler does NOT get called

This issue will track the changes needed to support the following requests:

  1. Call jsOpts.PublishAsync.ErrHandler on timeout, the timeout can be set through jsPubOptions.MaxWait
  2. Provide parity with Go PublishAsync API by supporting positive ack (along the lines of stanConnection_PublishAsync)
/* 
 * 's' can be NATS_OK, NATS_TIMEOUT or any other error due to async publish.
 * 'msg' handle, it is apps responsibility to free the msg
 */
typedef void (*jsPubAckHandler)(natsStatus s, natsMsg *msg, void *closure);
 
/* 
 * jsPubOptions.MaxWait can be used to control the timeout for the ack handler
 * 'ah' is called on success, async publish error or timeout
 */
NATS_EXTERN natsStatus
js_PublishAsyncAck(jsCtx *js, const char *subj, const void *data, int dataLen,
                jsPubOptions *opts, jsPubAckHandler ah, void *ahClosure);

Thanks for the help !!

kozlovic added a commit that referenced this issue Jul 6, 2022
[FIXED] Ability to have async publish call timeout and invoke err handler

The new jsPubAckHandler takes precedence and is invoked even on
successful publish.

If the option MaxWait is specified on publish, then the library
will invoke the ack handler (or err handler) if a publish ack
is not received by then.

Resolves #538

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant