Order shipping

Creating Shipping service

Shipping service should be created the same way as the other services were created

npx nx generate @microservice-stack/workspace:application-generator --applicationName=shipping --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 steps.

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

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

Order shipping

Shipping service takes care of collecting customers address and listens to the Order payment reserved event so it can trigger order shipping.

Once the order payment reserved event is received, the shipping service checks for customer address. If customer does not have shipping address registered with the shipping service, order is rejected and Order shipment failed event is broadcasted.

If the shipping address is present, the shipping service logs out the message Order shipped to <address> and broadcasts Order shipment succeeded event.

Order service has been updated to listen to these events and update Order status accordingly.

Testing order shipping

Before testing new updates, all services should be updated in the local cluster.

We can test the functionality again by creating the order. Once we call the order details endpoint it should return status failed

To fix this issue we should add a customer address by calling the following endpoint

Now that the customer address has been added we can try creating new order.

The order was now successfully created and now has status shipped! To verify that the order has really been shipped lets take a look at shipping service logs using kubectl logs command. The log should contain Order shipped message.

Last updated