January 2020
Intermediate to advanced
640 pages
16h 56m
English
For the majority of applications, using an in-memory queue implementation such as the one presented here should suffice. Implementing support for other types of queue systems (for example, Kafka, nats-streaming, or even plain files) is left as an exercise for you.
Let's start by defining the inMemoryQueue type and its constructor:
type inMemoryQueue struct { mu sync.Mutex msgs []Message latchedMsg Message } func NewInMemoryQueue() Queue { return new(inMemoryQueue) }
As you can see, the in-memory queue is nothing more than a slice of Message instances – a slot for storing the message that's being currently pointed to by an iterator and a sync.Mutex for serializing access to the list of messages. ...