MCPcopy
hub / github.com/nats-io/nats.go / RespondMsg

Method RespondMsg

nats.go:5729–5742  ·  view source on GitHub ↗

RespondMsg allows a convenient way to respond to requests in service based subscriptions that might include headers

(msg *Msg)

Source from the content-addressed store, hash-verified

5727
5728// RespondMsg allows a convenient way to respond to requests in service based subscriptions that might include headers
5729func (m *Msg) RespondMsg(msg *Msg) error {
5730 if m == nil || m.Sub == nil {
5731 return ErrMsgNotBound
5732 }
5733 if m.Reply == "" {
5734 return ErrMsgNoReply
5735 }
5736 msg.Subject = m.Reply
5737 m.Sub.mu.Lock()
5738 nc := m.Sub.conn
5739 m.Sub.mu.Unlock()
5740 // No need to check the connection here since the call to publish will do all the checking.
5741 return nc.PublishMsg(msg)
5742}
5743
5744// FIXME: This is a hack
5745// removeFlushEntry is needed when we need to discard queued up responses

Callers 6

TestRequestMsgFunction · 0.80
TestMsg_RespondMsgFunction · 0.80
RespondMethod · 0.80
ErrorMethod · 0.80

Calls 1

PublishMsgMethod · 0.65

Tested by 4

TestRequestMsgFunction · 0.64
TestMsg_RespondMsgFunction · 0.64