artemiscloud / activemq-artemis-broker-image

ActiveMQ Artemis Broker Image Reposifory
Apache License 2.0
10 stars 14 forks source link

Allow defining addresses and queues for local testing #22

Closed turing85 closed 1 year ago

turing85 commented 1 year ago

Background

In the process of migrating away from image vromero/actiemq-artemis, for local deployment via docker-compose, I tried to define addresses and queue on application startup, but was not able to. It would be nice to have this capability.

The exact method on providing the queues needed is secondary, as long as it is convenient enough to be used in a docker-compose.yml and flexible enough to allow common use cases.

Story

As a user who uses this image for local deployment When I need to define pre-defined addresses and queues Then I can define the addresses and queues needed.

brusdev commented 1 year ago

The activemq-artemis-broker-image container image is the base of the activemq-artemis-broker-kubernetes-image container image. The activemq-artemis-broker-kubernetes-image container image supports AMQ_ADDRESSES and AMQ_QUEUES environment variables to define addresses and queues on application startup.

Docker Compose makes deploying microservice applications very easy but it has some limitations for a production environment. I would take a look to the open source artemiscloud operator project that provide a way to deploy the Apache ActiveMQ Artemis Broker on Kubernetes.

cescoffier commented 1 year ago

Good to know about activemq-artemis-broker-kubernetes-image. Wondering if thew Quarkus Dev Service should switch to that image instead of activemq-artemis-broker-image.

turing85 commented 1 year ago

The activemq-artemis-broker-image container image is the base of the activemq-artemis-broker-kubernetes-image container image. The activemq-artemis-broker-kubernetes-image container image supports AMQ_ADDRESSES and AMQ_QUEUES environment variables to define addresses and queues on application startup.

Docker Compose makes deploying microservice applications very easy but it has some limitations for a production environment. I would take a look to the open source artemiscloud operator project that provide a way to deploy the Apache ActiveMQ Artemis Broker on Kubernetes.

This sounds reasonable. Do we have documentation on how to use those environment variables? In particular: How can we define an address foo with queues bar and baz?

brusdev commented 1 year ago

TL;DR; There is no way to define an address foo with queues bar and baz using AMQ_ADDRESSES and AMQ_QUEUES environment variables, you can only define addresses without queues or queues that matches the relative address name. For other advanced settings you could mount your custom broker.xml.

The AMQ_ADDRESSES and AMQ_QUEUES environment variables are passed to the artemis create command, i.e. artemis create --addresses $AMQ_ADDRESSES --queues $AMQ_QUEUES ..., for further details see https://github.com/artemiscloud/activemq-artemis-broker-kubernetes-image/blob/v1.0.11/modules/activemq-artemis-launch/added/launch.sh#L591

$ artemis help create
...
OPTIONS
        --addresses <addresses>
            Comma separated list of addresses
...
        --queues <queues>
            Comma separated list of queues with the option to specify a routing
            type. (ex: --queues myqueue,mytopic:multicast)
...            
turing85 commented 1 year ago

Where exactly would we mount the broker.xml?

brusdev commented 1 year ago

A custom configure_custom_config.sh file can be used to edit or overwrite the broker configuration files. i.e.

#!/bin/sh
set -e

INSTANCE_DIR=$1

cat <<EOT > $INSTANCE_DIR/etc/broker.xml
<?xml version='1.0'?>
<configuration xmlns="urn:activemq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xi="http://www.w3.org/2001/XInclude"
               xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
   <core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="urn:activemq:core ">
         <!-- my costom settings -->
   </core>
</configuration>
EOT
docker run -it --rm --name artemis -e AMQ_USER=admin -e AMQ_PASSWORD=admin -p 8161:8161 -v $(pwd)/configure_custom_config.sh:/opt/amq/bin/configure_custom_config.sh quay.io/artemiscloud/activemq-artemis-broker-kubernetes:latest
turing85 commented 1 year ago

Yes this works :slightly_smiling_face: a more convenient way would be nice, but it gets the job done (I have moved the configuration to a separate broker.xml that I then move/copy to INSTANCE_DIR).