...

/

The am and jetstream Packages

The am and jetstream Packages

Explore the am package for message handling and serialization, implementing an event stream system, and utilizing the jetstream package.

The am package

In the asynchronous package, we start with the message, as depicted here:

Press + to interact
The message and message handler interfaces
The message and message handler interfaces

The Message interface is kept slim and focused on the management of a message that needs to be sent or received. Yes—event-driven applications communicate with events, but the event will not be the only message we will be communicating with. The MessageHandler interface is defined with a generic Message type, so we can avoid having to maintain handlers for every possible kind of message we will be using.

We want to be able to publish anything into a stream, so our MessagePublisher interface is going to need to be with a generic interface{} or any type, as depicted in the following diagram:

Press + to interact
The message publisher, subscriber, and stream interfaces
The message publisher, subscriber, and stream interfaces

For the MessageSubscriber interface, we will be returning a Message type of some kind, and so it has been defined to use the previously defined generic MessageHandler interface.

Finally, the MessagePublisher and MessageSubscriber interfaces are brought together into the MessageStream interface, which will allow us to create a stream that will let us publish an Event type and receive an EventMessage type. That is exactly what we do to create the EventStream type that we will be adding in this chapter, ...