An open API service indexing awesome lists of open source software.

https://github.com/ralphv/gallifrey-rules-sample

A minimal sample application utilizing gallifrey-rules
https://github.com/ralphv/gallifrey-rules-sample

Last synced: about 1 month ago
JSON representation

A minimal sample application utilizing gallifrey-rules

Awesome Lists containing this project

README

          



Logo

Gallifrey Rules Sample



A modern robust framework for handling real-time events

## What is it

Gallifrey Rules Sample is a sample application using the library [gallifrey-rules](https://github.com/ralphv/gallifrey-rules)

This sample application use case does the following:

1. Listen to a kafka topic called `new-orders`
2. Translate the message into a gallifrey-rules event using the event dispatcher [new-order-dispatcher](https://github.com/ralphv/gallifrey-rules-sample/blob/main/src/modules/providers/NewOrdersDispatcher.ts)
3. Runs the **rule** [notify-customer-new-order-rule](https://github.com/ralphv/gallifrey-rules-sample/blob/main/src/modules/plugins/rules/NotifyCustomerNewOrderRule.ts)
4. The **rule** will call the **data object** [customer-info-data-object](https://github.com/ralphv/gallifrey-rules-sample/blob/main/src/modules/plugins/data-objects/CustomerInfoDataObject.ts) to get customer info, prepare an email
and then use the **action** [send-email-action](https://github.com/ralphv/gallifrey-rules-sample/blob/main/src/modules/plugins/actions/SendEmailAction.ts) to email the customer that his new order was received.

### Getting started

This will install modules, build and start off the application locally.
```shell
npm start
```
`Note: this will fail because of missing environment variables and this is expected`

To build your application docker image `gallifrey-rules-sample`
### Building docker image
```shell
npm run docker-build
```

To start your docker image
```shell
docker run --rm -it gallifrey-rules-sample
```

### Test it all together
```shell
docker compose up -d
```

This will start a kafka server and your application image, once running, you can call
```shell
npm run produce-message
```
To send a message into the kafka topic.
The sample application should consume it nicely, check the logs using
```shell
docker logs gallifrey-rules-sample -f
```
You should be able to see in the logs at least

```
Email sent to: "Doctor Who"
----------------------------------------------------------

Hello Doctor Who

Thank you so much for your recent order ID: 13

Your order contains the following items:

Name: Children of Earth, Qty: 1, Price: 12.43
Name: Type 40 TT Capsule, Qty: 500, Price: 26

Have a great day!

----------------------------------------------------------
```

You can also open [http://localhost:8080](http://localhost:8080) to open kafka ui and produce messages directly from there.