Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 81f73c9

Browse files
authored
Reuse existing NATS connection (#3345)
If using external NATS, we opened unnecessary connections. This now re-uses existing connections. [skip ci]
1 parent 79072c3 commit 81f73c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

setup/jetstream/nats.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetS
3838
defer natsLock.Unlock()
3939
// check if we need an in-process NATS Server
4040
if len(cfg.Addresses) != 0 {
41-
return setupNATS(process, cfg, nil)
41+
// reuse existing connections
42+
if s.nc != nil {
43+
return s.js, s.nc
44+
}
45+
s.js, s.nc = setupNATS(process, cfg, nil)
46+
return s.js, s.nc
4247
}
4348
if s.Server == nil {
4449
var err error

0 commit comments

Comments
 (0)