The tasks for the labs are:
Download and unpack either ActiveMQ 5.17 or ActiveMQ Artemis 2.21.
Specification of message passing API for Java.
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 and unpack https://d3s.mff.cuni.cz/files/teaching/nswi080/labs/Files/sources-3.zip .
Example-Classic is a simple producer-consumer exampleExample-Artemis version for the Artemis providerInput-Classic base for implementing the homework assignmentInput-Artemis version for the Artemis providerFor more examples, you can also look at:
The example shows how to send and receive messages to and from queues (producer-consumer)
ExampleQueue1 and ExampleQueue2ExampleQueue1 and ExampleQueue2setMessageListener, tell the consumer to call MessageListener of the specified object whenever a message is receivedactivemq starts the brokermake compile sourcesproducer, consumer run applicationsinstall script configures the brokeractivemq starts the brokermake compile sources using Mavenproducer, consumer run applications using Mavensetenv scripts to point to the extracted ActiveMQ implementation directory.Start message broker
bash activemq startbash activemq stopbash activemq consoleRunning the example
bash make to compile java codebash consumer to run the consumer (will be blocked until a message arrives to ExampleQueue1)bash producer to run the producerConfigure message broker
bash installStart message broker
bash activemq runbash activemq stopRunning the example
bash make to compile java codebash consumer to run the consumer (will be blocked until a message arrives to ExampleQueue1)bash producer to run the producerYou 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.
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:
broker/etc/broker.xml in the directory when you ran bash install. Network is configured in the acceptors tag.conf/activemq.xml in the root of the unpacked ActiveMQ archive. Network is configured in the transportConnectors tag.tcp://lab.d3s.mff.cuni.cz:5000
LabQueueLabTopicLabTopic (see code below)TextMessage containing the nickname to LabQueueTextMessage from LabTopic containing the hash?jms.watchTopicAdvisories=false to the connection stringYou 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);
https://d3s.mff.cuni.cz/files/teaching/nswi080/labs/Files/task-3-en.html
Task: a simple trading system
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.
BankGoodsClientp - publish the list of goods to other clientsl - print goods lists of other clientsb - buy goods
bash make to compile java codebash bank to run the bankbash client NAME to run a client