如何在射流流上进行请求?

发布于 2025-02-13 04:18:47 字数 1445 浏览 0 评论 0原文

我为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七堇年 2025-02-20 04:18:47

您获得{“流”:“ 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.

离去的眼神 2025-02-20 04:18:47

回答我自己的问题,作为解决方法,我为答复做了另一个主题,并将主题设置为消息标题。
然后,接收器从消息标题中获取主题并将其发布给主题的答复。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文