1 package de.spring.stomp.controllers;
3 import java.time.LocalDateTime;
5 import org.springframework.messaging.handler.annotation.MessageMapping;
6 import org.springframework.stereotype.Controller;
9 public class MessageGreetingController {
11 // Sending data to /app/greeting from STOMP client (client must first connect to endpoint, in my case portfolio)
12 // connecting to this URL -> http://172.17.0.3/spring-stomp-server/portfolio
13 // sending data to /app/greeting
15 // The data sent to /app/greeting will retrieved by this method.
16 @MessageMapping("/greeting")
17 public String handle(String greeting) {
18 // STOMP clients subscribed to /topic/greeting will receive the returned data from this method.
19 // Destination is selected based on a convention but can be overridden via @SendTo
20 return "[" + LocalDateTime.now() + ": " + greeting;