如何在射流流上进行请求?
我为 https://github.com/hnakamur/nats-stream-example/tree/2c834d7d967d967f024348fbaa478ee18e9749431ba 。
作为实验的下一步,我试图为” noreflow noreferrer“>” https://docs.nats.io/nats-concepts/core-nats/reqreply/reqreply/reqreply/reqreply_walkthror“请求 - 重新演练-NATS DOCS ,但在喷气流中而不是非喷气流流。 我的尝试是 https://github.com/hnakamur/nats-stream-example/commit/149243b8bd30974a592061cd9d0c3a9b7b7f3f3f3f30f30f3。
但是,一旦我运行了请求子命令,我就得到了msg.data = {“ stream”:“ my_stream2”,“ seq”:112}
,即使我没有运行我的回复SubCommand,也得到了答复。 。
这里有复制的步骤:
$ 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
如何在射流流上正确进行请求?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您获得
{“流”:“ my_stream2”,“ seq”:112}
回复的原因是,jetstream回复了回复,并确认已收到您的消息。通常,您不需要重新启动的目的jetstream,但是如果您需要它来记录请求,则可以通过使用no_ack选项进行流。
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.
回答我自己的问题,作为解决方法,我为答复做了另一个主题,并将主题设置为消息标题。
然后,接收器从消息标题中获取主题并将其发布给主题的答复。
https://github.com/hnakamur/nats-stream-example/commit/1406b14bf06cc390268ee7fa082ab555555c49b99050
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