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

Method Respond

nats.go:5714–5726  ·  view source on GitHub ↗

Respond allows a convenient way to respond to requests in service based subscriptions.

(data []byte)

Source from the content-addressed store, hash-verified

5712
5713// Respond allows a convenient way to respond to requests in service based subscriptions.
5714func (m *Msg) Respond(data []byte) error {
5715 if m == nil || m.Sub == nil {
5716 return ErrMsgNotBound
5717 }
5718 if m.Reply == "" {
5719 return ErrMsgNoReply
5720 }
5721 m.Sub.mu.Lock()
5722 nc := m.Sub.conn
5723 m.Sub.mu.Unlock()
5724 // No need to check the connection here since the call to publish will do all the checking.
5725 return nc.Publish(m.Reply, data)
5726}
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 {

Callers 1

TestMsgRespondFunction · 0.95

Calls 1

PublishMethod · 0.65

Tested by 1

TestMsgRespondFunction · 0.76