2021-02-10 13:29:17 +00:00
|
|
|
// NB:
|
|
|
|
// When adding new constants for the Method or CommandOrEvent
|
|
|
|
// types, make sure to also add them to the map
|
|
|
|
// <Method/CommandOrEvent>Available since the this will be used
|
|
|
|
// to check if the message values are valid later on.
|
2021-02-11 14:39:19 +00:00
|
|
|
|
2021-02-10 13:29:17 +00:00
|
|
|
package steward
|
|
|
|
|
2021-02-18 07:25:13 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2021-02-10 13:29:17 +00:00
|
|
|
// CommandOrEvent describes on the message level if this is
|
|
|
|
// an event or command kind of message in the Subject name.
|
|
|
|
// This field is mainly used to be able to spawn up different
|
|
|
|
// worker processes based on the Subject name so we can have
|
|
|
|
// one process for handling event kind, and another for
|
|
|
|
// handling command kind of messages.
|
|
|
|
// This type is used in both building the subject name, and
|
|
|
|
// also inside the Message type to describe if it is a Command
|
|
|
|
// or Event.
|
|
|
|
type CommandOrEvent string
|
|
|
|
|
|
|
|
func (c CommandOrEvent) GetCommandOrEventAvailable() CommandOrEventAvailable {
|
|
|
|
ma := CommandOrEventAvailable{
|
|
|
|
topics: map[CommandOrEvent]struct{}{
|
2021-02-17 17:59:49 +00:00
|
|
|
CommandACK: {},
|
|
|
|
CommandNACK: {},
|
|
|
|
EventACK: {},
|
|
|
|
EventNACK: {},
|
2021-02-10 13:29:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return ma
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Command, command that will just wait for an
|
|
|
|
// ack, and nothing of the output of the command are
|
|
|
|
// delivered back in the reply ack message.
|
|
|
|
// The message should contain the unique ID of the
|
|
|
|
// command.
|
2021-02-22 08:33:37 +00:00
|
|
|
CommandACK CommandOrEvent = "CommandACK"
|
2021-02-17 17:59:49 +00:00
|
|
|
// Same as above, but No ACK.
|
2021-02-22 08:33:37 +00:00
|
|
|
CommandNACK CommandOrEvent = "CommandNACK"
|
2021-02-17 17:59:49 +00:00
|
|
|
// Same as above, but No ACK
|
2021-02-10 13:29:17 +00:00
|
|
|
// Event, wait for and return the ACK message. This means
|
|
|
|
// that the command should be executed immediately
|
|
|
|
// and that we should get the confirmation if it
|
|
|
|
// was successful or not.
|
2021-02-22 08:33:37 +00:00
|
|
|
EventACK CommandOrEvent = "EventACK"
|
2021-02-17 17:59:49 +00:00
|
|
|
// Same as above, but No ACK.
|
2021-02-22 08:33:37 +00:00
|
|
|
EventNACK CommandOrEvent = "EventNACK"
|
2021-02-10 13:29:17 +00:00
|
|
|
// eventCommand, just wait for the ACK that the
|
|
|
|
// message is received. What action happens on the
|
|
|
|
// receiving side is up to the received to decide.
|
|
|
|
)
|
|
|
|
|
|
|
|
type CommandOrEventAvailable struct {
|
|
|
|
topics map[CommandOrEvent]struct{}
|
|
|
|
}
|
|
|
|
|
2021-03-02 12:46:02 +00:00
|
|
|
func (co CommandOrEventAvailable) CheckIfExists(c CommandOrEvent, subject Subject) bool {
|
2021-02-10 13:29:17 +00:00
|
|
|
_, ok := co.topics[c]
|
|
|
|
if ok {
|
2021-03-02 12:46:02 +00:00
|
|
|
log.Printf("info: CommandOrEventAvailable.CheckIfExists: command or event found: %v, for %v\n", c, subject.name())
|
2021-02-10 13:29:17 +00:00
|
|
|
return true
|
|
|
|
} else {
|
2021-03-02 12:46:02 +00:00
|
|
|
log.Printf("error: CommandOrEventAvailable.CheckIfExists: command or event not found: %v, for %v\n", c, subject.name())
|
2021-02-10 13:29:17 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|