Spring Core

Exercise: Chat Application (Basic Messaging)

  1. Run the ActiveMQ Classic message broker:
    docker run --name activemq -p 8161:8161 -p 61616:61616 -d apache/activemq-classic
    
  2. Create a Spring application with the starters spring-boot-starter-activemq and spring-boot-starter-json as dependencies.
  3. Define application properties that provide the URL of the ActiveMQ Classic message broker and enable the publish-subscribe domain:
    spring.activemq.broker-url=tcp://localhost:61616
    spring.jms.pub-sub-domain=true
    
  4. Implement a publisher and a listener component that allow a user to send text messages to and receive text messages from the topic ChatTopic.
  5. Add a property user to the messages that identifies the sender of the message and display it.
  6. Define a message selector such that the sender's own messages are not received.

Solution