06 Messaging Service

Messaging Service

API microservices will communicate with each other via REST or asynchronous messaging. In this section, we will create an Azure Bus Service to enable API internal communication via messaging.

Create Azure Service Bus

Create an Azure Service Bus by clicking Create resource > search Service Bus > Service Bus

placeholder

Click on the ‘Create’ button

placeholder

Provide the parameters to create the Service Bus and then click the ‘Create’ button

placeholder

Topic

A topic allows for a publish / subscription model for messaging. A sender will publish a message to a topic. One or more receivers can then subscribe to the topic.

In the demo application, the Order Service publishes a message to a Topic called ‘order-created’. The message is a JSON string that contains the product id of the product that was ordered , as well as, other data relevant to the order.

The Product Service subscribes to the topic, and when it receives the message it searches for the product and decreases the product’s ‘inStock’ value by 1. In this way, an inventory is kept for products in the store.

Create a topic

In the Service Bus, click on the ‘Topics’ link and the ‘+’ icon to create a new topic. Name the topic ‘order-created’.

The Order Service is programmed to publish its JSON string message to this topic each time an order is created.

placeholder

Add a subscription to a topic

We need to create a subscription for the Product Service to access the topic. Click on the ‘order-created’ topic, and then click on the ‘+’ icon to add a new subscription. Name the subscription ‘productsvc’.

The Product Service is programmed to update the product inventory each time it receives a message from the ‘productsvc’ subscription.

placeholder

Next Steps

The next article in this website will walk you through installing Web API services in the AKS cluster.

Next Article : Installing Web API Services

Comments