2021-02-10 13:29:17 +00:00
|
|
|
// NB:
|
2022-01-27 09:06:06 +00:00
|
|
|
// When adding new constants for the Method or event
|
2021-02-10 13:29:17 +00:00
|
|
|
// types, make sure to also add them to the map
|
2022-01-27 09:06:06 +00:00
|
|
|
// <Method/Event>Available since the this will be used
|
2021-02-10 13:29:17 +00:00
|
|
|
// 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
|
|
|
|
|
2022-01-27 06:19:04 +00:00
|
|
|
// Event describes on the message level if this is
|
2022-01-27 13:25:24 +00:00
|
|
|
// an ACK or NACK kind of message in the Subject name.
|
2021-02-10 13:29:17 +00:00
|
|
|
// This field is mainly used to be able to spawn up different
|
2022-01-27 13:25:24 +00:00
|
|
|
// worker processes based on the Subject name.
|
2021-02-10 13:29:17 +00:00
|
|
|
// This type is used in both building the subject name, and
|
2022-01-27 13:25:24 +00:00
|
|
|
// also inside the Message type to describe what kind like
|
|
|
|
// ACK or NACK it is.
|
2022-01-27 06:19:04 +00:00
|
|
|
type Event string
|
2021-02-10 13:29:17 +00:00
|
|
|
|
2022-01-27 06:19:04 +00:00
|
|
|
func (c Event) CheckEventAvailable() EventAvailable {
|
|
|
|
ma := EventAvailable{
|
|
|
|
topics: map[Event]struct{}{
|
|
|
|
EventACK: {},
|
|
|
|
EventNACK: {},
|
2021-02-10 13:29:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return ma
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2022-01-27 06:19:04 +00:00
|
|
|
// EventACK, wait for the return of an ACK message.
|
|
|
|
// The sender will wait for an ACK reply message
|
|
|
|
// to decide if it was succesfully delivered or not.
|
|
|
|
// If no ACK was received within the timeout, the
|
|
|
|
// message will be resent the nr. of times specified
|
|
|
|
// in retries field of the message.
|
|
|
|
EventACK Event = "EventACK"
|
2021-02-17 17:59:49 +00:00
|
|
|
// Same as above, but No ACK.
|
2022-01-27 06:19:04 +00:00
|
|
|
EventNACK Event = "EventNACK"
|
2021-02-10 13:29:17 +00:00
|
|
|
)
|
|
|
|
|
2022-01-27 09:06:06 +00:00
|
|
|
// EventAvailable are used for checking if the
|
|
|
|
// events are defined.
|
2022-01-27 06:19:04 +00:00
|
|
|
type EventAvailable struct {
|
|
|
|
topics map[Event]struct{}
|
2021-02-10 13:29:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 13:25:24 +00:00
|
|
|
// Check if an event exists.
|
2022-01-27 06:19:04 +00:00
|
|
|
func (e EventAvailable) CheckIfExists(event Event, subject Subject) bool {
|
|
|
|
_, ok := e.topics[event]
|
2021-02-10 13:29:17 +00:00
|
|
|
if ok {
|
2022-01-27 13:25:24 +00:00
|
|
|
// log.Printf("info: EventAvailable.CheckIfExists: event found: %v, for %v\n", c, subject.name())
|
2021-02-10 13:29:17 +00:00
|
|
|
return true
|
|
|
|
} else {
|
2022-01-27 13:25:24 +00:00
|
|
|
// log.Printf("error: EventAvailable.CheckIfExists: event not found: %v, for %v\n", c, subject.name())
|
2021-02-10 13:29:17 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|