DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Smart Deployment Strategies for Modern Applications
  • How We Diagnosed a Hidden Scheduler Failure in a Docker Swarm Cluster Serving 2 Million Users
  • Java Backend Development in the Era of Kubernetes and Docker
  • Docker Hardened Images for Container Security

Trending

  • Your AI Agent Tests Are Passing, But Your Agent Is Still Broken
  • Every Cache Miss Is a Tiny Tax on Your Performance
  • Building a Zero-Cost Approval Workflow With AWS Lambda Durable Functions
  • RAG Is Not Enough: Advanced Retrieval Architectures Using Vertex AI Search on GCP
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Customized Artemis Broker Configuration With Init Containers on Kubernetes or Openshift

Customized Artemis Broker Configuration With Init Containers on Kubernetes or Openshift

In this article, we will discuss and explore options on how we can customize the configuration for Artemis Broker on Kubernetes or OpenShift.

By 
Chandra Shekhar Pandey user avatar
Chandra Shekhar Pandey
·
Updated May. 18, 21 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
11.7K Views

Join the DZone community and get the full member experience.

Join For Free

Apache ActiveMQ Artemis is a powerful open-source multi-protocol message broker.  Red Hat AMQ 7 is the enterprise distribution of Apache ActiveMQ Artemis. Also, there is artemiscloud.io  available for Kubernetes and OpenShift. 

In this article, we will discuss how we can customize the configuration for Artemis Broker on Kubernetes. This could be helpful for those who are migrating from the Standalone version of AMQ 7 or Artemis to AMQ 7 on OpenShift. For beginners, the using_operator article would be helpful. In this article too, I am referring to this article for basic setup.

I am using minikube version: v1.19.0 for testing this setup on my laptop.  

By default, broker configuration doesn't have to divert configuration. A divert just route messages from one address to another address in the same broker. Thus there is no need for an external connector to move messages from one destination to another, simple broker configuration using divert will move the messages. Following the configuration we will make here exclusive is set as false which means a copy of the message will be routed or forwarded from priceUpdates address/destination to priceForwarding address/destination.

XML
 




x


 
1
<divert name="prices-divert">
2
   <address>priceUpdates</address>
3
   <forwarding-address>priceForwarding</forwarding-address>
4
   <exclusive>false</exclusive>
5
</divert>



So, let's start now 

1. Deploy Artemis Operator

Shell
 




xxxxxxxxxx
1
17


 
1
 $ minikube start -p artemis-operator-1
2
 $ mkdir artemis_cloud
3
 $ cd artemis_cloud/
4
 $ git clone https://github.com/artemiscloud/activemq-artemis-operator.git
5
 $ kubectl create namespace myproject
6
 $ kubectl config set-context --current --namespace=myproject
7
 $ cd activemq-artemis-operator/
8
 $ kubectl create -f deploy/service_account.yaml
9
 $ kubectl create -f deploy/role.yaml
10
 $ kubectl create -f deploy/role_binding.yaml
11
 $ kubectl create -f deploy/crds/broker_activemqartemis_crd.yaml
12
 $ kubectl create -f deploy/crds/broker_activemqartemisaddress_crd.yaml
13
 $ kubectl create -f deploy/crds/broker_activemqartemisscaledown_crd.yaml
14
 $ kubectl create -f deploy/operator.yaml
15
 $ kubectl get pods
16
NAME                                         READY   STATUS    RESTARTS   AGE
17
activemq-artemis-operator-85dddc589d-kqbvl   1/1     Running   0          2m22s
18

          


2. Configurations for Artemis init container:  We need config/post-config.sh file and Dockerfile. Dockerfile refers to artemis-broker-init image, also config folder with post-config.sh file.

Shell
 




x


 
1
$ mkdir init_image
2
$ cd init_image
3
$ tree
4
.
5
├── config
6
│   └── post-config.sh
7
└── Dockerfile
8

          
9
1 directory, 2 files
10
$ cat Dockerfile 
11
FROM quay.io/artemiscloud/activemq-artemis-broker-init:0.2.4
12
ADD config /amq/scripts 
13

          



