feat(outputs.nats): Use Jetstream publisher when using Jetstream (#16570)

This commit is contained in:
kfollesdal 2025-03-05 16:22:00 +01:00 committed by GitHub
parent d8548d158d
commit 26a692a240
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -264,8 +264,11 @@ func (n *NATS) Write(metrics []telegraf.Metric) error {
n.Log.Debugf("Could not serialize metric: %v", err) n.Log.Debugf("Could not serialize metric: %v", err)
continue continue
} }
// use the same Publish API for nats core and jetstream 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) err = n.conn.Publish(n.Subject, buf)
}
if err != nil { if err != nil {
return fmt.Errorf("failed to send NATS message: %w", err) return fmt.Errorf("failed to send NATS message: %w", err)
} }