Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] no responders return the original subject #5250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/client.go
Expand Up @@ -4051,7 +4051,8 @@ func (c *client) processInboundClientMsg(msg []byte) (bool, bool) {
c.mu.Lock()
if c.opts.NoResponders {
if sub := c.subForReply(c.pa.reply); sub != nil {
proto := fmt.Sprintf("HMSG %s %s 16 16\r\nNATS/1.0 503\r\n\r\n\r\n", c.pa.reply, sub.sid)
hdrLen := 32 /* header without the subject */ + len(c.pa.subject)
proto := fmt.Sprintf("HMSG %s %s %d %d\r\nNATS/1.0 503\r\nNats-Subject: %s\r\n\r\n\r\n", c.pa.reply, sub.sid, hdrLen, hdrLen, c.pa.subject)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked Nats-Subject as the header name because it is used elsewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case it means the original subject the current message was published as - not sure we want to use that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the only way you would get this is if you are responding and adding a reply subject - which means that when the server answers with no responders, you know what the reply subject that you published a response to is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why I need the feature:

  • Service A: pub reply to MyService.Endpoint with a _INBOX.
  • Service B: sub to MyService.Endpoint and publish multiple times (grpc server stream) to the client _INBOX.hash with a reply option to MyService.Endpoint.
  • The server tracks each inbox in a hashmap and deletes it when it receives a 503.

To resolve the issue, I'm doing something similar but my service subscribe to MyService.> and setting the reply as: MyService.Endpoint., I also could have two subscriptions, one for MyService.Endpoint and another for MyService.Endpoint.>

c.queueOutbound([]byte(proto))
c.addToPCD(c)
}
Expand Down
2 changes: 1 addition & 1 deletion server/client_test.go
Expand Up @@ -252,7 +252,7 @@ func TestClientNoResponderSupport(t *testing.T) {
if len(am) == 0 {
t.Fatalf("Did not get a match for %q", l)
}
checkPayload(cr, []byte("NATS/1.0 503\r\n\r\n"), t)
checkPayload(cr, []byte("NATS/1.0 503\r\nNats-Subject: foo\r\n\r\n\r\n"), t)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also checking that the body is empty.

}

func TestServerHeaderSupport(t *testing.T) {
Expand Down