3. Content of post-config.sh file: Here we are adding divert and address configurations. At the end of the post-config.sh with sed command we are appending these configuration to default broker.xml. Here We don't have to set this CONFIG_INSTANCE_DIR environment variable; it is resolved itself by init container and broker.

Shell
 




x


 
1
$ cat config/post-config.sh 
2
#!/bin/bash
3
echo "#### Custom config start. ####"
4
diverts=""
5
diverts="      ${diverts}<diverts>\n"
6
diverts="      ${diverts} <divert name=\"prices-divert\">\n"
7
diverts="      ${diverts}  <address>priceUpdates</address>\n"
8
diverts="      ${diverts}  <forwarding-address>priceForwarding</forwarding-address>\n"
9
diverts="      ${diverts}  <exclusive>false</exclusive>\n"
10
diverts="      ${diverts} </divert>\n"
11
diverts="      ${diverts}</diverts>\n\n"
12
address=""
13
address="      ${address}<address name=\"priceForwarding\">\n"
14
address="      ${address} <anycast>\n"
15
address="      ${address}  <queue name=\"priceForwarding\" />\n"
16
address="      ${address} </anycast>\n"
17
address="      ${address}</address>\n\n"
18
address="      ${address}<address name=\"priceUpdates\">\n"
19
address="      ${address} <anycast>\n"
20
address="      ${address}  <queue name=\"priceUpdates\" />\n"
21
address="      ${address} </anycast>\n"
22
address="      ${address}</address>\n\n"
23

          
24
sed -i "s|  <addresses>|${diverts}  <addresses> ${address}|g" ${CONFIG_INSTANCE_DIR}/etc/broker.xml
25
echo "#### Custom config done. ####"
26
$ 
27

          
28

          



4. Create a customized init Docker Image.

Shell
 




x
10


 
1
# set docker context to minikube profile artemis-operator-1.
2
$ eval $(minikube -p artemis-operator-1 docker-env)
3
# check if docker context is set for minikube profile artemis-operator-1.
4
$ minikube profile list|grep artemis-operator-1
5
| artemis-operator-1         | kvm2      | docker  | 192.168.50.67  | 8443 | v1.20.2 | Running |     1 |
6
$ docker context ls
7
NAME                DESCRIPTION                               DOCKER ENDPOINT            KUBERNETES ENDPOINT                      ORCHESTRATOR
8
default *           Current DOCKER_HOST based configuration   tcp://192.168.50.67:2376   https://192.168.50.67:8443 (myproject)   swarm
9

          
10
# Finally create docker image.
11
$ docker build -t init-custom:v1 .
12
$ docker images|grep init
13
REPOSITORY                                          TAG                 IMAGE ID            CREATED             SIZE
14
init-custom                                         v1                  c57643837947        16 seconds ago      726MB
15
quay.io/artemiscloud/activemq-artemis-broker-init   0.2.4               636a02126ffc        2 months ago        726MB
16
$ 



5.  Deploy Artemis broker instance using init image we just created: Within the git repository we cloned in first step, we can find examples activemq-artemis-operator/deploy/examples.  We can create a artemis-basic-deployment-init.yaml with same content of artemis-basic-deployment.yaml. Than we can modify artemis-basic-deployment-init.yaml with image as broker image and initImage with the image we created.

Shell
 




x


 
1
$ cp artemis-basic-deployment.yaml artemis-basic-deployment-init.yaml
2
$ cat artemis-basic-deployment-init.yaml
3
apiVersion: broker.amq.io/v2alpha4
4
kind: ActiveMQArtemis
5
metadata:
6
  name: ex-aao
7
spec:
8
  deploymentPlan:
9
    size: 1
10
    image: quay.io/artemiscloud/activemq-artemis-broker-kubernetes:0.2.1
11
    initImage: init-custom:v1
12

          
13
# finally create broker instance
14
$ kubectl apply -f artemis-basic-deployment-init.yaml
15
activemqartemis.broker.amq.io/ex-aao created
16
$ kubectl get pods -w
17
NAME                                         READY   STATUS            RESTARTS   AGE
18
activemq-artemis-operator-85dddc589d-kqbvl   1/1     Running           0          73m
19
ex-aao-ss-0                                  0/1     PodInitializing   0          20s
20

          
21
# In a minute or two
22
$ kubectl get pods
23
NAME                                         READY   STATUS    RESTARTS   AGE
24
activemq-artemis-operator-85dddc589d-kqbvl   1/1     Running   0          94m
25
ex-aao-ss-0                                  1/1     Running   0          21m
26
$ 
27

          



