mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Reuse existing connections, as we don't need separate ones
This commit is contained in:
parent
3a2e8606c7
commit
d0a764a083
|
|
@ -20,6 +20,8 @@ import (
|
|||
|
||||
type NATSInstance struct {
|
||||
*natsserver.Server
|
||||
nc *natsclient.Conn
|
||||
js natsclient.JetStreamContext
|
||||
}
|
||||
|
||||
var natsLock sync.Mutex
|
||||
|
|
@ -69,11 +71,18 @@ func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetS
|
|||
if !s.ReadyForConnections(time.Second * 10) {
|
||||
logrus.Fatalln("NATS did not start in time")
|
||||
}
|
||||
// reuse existing connections
|
||||
if s.nc != nil {
|
||||
return s.js, s.nc
|
||||
}
|
||||
nc, err := natsclient.Connect("", natsclient.InProcessServer(s))
|
||||
if err != nil {
|
||||
logrus.Fatalln("Failed to create NATS client")
|
||||
}
|
||||
return setupNATS(process, cfg, nc)
|
||||
js, _ := setupNATS(process, cfg, nc)
|
||||
s.js = js
|
||||
s.nc = nc
|
||||
return js, nc
|
||||
}
|
||||
|
||||
func setupNATS(process *process.ProcessContext, cfg *config.JetStream, nc *natsclient.Conn) (natsclient.JetStreamContext, *natsclient.Conn) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue