gklijs / graphql_axon_synapse

Example how to leverage synapse for building a GraphQL endpoint with Deno.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Demo Application leveraging Axon Synapse to add a GraphQL endpoint

Quickstart

The application contains 3 major parts, you need all of them to be able to execute commands successfully.

  1. Infra components, Axon Server, Axon Synapse and MongoDB. Start with docker console up -d in the docker folder. In projection we assume the Deno app can be reached via http://host.docker.internal:3000/events from Synapse which might not be the case in your docker setup.
  2. JVM app which handles commands, builds his own projection, and has a basic ui. Run ./mvnw spring-boot:run in the main folder to start. You do need Java installed.
  3. A Deno app, which has its own projection in MongoDB, Run deno run --allow-net --allow-read --import-map ./import_map.json server.ts in the deno folder, you do need to have Deno installed.

Where to find more information

  • The Axon Reference Guide is definitive guide on the Axon Framework and Axon Server.
  • Visit www.axoniq.io to find out about AxonIQ, the team behind the Axon Framework and Server.
  • Subscribe to the AxonIQ YouTube channel to get the latest Webinars, announcements, and customer stories.
  • To start a fresh Axon Application, you can go to start.axoniq.io.
  • Additional information may be gained by following some of AxonIQ's courses on the AxonIQ Academy.
  • The latest version of the Giftcard App can be found on GitHub.
  • Docker images for Axon Server are pushed to Docker Hub.
  • If there are any Axon related questions remaining, you can always go to the forum.

Components

More information about some of the components involved

The Giftcard app(JVM)

It's a Axon Framework application, which has been forked. The fork might diverge at some points. The major difference is that within this project, its using MongoDB to store the projection.

Background story

See the wikipedia article for a basic definition of gift cards. Essentially, there are just two events in the life cycle of a gift card:

  • They get issued: a new gift card gets created with some amount of money stored.
  • They get redeemed: all or part of the monetary value stored on the gift card is used to purchase something.

Structure of the App

The Giftcard application is split into four parts, using four sub-packages of io.axoniq.demo.giftcard:

  • The api package contains the (Java Records) sourcecode of the messages and entity. They form the API (sic) of the application.
  • The command package contains the GiftCard Aggregate class, with all command- and associated eventsourcing handlers.
  • The query package provides the query handlers, with their associated event handlers.
  • The rest package contains the Spring Webflux-based Web API.

Building the Giftcard app from the sources

To build the demo app, simply run the provided Maven wrapper:

./mvnw clean package

Note that the Giftcard app expects JDK 17 to be used.

Running the Giftcard app

The simplest way to run the app is by using the Spring-boot maven plugin:

./mvnw spring-boot:run

However, if you have copied the jar file giftcard-demo-1.0.jar from the Maven target directory to some other location, you can also start it with:

java -jar giftcard-demo-1.0.jar

The Web GUI can be found at http://localhost:8080.

Axon Server

Axon server is both a event store and a message router. It was developed to work well together with Axon Framework applications.

Running Axon Server

By default, the Axon Framework is configured to expect a running Axon Server instance, and it will complain if the server is not found. To run Axon Server, you'll need a Java runtime.
A copy of the server JAR file has been provided in the demo package. You can run it locally, in a Docker container or on a separate server.

The section below give a fair description on how to run Axon Server for this sample project. If you are looking for more in depth information on the subject, we recommend this three-part blog series:

  1. Running Axon Server - Going from local developer install to full-featured cluster in the cloud
  2. Running Axon Server in Docker - Continuing from local developer install to containerized
  3. Running Axon Server in a Virtual Machine

Running Axon Server locally

To run Axon Server locally, all you need to do is put the server JAR file in the directory where you want it to live, and start it using:

java -jar axonserver.jar

You will see that it creates a subdirectory data where it will store its information.

Running Axon Server in a Docker container

To run Axon Server in Docker you can use the image provided on Docker Hub:

$ docker run -d --name my-axon-server -p 8024:8024 -p 8124:8124 axoniq/axonserver
...some container id...
$

Configuring Axon Server

Axon Server uses sensible defaults for all of its settings, so it will actually run fine without any further configuration. However, if you want to make some we recommend checking out the Configuration section of the Reference Guide.

Axon Server HTTP server

Axon Server provides two servers; one serving HTTP requests, the other gRPC. By default, these use ports 8024 and 8124 respectively, but you can change these in the settings.

The HTTP server has in its root context a management Web GUI, a health indicator is available at /actuator/health, and the REST API at /v1. The API's Swagger endpoint finally, is available at /swagger-ui.html, and gives the documentation on the REST API.

Axon Synapse

Axon Synapse has its own ui, available at localhost:8081 when using the docker compose. You can see things like which applications are connected.

Deno

You need to have Deno installed. If you are on a mac, you can run:

brew install deno

After that, you can run the deno app with:

cd deno
deno run --allow-net --allow-read --import-map ./import_map.json server.ts

Potential Gotchas

About

Example how to leverage synapse for building a GraphQL endpoint with Deno.

License:Apache License 2.0


Languages

Language:Java 53.9%Language:TypeScript 22.1%Language:JavaScript 16.4%Language:HTML 7.6%