Reuse existing NATS connection (#3345)

If using external NATS, we opened unnecessary connections. This now
re-uses existing connections.

[skip ci]
This commit is contained in:
Till 2024-03-22 22:33:23 +01:00 committed by GitHub
parent 79072c3dcd
commit 81f73c9f8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -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