Respond allows a convenient way to respond to requests in service based subscriptions.
(data []byte)
| 5712 | |
| 5713 | // Respond allows a convenient way to respond to requests in service based subscriptions. |
| 5714 | func (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 |
| 5729 | func (m *Msg) RespondMsg(msg *Msg) error { |