Creating the Queues

Queues are created when the application first attempts to read from or write to them. You can pre-create them instead using broker properties, an Init Container, or an ActiveMQArtemisAddress custom resource (CR).

Broker Properties

Artemis Cloud broker can accept broker properties that apply values after broker.xml has been read.

Broker Properties are added by the ActiveMQArtemis Custom Resource (CR). For example, the following broker properties add a queue named demo-one.

apiVersion: broker.amq.io/v1beta1
kind: ActiveMQArtemis
metadata:
  name: artemis-broker
spec:
  ...
  brokerProperties:
    - 'addressConfigurations.demo-one.routingTypes=ANYCAST'
    - 'addressConfigurations.demo-one.queueConfigs.demo-one.address=demo-one'
    - 'addressConfigurations.demo-one.queueConfigs.demo-one.routingType=ANYCAST'

Because broker properties use dot notation, you must quote any strings that contain the dot character. For example, create a queue named demo.two with the following broker properties:

apiVersion: broker.amq.io/v1beta1
kind: ActiveMQArtemis
metadata:
  name: artemis-broker
spec:
  ...
  brokerProperties:
    - 'addressConfigurations."demo.two".routingTypes=ANYCAST'
    - 'addressConfigurations."demo.two".queueConfigs."demo.two".address=demo.two'
    - 'addressConfigurations."demo.two".queueConfigs."demo.two".routingType=ANYCAST'
Note: There is no feedback if you provide an invalid broker property. The property is silently ignored.

For more information, see the discussion about broker properties in Artemis Cloud component documentation at the ActiveMQ website.

Init Container

The Artemis Cloud operator allows you to specify a custom image for configuration of the broker. The custom image must be based on quay.io/artemiscloud/activemq-artemis-broker-init:artemis.2.33.0 and contain a post-config.sh script which allows you to define the modification.

The following is an example dockerfile for an Init Container image:

FROM quay.io/artemiscloud/activemq-artemis-broker-init:artemis.2.33.0
 
# Install yq for xml processing
USER root
RUN pip3 install yq
USER 185
 
# Add the post-config.sh script
ADD post-config.sh /amq/scripts/post-config.sh
 
# Add xml includes
ADD mtx-*.xml /amq/includes/

The following is the post-config.sh script referenced in the dockerfile:

#!/bin/bash
XML_INCLUDE_PATH="/home/jboss/amq-broker/etc"
BROKER_XML_FILE="${CONFIG_INSTANCE_DIR}/etc/broker.xml"
 
# add the includes at the end of the broker.xml
sed -i "s|</core>|<xi:include href=\"file://${XML_INCLUDE_PATH}/mtx-addresses.xml\"/>      </core>|g" ${BROKER_XML_FILE}
 
# remove the existing addresses (using the xq tool)
xq -x --in-place '.configuration.core.addresses=[]' ${BROKER_XML_FILE}
 
# copy the xml fragments to include
cp -rv /amq/includes/*.xml ${CONFIG_INSTANCE_DIR}/etc/

The following custom-addresses.xml file defines two queues: demo.one and demo.two:

<addresses xmlns="urn:activemq:core">
   <address name="demo.one">
      <anycast>
         <queue name="demo.one" />
      </anycast>
   </address>
   <address name="demo.two">
      <anycast>
         <queue name="demo.two" />
      </anycast>
   </address>
</addresses>

Build the image and push it to your repository with the following commands:

docker build . -t repository_domain:repository_port/custom-artemis-cloud-init:1.0.0
docker push repository_domain:repository_port/custom-artemis-cloud-init:1.0.0

The Artemis Cloud CR references the image with the initImage property:

apiVersion: broker.amq.io/v1beta1
kind: ActiveMQArtemis
metadata:
  name: artemis-broker
spec:
  ...
  deploymentPlan:
    initImage: localhost:32000/custom-artemis-cloud-init:1.0.0

ActiveMQArtemisAddress Custom Resource

Note: The following is a minimal example. For more information see the discussion about address CR configuration at the Artemis Cloud website.

The Artemis Cloud operator can read ActiveMQArtemisAddress CRs to create queues as shown in the following CR definition:

kind: ActiveMQArtemisAddress
metadata:
  name: name
spec:
  addressName: name
  queueName: name
  routingType: anycast
  removeFromBrokerOnDelete: true

Create the CR in the namespace where the broker is deployed using the kubectl apply command. Replace name with the name of the queue.