简体   繁体   中英

Unexpected replies using nats jetstream

I am using Nats JetStream to implement request-reply functionality. It all works fine, except for the minor detail that I get a very strange reply back. The data in the reply message is not at all what I was sending from the replying end.

This can also be reproduced using the nats cli, which means my code that is sending or receiving the message is not the issue. What might be the issue however is the way I'm creating the stream, as this works fine when using nats without a stream.

This is my stream config i Go:

var Read = &nats.StreamConfig{
    Name:        "read",
    Description: "Read Stream",
    Subjects: []string{
        "read.things",
    },
    Retention:    nats.LimitsPolicy,
    MaxConsumers: -1,
    MaxMsgs:      -1,
    MaxBytes:     -1,
    Discard:      nats.DiscardOld,
    MaxAge:       0,
    MaxMsgSize:   -1,
    Storage:      nats.FileStorage,
    Replicas:     0,
    NoAck:        false,
    Duplicates:   2 * time.Minute,
}

And I create it like this:

_, err = jetStream.AddStream(streams.Read)

To reproduce the issue I first setup a listener using nats cli:

nats reply 'read.things' "Hello there"

Then i send a request:

nats request read.things
Hi
[Ctrl+D]

And I get this:

12:01:08 Reading payload from STDIN
hi?
12:01:12 Sending request on "read.things"
12:01:12 Received on "_INBOX.91kMP9XDsFLK09g690N97Z.zTJsXJxE" rtt 19.422916ms
{"stream":"read", "seq":1}

As you can see I get this back: {"stream":"read", "seq":1} when I expected to get Hello there . Why is this?

I got this reply from the nats slack ( https://natsio.slack.com ):

"JetStream isn't for Request-Reply. It's for uncoupled work loads. If you want coupled request-reply you don't need persistence.

What you are seeing is the reply from the stream saying “yup, got your message”"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM