MCPcopy
hub / github.com/mudler/LocalAI / SubscribeReply

Method SubscribeReply

core/services/messaging/client.go:236–248  ·  view source on GitHub ↗

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)))

Source from the content-addressed store, hash-verified

234// SubscribeReply creates a subscription that supports replying to requests.
235// The handler receives the raw request data and the reply subject.
236func (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.

Callers

nothing calls this directly

Calls 3

confirmSubscriptionMethod · 0.95
SubscribeMethod · 0.65
handlerFunction · 0.50

Tested by

no test coverage detected