Skip to content
Sample project to demostrate Keda External Scaler
Go Java Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
consumer initial Nov 2, 2019
k8s-manifest initial Nov 2, 2019
metrics-provider initial Nov 2, 2019
producer initial Nov 2, 2019
.gitignore initial Nov 2, 2019
LICENSE initial Nov 2, 2019 add badge. Nov 2, 2019
skaffold.yaml initial Nov 2, 2019

Keda External Scaler with ActiveMQ Artemis

This is a demonstration on how to use KEDA's external scaler to monitor ActiveMQ Artemis Queue.

The Keda external scaler calls metrics-provider GRPC server which will collect the metrics from ActiveMQ Artemis.

Note: use your own docker repository while building the project.


  • Kubernetes cluster
  • Keda installed in the cluster.
  • skaffold - used to build the images
  • maven - use to build the java consumer and producer project.

Code organization

  • consumer - a simple Springboot application which consumes messages from ActiveMQ Artemis. The queue name used is test. The consumerWindowSize is also set to 0 so that it will not buffer the messages to one consumer.
  • producer - a simple Springboot application which pumps messages to the queue test
  • metrics-provider - a Go application which serves as the GRPC server to serve the Keda External Scaler. It queries ActiveMQ Artemis MessageCount using the built -in jolokia endpoint exposed by Artemis.
  • k8s-manifest - everything Kubernetes

Building the metrics provider for external scaler

You can get the proto file from the Keda github.

This project already contains the externalscaler.proto

Use protoc to autogenerate the Proto codes.

protoc -I externalscaler/ externalscaler/proto/externalscaler.proto --go_out=plugins=grpc:externalscaler

Note: We use kaniko in-cluster builder

Setup kaniko registry access secret

kubectl -n artemis create secret generic regcred --from-file $HOME/.docker/config.json

$ skaffold run -p metrics-provider

External Scaler as ActiveMQ Artemis sidecar

The docker image used taken from vromero/activemq-artemis-docker uses the hostname as its broker name, in order to avoid hardcoding the broker name, the metrics provider is deployed as a sidecar to ActiveMQ Artemis.

Added to the file k8s-manifest/artemis/deployment.yaml

  - name: artemis-activemq-metrics-provider
    args: ["--port","5050","--broker","$(POD_NAME)", "--user", "$(ARTEMIS_USERNAME)","--password","${ARTEMIS_PASSWOORD)"]
    imagePullPolicy: Always
        cpu: 100m
        memory: 10Mi   

Build and deploy the consumer.

Using skaffold and jib, simply execute the command below.

skaffold run -p consumer

Please make sure that you use your docker repository.

Deploy the External Scaler manifest

Now its time to setup the KEDA's external scaler.

kubectl apply -f k8s-manifest/externalscaler_scaledobject.yaml

The file looks like this.

kind: ScaledObject
  name: artemis-scaledobject
  namespace: artemis
    deploymentName: artemis-consumer
  pollingInterval: 10   # Optional. Default: 30 seconds
  cooldownPeriod: 100  # Optional. Default: 300 seconds
  minReplicaCount: 0   # Optional. Default: 0
  maxReplicaCount: 30  # Optional. Default: 100  
    deploymentName: artemis-consumer
  - type: external
      scalerAddress: artemis-activemq.artemis:5050
      queueLength: "10"
      brokerAddress: "test"
      queueName: "test"


  • scalerAddress: is the location of the GRPC metrics provider host and port.
  • queueLength: the target queue length.
  • brokerAddress: An address represents a messaging endpoint. Within the configuration, a typical address is given a unique name, 0 or more queues, and a routing type.
  • queueName: the name of queue to monitor.

Before pumping in messages, check the HPA.

Check the HPA

kubectl -n artemis get hpa
NAME                        REFERENCE                     TARGETS              MINPODS   MAXPODS   REPLICAS   AGE
keda-hpa-artemis-consumer   Deployment/artemis-consumer   <unknown>/20 (avg)   1         30        0          58m

At this point,HPA doesn't have the TargetAverageValue to scale up or down the pods. This can be observed by the <unknown>/20(avg)

Start the producer

The producer is a simple Springboot application.

If you are going to run the Springboot application using your IDE, make sure that you point to the host and port of the ActiveMQ Artemis.

Check the file application.yml

As an example:

    mode: native
    port: ${ARTEMIS_SERVER_PORT:61616}
    user: ${ARTEMIS_USERNAME:artemis}
    password: ${ARTEMIS_PASSWORD:artemis}

In the Class

You can modify how much messages you want to send to the broker. In the example below, the program is pushing 10000 messages to the broker, with a delay of 200 milliseonds.

public void run(String... args) throws Exception {
	for (int i = 0; i < 10000; i++){
		producer.send("Message is: " + System.currentTimeMillis());

Checking the scaling up of the pods.

$ kubectl -n artemis get pods
NAME                                READY   STATUS              RESTARTS   AGE
artemis-activemq-66c66ffdcc-9f7hq   2/2     Running             0          15m
artemis-consumer-589c9b87f7-mldrx   0/1     ContainerCreating   0          4s
artemis-consumer-589c9b87f7-mltqx   1/1     Running             0          14s

Scale to zero

Once you stop the producer program, KEDA will determine that messages are no longer coming and will scale down the pods to zero.

$kubectl -n artemis get pods -w
NAME                                READY   STATUS    RESTARTS   AGE
artemis-activemq-66c66ffdcc-9f7hq   2/2     Running   0          16m
artemis-consumer-589c9b87f7-8xwq6   1/1     Running   0          43s
artemis-consumer-589c9b87f7-k2bf5   1/1     Running   0          12s
artemis-consumer-589c9b87f7-mldrx   1/1     Running   0          58s
artemis-consumer-589c9b87f7-mltqx   1/1     Running   0          68s
artemis-consumer-589c9b87f7-mltqx   1/1     Terminating   0          81s
artemis-consumer-589c9b87f7-8xwq6   1/1     Terminating   0          56s
artemis-consumer-589c9b87f7-mldrx   1/1     Terminating   0          71s
artemis-consumer-589c9b87f7-k2bf5   1/1     Terminating   0          25s
artemis-consumer-589c9b87f7-8xwq6   0/1     Terminating   0          57s
artemis-consumer-589c9b87f7-mldrx   0/1     Terminating   0          72s
artemis-consumer-589c9b87f7-k2bf5   0/1     Terminating   0          27s
artemis-consumer-589c9b87f7-mldrx   0/1     Terminating   0          73s
artemis-consumer-589c9b87f7-mldrx   0/1     Terminating   0          73s
artemis-consumer-589c9b87f7-mltqx   0/1     Terminating   0          83s

Clean up

Delete the consumer

skaffold delete -p consumer

Delete ActiveMQ Artemis and the metrics provider

skaffold delete -p metrics-provider

Delete the External Scaler object

kubectl delete -f k8s-manifest/externalscaler_scaledobject.yaml

Verify that the HPA is successfully deleted

kubectl -n artemis get hpa

You can’t perform that action at this time.