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
Note: This is not a supported image for production purposes. Please use with caution.
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
axonserver, and pass the
AXONSERVER_HOSTNAME environment variable to adjust the properties accordingly:
$ docker run -d --name my-axon-server -p 8024:8024 -p 8124:8124--hostname axonserver -e AXONSERVER_HOSTNAME=axonserver axoniq/axonserver
When you start the client containers, you can now use
--link axonserver to provide them with the correct DNS entry. 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: TCPreadinessProbe:httpGet:port: 8024path: /actuator/healthinitialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 1---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 throught 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
If you are using a 'real' Kubernetes cluster, you will naturally not want to use
localhost as hostname for Axon Server, so you need to add three lines to the container spec to specify the
...readinessProbe:httpGet:port: 8024path: /actuator/healthinitialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 1env:- name: AXONSERVER_HOSTNAMEvalue: axonserver---apiVersion: v1kind: Service...
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.