This guide shows you how to send and receive messages using Apache Qpid JMS and ActiveMQ Artemis on Kubernetes. 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 Qpid JMS API to perform messaging operations.
-
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 broker --image docker.io/ssorj/activemq-artemis deployment.apps/broker created $ kubectl expose deployment/broker --port 5672 service/broker exposed
-
Change directory to the sender application, build it, create a deployment, and expose it as a service:
$ cd sender/ $ mvn package [Maven output] $ docker build -t sender . [Docker output] $ kubectl run sender --image sender --image-pull-policy Never --env MESSAGING_SERVICE_HOST=broker deployment.apps/sender created $ kubectl expose deployment/sender --port 8080 --type NodePort service/sender exposed
-
Change directory to the receiver application, build it, create a deployment, and expose it as a service:
$ cd ../receiver/ $ mvn package [Maven output] $ docker build -t receiver . [Docker output] $ kubectl run receiver --image receiver --image-pull-policy Never --env MESSAGING_SERVICE_HOST=broker deployment.apps/receiver created $ kubectl expose deployment/receiver --port 8080 --type NodePort service/receiver exposed
-
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 sender --url) $ receiver_url=$(minikube service receiver --url)
-
Use
curl
to test the readiness of the send and receive services:$ curl $sender_url/api/ready OK $ curl $receiver_url/api/ready OK
-
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 -X POST $receiver_url/api/receive hello1 $ curl -X POST $receiver_url/api/receive hello2 $ curl -X POST $receiver_url/api/receive hello3