Lab 3 - JMS

The tasks for the labs are:

Download a JMS Provider

Download and unpack either ActiveMQ 5.17 or ActiveMQ Artemis 2.21.

JMS

Specification of message passing API for Java.

JMS Provider

Multiple commercial or open source implementations of JMS exist. Use one of these implementations:

The differences for the purpose of these labs is very small:

If using Java 8, then use ActiveMQ Classic 5.16.4 or ActiveMQ Artemis 2.19.1.

Download source code

Download and unpack https://d3s.mff.cuni.cz/files/teaching/nswi080/labs/Files/sources-3.zip .

Materials from lectures

For more examples, you can also look at:

Explore example source codes

The example shows how to send and receive messages to and from queues (producer-consumer)

Java Sources

Build / run scripts

Run the example

ActiveMQ Classic

ActiveMQ Artemis

Note

You may encounter a warning WARNING: An illegal reflective access operation has occurred, or SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".. These warnings should not affect the working of the programs and can be ignored.

Network configuration

The message broker by default listens on tcp://0.0.0.0:61616 and running the examples and solving the tasks does not require any change to the configuration. If you want to change it, see:

Lab activity task

Code

You can use the following code snippets to modify the example:

Connect to the broker (when using ActiveMQ Classic):

ActiveMQConnectionFactory connectionFactory =
  new ActiveMQConnectionFactory("labUser", "sieb5w9", "tcp://lab.d3s.mff.cuni.cz:5000?jms.watchTopicAdvisories=false");

Connect to the broker (when using ActiveMQ Artemis):

ActiveMQConnectionFactory connectionFactory =
  new ActiveMQConnectionFactory("tcp://lab.d3s.mff.cuni.cz:5000", "labUser", "sieb5w9");

Create a message consumer for LabTopic:

Topic topic = session.createTopic("LabTopic");
MessageConsumer consumer = session.createConsumer(topic);
consumer.setMessageListener(...);

Create a message producer for LabQueue:

Queue queue = session.createQueue("LabQueue");
MessageProducer producer = session.createProducer(queue);

Read the homework assignment

Explore assignment source codes

The source code (Input-Classic or Input-Artemis) is a base for your solution. You will need to design the application protocol and implement the missing parts.

Bank

Goods

Client

Running