Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions plugins/outputs/nats/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading