One Publisher One Subscriber

In this step, you will see how queues and topics behave differently, even when only one subscriber (receiver) is connected.

You will be sending your messages to topics in this lab.

Select the top left terminal and run the following command to start the publisher (sender), note that in the this lab, the type is now set to topic, unlike in the previous lab where it was set to queue:

java -jar ./bin/amazon-mq-client.jar -url $url -mode sender -type topic -destination demo.topicA -name Sender-1

You should see a log output like the following:

[ActiveMQ Task-1] INFO org.apache.activemq.transport.failover.FailoverTransport - Successfully connected to ssl://b-4e4bfd69-7b83-4a27-9faf-4684cfa80443-2.mq.eu-central-1.amazonaws.com:61617
12.04.2018 12:00:58.369 - Sender: sent '[topic://workshop.topicA] [Sender-1] Message number 1'
12.04.2018 12:00:58.395 - Sender: sent '[topic://workshop.topicA] [Sender-1] Message number 2'
12.04.2018 12:00:58.419 - Sender: sent '[topic://workshop.topicA] [Sender-1] Message number 3'
...

Watch the message numbers increment for 10 seconds. Now select the bottom left terminal and run the following command to start a receiver. Again note that this is of type topic.

java -jar ./bin/amazon-mq-client.jar -url $url -mode receiver -type topic -destination demo.topicA

The receiver is receiving messages published on the topic by the sender and you should see a log output like the following:

[ActiveMQ Task-1] INFO org.apache.activemq.transport.failover.FailoverTransport - Successfully connected to ssl://b-4e4bfd69-7b83-4a27-9faf-4684cfa80443-2.mq.eu-central-1.amazonaws.com:61617
12.04.2018 12:01:03.672 - Receiver: received '[topic://workshop.topicA] [Sender-1] Message number 1'
12.04.2018 12:01:03.772 - Receiver: received '[topic://workshop.topicA] [Sender-1] Message number 2'
12.04.2018 12:01:03.673 - Receiver: received '[topic://workshop.topicA] [Sender-1] Message number 3'
...

Note that the receiver starts to receive only the new messages that are being sent by the sender. The messages that were sent to the topic before the consumer connected are lost. You can see how this behaves by stopping the receiver by pressing CTRL + C in the bottom left terminal, and then starting it again.