Product ordering

Creating order service

Ordering service should be created the same way customer service was created in the previous step

npx nx generate @microservice-stack/workspace:application-generator --applicationName=order --includeDatabase --includeQueue

Once the service is generated, we can again validate that the generation was successful by deploying it to the local cluster. This time the deployment will be done by using the update command in the CLI, as the local cluster should already be set up from the previous step.

npx @microservice-stack/local-deployment update -s order

After the CLI process has been successfully completed, we can validate the deployment using the kubectl tool

kubectl get pods

It should return something like this

Product Ordering

All code for product ordering logic can be seen in the pull request above.

Product ordering works in a way where customer creates a new order request by using REST api. Once the order is created, a new order entity is created and order service broadcasts the message about order creation through the RabbitMQ messaging.

Order created event

This is the first update in which RabbitMQ messaging is used to notify other services of a state change. The event definition can be seen in the service specific constants library.

export const ORDER_CREATED_EVENT = new Event<OrderCreatedEventPayload>(
  'order.created',
  1
);

The event is comprised of

  1. Payload type, which is used for type inferrence when publishing the event

  2. Routing key, a key which determines who will receive the copy of the message

  3. Event version

The default RabbitMQ configuration is using a Fanout exchange. This exchange broadcasts the message to all queues bound to the same routing key.

The order functionality introduced new endpoint which has to be added to the ingress config.

The ingress and service should be deployed locally the same way as in the Customer authentication step.

Testing order service

Once everything is deployed, we can test the newly added API by creating a new order

Once the order is created, we can take the order id, and use it to get the order details

The next step in demo project implementation is order payment reservation.

Last updated