diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2024-03-22 22:33:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 22:33:23 +0100 |
commit | 81f73c9f8df6dd3078a93b6ca978ecbb9c95df16 (patch) | |
tree | 7e660378ad592bd8393e8382094bef649138882a /setup | |
parent | 79072c3dcdc88b77dd5a49c013a0c62624dd3224 (diff) |
Reuse existing NATS connection (#3345)
If using external NATS, we opened unnecessary connections. This now
re-uses existing connections.
[skip ci]
Diffstat (limited to 'setup')
-rw-r--r-- | setup/jetstream/nats.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/setup/jetstream/nats.go b/setup/jetstream/nats.go index 8820e86b..8630a141 100644 --- a/setup/jetstream/nats.go +++ b/setup/jetstream/nats.go @@ -38,7 +38,12 @@ func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetS defer natsLock.Unlock() // check if we need an in-process NATS Server if len(cfg.Addresses) != 0 { - return setupNATS(process, cfg, nil) + // reuse existing connections + if s.nc != nil { + return s.js, s.nc + } + s.js, s.nc = setupNATS(process, cfg, nil) + return s.js, s.nc } if s.Server == nil { var err error |