2021-02-24 09:58:02 +00:00
|
|
|
package steward
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *server) subscribeMessages(proc process) {
|
|
|
|
subject := string(proc.subject.name())
|
|
|
|
|
|
|
|
// Subscribe will start up a Go routine under the hood calling the
|
|
|
|
// callback function specified when a new message is received.
|
|
|
|
_, err := s.natsConn.Subscribe(subject, func(msg *nats.Msg) {
|
|
|
|
// We start one handler per message received by using go routines here.
|
|
|
|
// This is for being able to reply back the current publisher who sent
|
|
|
|
// the message.
|
2021-02-26 14:11:20 +00:00
|
|
|
go s.subscriberHandler(s.natsConn, s.nodeName, msg, proc)
|
2021-02-24 09:58:02 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error: Subscribe failed: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *server) subscribersStart() {
|
|
|
|
// Start a subscriber for shellCommand messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting shellCommand subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(ShellCommand, CommandACK, s.nodeName)
|
2021-02-26 14:11:20 +00:00
|
|
|
proc := s.processPrepareNew(sub, s.errorKernel.errorCh, processKindSubscriber, []node{"central", "ship2"})
|
2021-02-24 09:58:02 +00:00
|
|
|
// fmt.Printf("*** %#v\n", proc)
|
|
|
|
go s.spawnWorkerProcess(proc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a subscriber for textLogging messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting textlogging subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(TextLogging, EventACK, s.nodeName)
|
2021-02-26 14:11:20 +00:00
|
|
|
proc := s.processPrepareNew(sub, s.errorKernel.errorCh, processKindSubscriber, []node{"central"})
|
2021-02-24 09:58:02 +00:00
|
|
|
// fmt.Printf("*** %#v\n", proc)
|
|
|
|
go s.spawnWorkerProcess(proc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a subscriber for SayHello messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting SayHello subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(SayHello, EventNACK, s.nodeName)
|
2021-02-26 14:11:20 +00:00
|
|
|
proc := s.processPrepareNew(sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"})
|
2021-02-24 09:58:02 +00:00
|
|
|
// fmt.Printf("*** %#v\n", proc)
|
|
|
|
go s.spawnWorkerProcess(proc)
|
|
|
|
}
|
2021-02-24 14:43:31 +00:00
|
|
|
|
|
|
|
if s.centralErrorLogger {
|
|
|
|
// Start a subscriber for ErrorLog messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting ErrorLog subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(ErrorLog, EventNACK, "errorCentral")
|
2021-02-26 14:11:20 +00:00
|
|
|
proc := s.processPrepareNew(sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"})
|
2021-02-24 14:43:31 +00:00
|
|
|
// fmt.Printf("*** %#v\n", proc)
|
|
|
|
go s.spawnWorkerProcess(proc)
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|