> For the complete documentation index, see [llms.txt](https://docs.microservice-stack.com/introduction/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.microservice-stack.com/introduction/demo-project/product-ordering.md).

# 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

![](https://3048002809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ6xEka2WKHRv890dwrNn%2Fuploads%2FncSzhcVlW8rO1fwVlCTe%2Fimage.png?alt=media\&token=8fc6bcfd-1d4f-4d48-b15b-5cb7d96e8eb5)

### Product Ordering

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/5/files>" %}

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.

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/5/files#diff-010775d32e7af56b01fd5fdfc1dbfbb874394a8ea6429af4a03130796707f592>" %}

```typescript
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.

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/5/files#diff-3612358a90d6505662884def0f140627ab01d90974dea503d6f8e464ef47ccd4>" %}

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

### Testing order service

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

![](https://3048002809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ6xEka2WKHRv890dwrNn%2Fuploads%2FboOAV3NTJ1r4Xrz1MG3x%2Fimage.png?alt=media\&token=d2455b3d-902d-40fb-9f9a-76d7c2ff6341)

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

![](https://3048002809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ6xEka2WKHRv890dwrNn%2Fuploads%2FbwomEirazb20jlnakZnD%2Fimage.png?alt=media\&token=2bb1eafb-436c-4a13-81df-497b400d826d)

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