This guide shows you how to send and receive messages using Apache Qpid JMS and ActiveMQ Artemis on Kubernetes using a Quarkus Qpid JMS extension. It uses the AMQP 1.0 message protocol to send and receive messages.
The example application has three parts:
-
An AMQP 1.0 message broker, ActiveMQ Artemis
-
A sender service exposing an HTTP endpoint that converts HTTP requests into AMQP 1.0 messages. It sends the messages to a queue called
example/strings
on the broker. -
A receiver service that consumes AMQP messages from
example/strings
. It exposes another HTTP endpoint that returns the messages as HTTP responses.
The sender and the receiver use the JMS API to perform messaging operations.
-
Optional: For native builds without using docker, GraalVM version 19.1.1+ installed, with
GRAALVM_HOME
set and native-image extension.
-
Change directory to the sender application, build it to prepare for creating a docker image to deploy.
$ cd sender/ $ mvn package -Pnative -Dnative-image.docker-build=true [Maven output] cd ../
-
Change directory to the receiver application, build it to prepare for creating a docker image to deploy.
$ cd receiver/ $ mvn package -Pnative -Dnative-image.docker-build=true [Maven output] cd ../
-
Configure your shell to use the Minikube Docker instance:
$ eval $(minikube docker-env) $ echo $DOCKER_HOST tcp://192.168.39.67:2376
-
Create a broker deployment and expose it as a service:
$ kubectl run messaging --generator=run-pod/v1 --image docker.io/ssorj/activemq-artemis pod/messaging created $ kubectl expose pod messaging --type=ClusterIP --port=5672 service/messaging exposed
-
Change directory to the sender application, create a deployment, and expose it as a service:
$ cd sender/ $ docker build -f src/main/docker/Dockerfile.native -t quarkus-jms-sender . [Docker output] $ kubectl apply -f kubernetes.yml service/quarkus-jms-sender created deployment.apps/quarkus-jms-sender created
-
Change directory to the receiver application, create a deployment, and expose it as a service:
$ cd ../receiver/ $ docker build -f src/main/docker/Dockerfile.native -t quarkus-jms-receiver . [Docker output] $ kubectl apply -f kubernetes.yml service/quarkus-jms-receiver created deployment.apps/quarkus-jms-receiver created
-
Check that the deployments and pods are present. You should see deployments and services for
broker
,sender
, andreceiver
.$ kubectl get deployment $ kubectl get service
-
Save the
NodePort
URLs in local variables:$ sender_url=$(minikube service quarkus-jms-sender --url) $ receiver_url=$(minikube service quarkus-jms-receiver --url)
-
Use
curl
to test the readiness of the send and receive services:$ curl $sender_url/health/ready { "status": "UP", "checks": [ ] $ curl $receiver_url/health/ready { "status": "UP", "checks": [ ]
-
Use
curl
to send strings to the sender service:$ curl -X POST -H "content-type: text/plain" -d hello1 $sender_url/api/send OK $ curl -X POST -H "content-type: text/plain" -d hello2 $sender_url/api/send OK $ curl -X POST -H "content-type: text/plain" -d hello3 $sender_url/api/send OK
-
Use
curl
to receive the sent strings back from the receiver service:$ curl $receiver_url/api/receive hello1 $ curl $receiver_url/api/receive hello2 $ curl $receiver_url/api/receive hello3