Skip to content

Latest commit

 

History

History

drestaurant-microservices-websockets

Microservices / Websockets / AxonServer

:octocat: /drestaurant-apps/drestaurant-microservices-websockets :octocat:

This is a thin layer which coordinates the application activity. It does not contain business logic. It does not hold the state of the business objects

We designed and structured our loosely coupled components in a modular way, and that enable us to choose different deployment strategy and take first step towards Microservices architectural style.

Each microservice:

  • has its own bounded context,
  • has shared event(sourcing) storage (AxonServer)
  • and we route and distribute messages (events, commands, queries) between them via AxonServer

AxonServer & event messages & command messages & query messages

Both AxonFramework and AxonServer form an Axon platform.

The key characteristics of AxonServer are:

  • Dedicated infrastructure for exchanging three types of messages (commands, events, queries) in a message-driven micro-services environment
  • Purpose-built database system optimized for the storage of event data of the type that is generated by applications that use the event sourcing architecture pattern
  • Built-in knowledge on CQRS message patterns
  • Easy-to-use and easy-to-manage

AxonServer connector is configured by default :

<dependency>
    <groupId>org.axonframework</groupId>
    <artifactId>axon-spring-boot-starter</artifactId>
    <version>${axon.version}</version>
</dependency>

Alternatively, you can exclude AxonServer connector and fallback to JPA event store and storage in general. In that case you have to choose (and configure, and operate) other options (Spring cloud, Kafka, RabbitMQ, ...) to distribute your messages. We did this already in other apps (Micorservices1, Microservices2, ...) as a proof that you can benefit from AxonFramework programming model only (without AxonServer as an infrastructural component)

<dependency>
    <groupId>org.axonframework</groupId>
    <artifactId>axon-spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-server-connector</artifactId>
        </exclusion>
    </exclusions>
</dependency>

AxonFramework and AxonServer are open source. Axon Server Enterprise is targeted towards mission-critical, medium to large scale production deployments of Axon.

STOMP over WebSockets API

Customer (command side)

WebSocket SockJS endpoint: ws://localhost:8081/customer/websocket

  • /app/customers/createcommand, messageType=[MESSAGE]

Courier (command side)

WebSocket SockJS endpoint: ws://localhost:8082/courier/websocket

  • /app/couriers/createcommand, messageType=[MESSAGE]
  • /app/couriers/orders/assigncommand, messageType=[MESSAGE]
  • /app/couriers/orders/markdeliveredcommand, messageType=[MESSAGE]

Restaurant (command side)

WebSocket SockJS endpoint: ws://localhost:8084/restaurant/websocket

  • /app/restaurants/createcommand, messageType=[MESSAGE]
  • /app/restaurants/orders/markpreparedcommand, messageType=[MESSAGE]

Order (command side)

WebSocket SockJS endpoint: ws://localhost:8083/order/websocket

  • /app/orders/createcommand, messageType=[MESSAGE]

Query side

WebSocket SockJS endpoint: ws://localhost:8085/query/websocket

  • /app/customers, messageType=[SUBSCRIBE]
  • /app/customers/{id}, messageType=[SUBSCRIBE]
  • /app/couriers, messageType=[SUBSCRIBE]
  • /app/couriers/{id}, messageType=[SUBSCRIBE]
  • /app/couriers/orders, messageType=[SUBSCRIBE]
  • /app/couriers/orders/{id}, messageType=[SUBSCRIBE]
  • /app/restaurants, messageType=[SUBSCRIBE]
  • /app/restaurants/{id}, messageType=[SUBSCRIBE]
  • /app/orders, messageType=[SUBSCRIBE]
  • /app/orders/{id}, messageType=[SUBSCRIBE]
  • /app/restaurants/orders, messageType=[SUBSCRIBE]
  • /app/restaurants/orders/{id}, messageType=[SUBSCRIBE]
  • /topic/couriers.updates (courier list has been updated, e.g. new courier has been created)
  • /topic/customers.updates (customer list has been updated, e.g. new customer has been created)
  • /topic/orders.updates (order list has been updated, e.g. new order has been created)
  • /topic/restaurants.updates (restaurant list has been updated, e.g. new restaurant has been created)
  • /topic/couriers/orders.updates (courier order list has been updated, e.g. new courier order has been created)
  • /topic/restaurants/orders.updates(restaurant order list has been updated, e.g. new restaurant order has been created)

Development

This project is driven using Maven.

Clone

$ git clone https://github.com/idugalic/digital-restaurant

Build

$ cd digital-restaurant
$ mvn clean install

Run microservices

AxonServer is required.

$ cd digital-restaurant/drestaurant-apps/drestaurant-microservices-websockets/drestaurant-microservices-websockets-comand-courier
$ mvn spring-boot:run
$ cd digital-restaurant/drestaurant-apps/drestaurant-microservices-websockets/drestaurant-microservices-websockets-comand-customer
$ mvn spring-boot:run
$ cd digital-restaurant/drestaurant-apps/drestaurant-microservices-websockets/drestaurant-microservices-websockets-comand-restaurant
$ mvn spring-boot:run
$ cd digital-restaurant/drestaurant-apps/drestaurant-microservices-websockets/drestaurant-microservices-websockets-comand-order
$ mvn spring-boot:run
$ cd digital-restaurant/drestaurant-apps/drestaurant-microservices-websockets/drestaurant-microservices-websockets-query
$ mvn spring-boot:run

Infrastructure and Platform (As A Service)