SubscribeReply creates a subscription that supports replying to requests. The handler receives the raw request data and the reply subject.
(subject string, handler func(data []byte, reply func([]byte)))
| 234 | // SubscribeReply creates a subscription that supports replying to requests. |
| 235 | // The handler receives the raw request data and the reply subject. |
| 236 | func (c *Client) SubscribeReply(subject string, handler func(data []byte, reply func([]byte))) (Subscription, error) { |
| 237 | return c.confirmSubscription(subject, func(conn *nats.Conn) (*nats.Subscription, error) { |
| 238 | return conn.Subscribe(subject, func(msg *nats.Msg) { |
| 239 | handler(msg.Data, func(replyData []byte) { |
| 240 | if msg.Reply != "" { |
| 241 | if err := msg.Respond(replyData); err != nil { |
| 242 | xlog.Warn("Failed to send NATS reply", "subject", subject, "error", err) |
| 243 | } |
| 244 | } |
| 245 | }) |
| 246 | }) |
| 247 | }) |
| 248 | } |
| 249 | |
| 250 | // QueueSubscribeReply creates a queue subscription that supports replying to requests. |
| 251 | // Load-balanced across subscribers in the same queue group, with request-reply support. |
nothing calls this directly
no test coverage detected