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.
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.
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
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
{
"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
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
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.
