There is more then one way to start and run Axon Server:
The Axon Server ZIP download contains executable JAR files for the server itself and the CLI. Copy
axonserver.jar to a directory of your choice. Because Axon Server uses sensible defaults, you are now ready to go. Start the Axon Server using the following command:
or when not running bash shell:
$ java -jar axonserver.jar
When you see a log line announcing "Started Axon Server in some-value seconds (JVM running for some-other-value)", the server is ready for action. To verify that the server is started correctly, open the page http://localhost:8024.
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
This starts Axon Server in a docker container, and exposes the HTTP and GRPC ports to the host. The Axon Server docker image uses 2 volumes, /data and /eventdata. You want to preserve the data that is written on these volumes. You can mount these on the host using the --mount options:
docker volume create axonserver-datadocker volume create axonserver-eventdatadocker run --name my-axon-server -p 8024:8024 -p 8124:8124 \--mount source=axonserver-data,target=/data \--mount source=axonserver-eventdata,target=/eventdata axoniq/axonserver
If you want to run the clients in Docker containers as well, and are not using something like Kubernetes, use the
--hostname option of the
docker command to set a useful name like
$ docker run -d --name my-axon-server -p 8024:8024 -p 8124:8124 \--hostname axonserver axoniq/axonserver
When you start the client containers, you can now use
--link axonserver to provide them with the correct DNS entry. Alternatively you can define a network in docker and run axonserver and the clients in the same network.
The Axon Server-connector looks at the
axon.axonserver.servers property to determine where Axon Server lives, so don't forget to set it to
axonserver and pass it to your app.
For more information on the environment variables you can use to tweak settings, see Customizing the Docker image of Axon Server.
Warning: Although you can get a pretty functional cluster running locally using Minikube, you can run into trouble when you want to let it serve clients outside of the cluster. Minikube can provide access to HTTP servers running in the cluster, for other protocols you have to run a special protocol-agnostic proxy like you can with
kubectl port-forward <pod-name> <port-number>. For non-development scenarios, we do not recommend using Minikube.
Deployment requires the use of a YAML descriptor, defining a StatefulSet for Axon Server, with two Services to provide access to the HTTP and gRPC ports:
apiVersion: apps/v1kind: StatefulSetmetadata:name: axonserverlabels:app: axonserverspec:serviceName: axonserverreplicas: 1selector:matchLabels:app: axonservertemplate:metadata:labels:app: axonserverspec:containers:- name: axonserverimage: axoniq/axonserverimagePullPolicy: Alwaysports:- name: grpccontainerPort: 8124protocol: TCP- name: guicontainerPort: 8024protocol: TCPvolumeMounts:- name: eventstoremountPath: /eventdata- name: datamountPath: /datareadinessProbe:httpGet:port: 8024path: /actuator/infoinitialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 1volumeClaimTemplates:- metadata:name: eventstorespec:accessModes: [ "ReadWriteOnce" ]resources:requests:storage: 5Gi- metadata:name: dataspec:accessModes: [ "ReadWriteOnce" ]resources:requests:storage: 1Gi---apiVersion: v1kind: Servicemetadata:name: axonserver-guilabels:app: axonserver-guispec:ports:- name: guiport: 8024targetPort: 8024selector:app: axonservertype: LoadBalancer---apiVersion: v1kind: Servicemetadata:name: axonserverlabels:app: axonserverspec:ports:- name: grpcport: 8124targetPort: 8124clusterIP: Noneselector:app: axonserver
To run it, use the following commands:
$ kubectl apply -f kubernetes/axonserver.yamlstatefulset.apps "axonserver" createdservice "axonserver-gui" createdservice "axonserver" created$ kubectl port-forward axonserver-0 8124Forwarding from 127.0.0.1:8124 -> 8124Forwarding from [::1]:8124 -> 8124
You can now run the Giftcard app, which will connect through the proxied gRPC port. To see the Axon Server Web GUI, use
minikube service --url axonserver-gui to obtain the URL for your browser. Actually, if you leave out the
--url, Minikube will open the the GUI in your default browser for you.
To clean up the deployment, use:
$ kubectl delete sts axonserverstatefulset.apps "axonserver" deleted$ kubectl delete svc axonserverservice "axonserver" deleted$ kubectl delete svc axonserver-guiservice "axonserver-gui" deleted
axonserver (as that is the name of the Kubernetes service) if you're going to deploy the client next to the server in the cluster, which is what you'ld probably want. Running the client outside the cluster, with Axon Server inside, entails extra work to enable and secure this, and is definitely beyond the scope of this example.