From 26a692a240a4d59e374e56c60f0bb768949dc575 Mon Sep 17 00:00:00 2001 From: kfollesdal Date: Wed, 5 Mar 2025 16:22:00 +0100 Subject: [PATCH] feat(outputs.nats): Use Jetstream publisher when using Jetstream (#16570) --- plugins/outputs/nats/nats.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/outputs/nats/nats.go b/plugins/outputs/nats/nats.go index d00598d75..1316766b8 100644 --- a/plugins/outputs/nats/nats.go +++ b/plugins/outputs/nats/nats.go @@ -264,8 +264,11 @@ func (n *NATS) Write(metrics []telegraf.Metric) error { n.Log.Debugf("Could not serialize metric: %v", err) continue } - // use the same Publish API for nats core and jetstream - err = n.conn.Publish(n.Subject, buf) + if n.Jetstream != nil { + _, err = n.jetstreamClient.Publish(context.Background(), n.Subject, buf, jetstream.WithExpectStream(n.Jetstream.Name)) + } else { + err = n.conn.Publish(n.Subject, buf) + } if err != nil { return fmt.Errorf("failed to send NATS message: %w", err) }