Spring Application Services
Exercise: Chat Application (Basic Messaging)
- Run the ActiveMQ Artemis message broker in a docker container:
docker run --name artemis --detach --rm -p 61616:61616 -p 8161:8161
-e ANONYMOUS_LOGIN=true apache/activemq-artemis:latest-alpine
- Create a Spring application with the starters
spring-boot-starter-artemis
and spring-boot-starter-json
as dependencies.
- Define application properties that provide the URL of the ActiveMQ Artemis message broker and enable the publish-subscribe domain:
spring.artemis.broker-url=tcp://localhost:61616
spring.jms.pub-sub-domain=true
- Implement a publisher and a listener component that allow a user to send text messages to and receive text messages from the topic
ChatTopic
.
- Add a property
user
to the messages that identifies the sender of the message and display it.
- Define a message selector such that the sender's own messages are not received.
Solution