QueueSubscribeJSON creates a queue subscription that automatically unmarshals JSON messages. Invalid JSON messages are logged and skipped.
(c MessagingClient, subject, queue string, handler func(T))
| 279 | // QueueSubscribeJSON creates a queue subscription that automatically unmarshals JSON messages. |
| 280 | // Invalid JSON messages are logged and skipped. |
| 281 | func QueueSubscribeJSON[T any](c MessagingClient, subject, queue string, handler func(T)) (Subscription, error) { |
| 282 | return c.QueueSubscribe(subject, queue, func(data []byte) { |
| 283 | var evt T |
| 284 | if err := json.Unmarshal(data, &evt); err != nil { |
| 285 | xlog.Warn("Failed to unmarshal NATS message", "subject", subject, "error", err) |
| 286 | return |
| 287 | } |
| 288 | handler(evt) |
| 289 | }) |
| 290 | } |
| 291 | |
| 292 | // RequestJSON sends a JSON request-reply via NATS, marshaling the request and |
| 293 | // unmarshaling the reply. This eliminates the repeated marshal/request/unmarshal |
no test coverage detected