6. Now send some messages to test Divert functionality.

Shell
 




x


 
1
# Send some messages to priceUpdates destination
2
$ kubectl exec ex-aao-ss-0 -n myproject -- /bin/bash /home/jboss/amq-broker/bin/artemis producer --user admin --password admin --url tcp://ex-aao-ss-0:61616 --destination priceUpdates --message-count 5
3
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
4
Connection brokerURL = tcp://ex-aao-ss-0:61616
5
Producer ActiveMQQueue[priceUpdates], thread=0 Started to calculate elapsed time ...
6

          
7
Producer ActiveMQQueue[priceUpdates], thread=0 Produced: 5 messages
8
Producer ActiveMQQueue[priceUpdates], thread=0 Elapsed time in second : 1 s
9
Producer ActiveMQQueue[priceUpdates], thread=0 Elapsed time in milli second : 1328 milli seconds
10

          
11
# check queue stats
12
$ kubectl exec ex-aao-ss-0 -n myproject -- /bin/bash /home/jboss/amq-broker/bin/artemis queue stat --user admin --password admin --url tcp://ex-aao-ss-0:61616
13
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
14
Connection brokerURL = tcp://ex-aao-ss-0:61616
15
|NAME                     |ADDRESS                  |CONSUMER_COUNT |MESSAGE_COUNT |MESSAGES_ADDED |DELIVERING_COUNT |MESSAGES_ACKED |SCHEDULED_COUNT |ROUTING_TYPE |
16
|DLQ                      |DLQ                      |0              |0             |0              |0                |0              |0               |ANYCAST      |
17
|ExpiryQueue              |ExpiryQueue              |0              |0             |0              |0                |0              |0               |ANYCAST      |
18
|activemq.management.1b865d33-fa08-4340-852e-b10d458fb1b9|activemq.management.1b865d33-fa08-4340-852e-b10d458fb1b9|1              |0             |0              |0                |0              |0               |MULTICAST    |
19
|priceForwarding          |priceForwarding          |0              |5             |5              |0                |0              |0               |ANYCAST      |
20
|priceUpdates             |priceUpdates             |0              |5             |5              |0                |0              |0               |ANYCAST      |
21
$ 
22

          



7. Check If broker.xml has divert and address configuration set.

Shell
 




xxxxxxxxxx
1
31


 
1
$ kubectl exec --stdin --tty ex-aao-ss-0 -- /bin/bash
2
[jboss@ex-aao-ss-0 ~]$ pwd
3
/home/jboss
4
[jboss@ex-aao-ss-0 ~]$ cd amq-broker/etc/
5
[jboss@ex-aao-ss-0 etc]$ cat broker.xml 
6

          
7
# to keep this short, removing other content
8
                                              <diverts>
9
 <divert name="prices-divert">
10
  <address>priceUpdates</address>
11
  <forwarding-address>priceForwarding</forwarding-address>
12
  <exclusive>false</exclusive>
13
 </divert>
14
</diverts>
15

          
16
  <addresses>                                                             <address name="priceForwarding">
17
 <anycast>
18
  <queue name="priceForwarding" />
19
 </anycast>
20
</address>
21

          
22
<address name="priceUpdates">
23
 <anycast>
24
  <queue name="priceUpdates" />
25
 </anycast>
26
</address>
27

          
28
# to keep this short, removing other content
29

          
30
[jboss@ex-aao-ss-0 etc]$ exit
31

          


That's it, guys. I hope you will find this article helpful. When containers are immutable, it means any changes at runtime will not persist after pod restart, but with init containers, we can have our own customized image and this will persist during and after restart too.

Kubernetes Docker (software) OpenShift

Opinions expressed by DZone contributors are their own.

Related

  • Smart Deployment Strategies for Modern Applications
  • How We Diagnosed a Hidden Scheduler Failure in a Docker Swarm Cluster Serving 2 Million Users
  • Java Backend Development in the Era of Kubernetes and Docker
  • Docker Hardened Images for Container Security

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook