Files
mesh-controller/internal/link/bus_nats.go
T

30 lines
1.1 KiB
Go

package link
import (
"github.com/novox/mesh-controller/internal/broker"
)
// ConnectNats is Connect for the bus being built: the controller's inbound and outbound over one
// JetStream connection the caller has already raised the streams on. Nothing is declared here —
// the streams and the controller's consumers are asserted by Raise, before anything is served.
func ConnectNats(js *broker.JetStream, enroller Enroller, listener Listener) *Server {
logger := newLog()
inbound := Nats(js).(*natsInbound)
inbound.log = logger
return &Server{
inbound: inbound,
bus: OverNATS{JS: js.Context(), Conn: js.Conn()},
js: js,
enroller: enroller,
listener: listener,
log: logger,
}
}
// Bus is the controller's outbound, whichever transport it connected over. Callers that send a
// declaration or ask a tool use this rather than the channel, which one transport does not have.
func (s *Server) Bus() Bus { return s.bus }
// SendingOn is a server that only sends, over the bus given: for a test of a sender with a bus it holds in its hand.
func SendingOn(bus Bus) *Server { return &Server{bus: bus} }