feat(outputs.nats): Use Jetstream publisher when using Jetstream (#16570)
This commit is contained in:
parent
d8548d158d
commit
26a692a240
|
|
@ -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.conn.Publish(n.Subject, buf)
|
_, 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to send NATS message: %w", err)
|
return fmt.Errorf("failed to send NATS message: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue