Module 5: Produce and Consume Messages

Objectives

  • Send messages from SNO edge brokers using regional addresses

  • Consume those messages at hub-01 (federation)

  • Confirm hub-colocated spoke-* URLs are not this exercise

Hub-01 in these steps is the AMQ hub on this regional ACM hub, not Global Hub. messages.NY.5604 should appear on hub-01; messages.NY.5603 must not.

NY and NJ site brokers federate over AMQPS to AMQ hub-01 on regional ACM east. messages.NY.5604 reaches the AMQ hub; messages.NY.5603 stays on the SNO. Global Hub has no AMQ broker.
Figure 1. Mode 2 messaging — 5604 reaches AMQ hub-01; 5603 stays on the SNO

Steps

1. Start a Consumer on the Hub

Start the consumer before producing messages. Topic (multicast) subscriptions only receive messages sent after the subscription is created.

Open a terminal and run:

oc -n artemis run consumer -ti \
  --image=registry.redhat.io/amq7/amq-broker-rhel9:7.14 \
  --rm=true --restart=Never -- /bin/bash

Inside the container:

/opt/amq/bin/artemis consumer \
  --url=amqp://hub-01-broker-amqp-acceptor-0-svc.artemis.svc.cluster.local:5672 \
  --protocol=AMQP --user=bob --password=bosco \
  --destination=topic://messages.NY.5604 --message-count=5 --receive-timeout=60000 --verbose
If bob/bosco fails with a SASL authentication error, use admin/admin instead.

Leave this consumer running and open a second terminal for the next step. After the NY producer finishes, the consumer prints five Received lines and Consumed: 5 messages. JMS Message IDs and elapsed time differ every run.

Expected output (hub consumer on messages.NY.5604, after NY produce)
Consumer messages.NY.5604, thread=0 Received hello from NY SNO
Consumer messages.NY.5604, thread=0 Received hello from NY SNO
Consumer messages.NY.5604, thread=0 Received hello from NY SNO
Consumer messages.NY.5604, thread=0 Received hello from NY SNO
Consumer messages.NY.5604, thread=0 Received hello from NY SNO
Consumer messages.NY.5604, thread=0 Consumed: 5 messages

2. Produce from the NY SNO

Use the sno-edge-01 AMQPS Route. SNO brokers use admin / admin.

oc -n artemis run producer-ny -ti \
  --image=registry.redhat.io/amq7/amq-broker-rhel9:7.14 \
  --rm=true --restart=Never -- /opt/amq/bin/artemis producer \
  --url='amqps://spoke-01-broker-amqps-acceptor-0-svc-rte-artemis.apps.sno-edge-01.%sandbox_guid%.gcp.redhatworkshops.io:443?sslEnabled=true&transport.trustAll=true&transport.verifyHost=false&useTopologyForLoadBalancing=false' \
  --protocol=AMQP --user=admin --password=admin \
  --message-count=5 --message='hello from NY SNO' \
  --destination=topic://messages.NY.5604 --verbose
Expected output
Producer messages.NY.5604, thread=0 Sent: hello from NY SNO
Producer messages.NY.5604, thread=0 Sent: hello from NY SNO
Producer messages.NY.5604, thread=0 Sent: hello from NY SNO
Producer messages.NY.5604, thread=0 Sent: hello from NY SNO
Producer messages.NY.5604, thread=0 Sent: hello from NY SNO
Producer messages.NY.5604, thread=0 Produced: 5 messages

The hub consumer in step 1 should then show the five messages.NY.5604 messages (see that step’s expected output). Elapsed-time lines differ every run.

3. Prove 5603 stays on the SNO

Produce five messages to messages.NY.5603 on the NY SNO. Because *.5603 is excluded from federation, these messages stay on the edge broker and never reach hub-01. Use Jolokia MessageCount to prove it.

oc -n artemis run producer-5603 -ti \
  --image=registry.redhat.io/amq7/amq-broker-rhel9:7.14 \
  --rm=true --restart=Never -- /opt/amq/bin/artemis producer \
  --url='amqps://spoke-01-broker-amqps-acceptor-0-svc-rte-artemis.apps.sno-edge-01.%sandbox_guid%.gcp.redhatworkshops.io:443?sslEnabled=true&transport.trustAll=true&transport.verifyHost=false&useTopologyForLoadBalancing=false' \
  --protocol=AMQP --user=admin --password=admin \
  --message-count=5 --message='stays on NY SNO' \
  --destination=topic://messages.NY.5603 --verbose

Now query the SNO broker — the messages should be there:

curl -sS -u admin:admin \
  'http://spoke-01-broker-wconsj-0-svc-rte-artemis.apps.sno-edge-01.%sandbox_guid%.gcp.redhatworkshops.io/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22,component=addresses,address=%22messages.NY.5603%22/RoutedMessageCount' \
  | python3 -m json.tool
Expected output
{
    "value": 5
}

RoutedMessageCount >= 5 on the SNO confirms the messages were accepted. They stay on the edge because *.5603 has no federation address match.

The 5604 consumer from step 1 also receives nothing from this produce — 5603 is a different address and is excluded from federation.

4. Produce from the NJ SNO

NJ uses messages.NJ.5604. Start a hub consumer on that address first.

After starting the NJ consumer, wait ~30 seconds before producing. Federation needs time to propagate the address demand from hub-01 to sno-edge-02. If the first produce shows no messages on the consumer, produce again — the demand is now active.
/opt/amq/bin/artemis consumer \
  --url=amqp://hub-01-broker-amqp-acceptor-0-svc.artemis.svc.cluster.local:5672 \
  --protocol=AMQP --user=bob --password=bosco \
  --destination=topic://messages.NJ.5604 --message-count=5 --receive-timeout=60000 --verbose
oc -n artemis run producer-nj -ti \
  --image=registry.redhat.io/amq7/amq-broker-rhel9:7.14 \
  --rm=true --restart=Never -- /opt/amq/bin/artemis producer \
  --url='amqps://spoke-02-broker-amqps-acceptor-0-svc-rte-artemis.apps.sno-edge-02.%sandbox_guid%.gcp.redhatworkshops.io:443?sslEnabled=true&transport.trustAll=true&transport.verifyHost=false&useTopologyForLoadBalancing=false' \
  --protocol=AMQP --user=admin --password=admin \
  --message-count=5 --message='hello from NJ SNO' \
  --destination=topic://messages.NJ.5604 --verbose
Expected output
Producer messages.NJ.5604, thread=0 Sent: hello from NJ SNO
Producer messages.NJ.5604, thread=0 Sent: hello from NJ SNO
Producer messages.NJ.5604, thread=0 Sent: hello from NJ SNO
Producer messages.NJ.5604, thread=0 Sent: hello from NJ SNO
Producer messages.NJ.5604, thread=0 Sent: hello from NJ SNO
Producer messages.NJ.5604, thread=0 Produced: 5 messages
Expected output (hub consumer, after NJ produce)
Consumer messages.NJ.5604, thread=0 Received hello from NJ SNO
Consumer messages.NJ.5604, thread=0 Received hello from NJ SNO
Consumer messages.NJ.5604, thread=0 Received hello from NJ SNO
Consumer messages.NJ.5604, thread=0 Received hello from NJ SNO
Consumer messages.NJ.5604, thread=0 Received hello from NJ SNO
Consumer messages.NJ.5604, thread=0 Consumed: 5 messages

maxHops=1 on remote-policy-5604 means NJ 5604 reaches AMQ hub-01 and does not hop to the NY SNO.

The SNO remote address policy pushes messages.{region}. to hub-01. messages.ALL. is pulled from the hub onto the SNO, not the reverse.

5. CT region

This catalog item has no sno-edge-03. First pass is NY and NJ on east only. Skip CT.

The artemis CLI does not support --protocol=MQTT. Native MQTT would target the SNO MQTT acceptor, which is not exposed on a Route in this demo.