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?

hnakamur
  • 521
  • 4
  • 17

1 Answers1

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

hnakamur
  • 521
  • 4
  • 17