...

/

Making the Store Management Module Asynchronous

Making the Store Management Module Asynchronous

Explore how to update the Store Management module to publish integration events.

We are going to update the Store Management module to publish integration events and will also update the Shopping Baskets module to receive messages. The Shopping Baskets module will not be doing much more than logging the receipt of the message.

Modifying the monolith configuration

Starting with a simple configuration for NATS, we need a uniform resource locator (URL) to connect to and a name for our stream. Of course, both could be hardcoded or put into variables in the code, but we run the application from a Docker container and without. The stream name is used in a few places, so having it be part of the configuration for the application is the lazy option. The code is illustrated here:

NatsConfig struct {
URL string `required:"true"`
Stream string `default:"mallbots"`
}
Simple configuration for NATS

The preceding code is added to the AppConfig with the field name Nats. To access the connection URL, we would use cfg.Nats.URL. For the Docker Compose environment, NATS will be available at nats:4222.

Updating the monolith application

...