2

I made a Go example for JetStream Walkthrough - NATS Docs at https://github.com/hnakamur/nats-stream-example/tree/2c834d7d967f024348fbaa478eae18e9749431ba.

As a next step of my experiments, I tried to make a Go example for Request-Reply Walkthrough - NATS Docs but on a JetStream stream instead of a non-JetStream stream. My attempt is https://github.com/hnakamur/nats-stream-example/commit/149243b8bd30974a592061cd9d0c3a9b7f3f30fc.

However as soon as I ran my request subcommand, I got replies like msg.Data={"stream":"my_stream2", "seq":112}, even though I did not run my reply subcommand.

Here are steps to reproduce:

$ nats-server -js
$ ./nats-stream-example stream-add --stream my_stream2 --subject foo2
$ ./nats-stream-example consumer-add --consumer pull_consumer2 --stream my_stream2
$ ./nats-stream-example request --subject foo2 --count 100

How can I do request-reply properly on a JetStream stream?

2 Answers 2

2

The reason you get the {"stream":"my_stream2", "seq":112} reply is that Jetstream replies with a confirmation saying it has received your message.

Normally you wouldn't need Jetstream for the purpose of Request-Reply, but if you need it in order to log the requests, it should be possible by using the no_ack option for the stream.

0

Answering my own question, as a workaround, I made another subject for the reply and set the subject to the message header. Then the receiver get the subject from the message header and publish the reply to the subject.

https://github.com/hnakamur/nats-stream-example/commit/1406b14bf06cc390268ee7fa082ab55c49b99050

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.