--- /dev/null
+package de.spring.stomp.controllers;
+
+import java.time.LocalDateTime;
+
+import org.springframework.messaging.handler.annotation.MessageMapping;
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class MessageGreetingController {
+
+ // Sending data to /app/greeting from STOMP client (client must first connect to endpoint, in my case portfolio)
+ // connecting to this URL -> http://172.17.0.3/spring-stomp-server/portfolio
+ // sending data to /app/greeting
+
+ // The data sent to /app/greeting will retrieved by this method.
+ @MessageMapping("/greeting")
+ public String handle(String greeting) {
+ // STOMP clients subscribed to /topic/greeting will receive the returned data from this method.
+ // Destination is selected based on a convention but can be overridden via @SendTo
+ return "[" + LocalDateTime.now() + ": " + greeting;
+ }
+}
+++ /dev/null
-package de.spring.webservices.rest.controller;
-
-import java.time.LocalDateTime;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.messaging.simp.SimpMessagingTemplate;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
-
-@Controller
-public class GreetingController {
-
- private SimpMessagingTemplate template;
-
- @Autowired
- public GreetingController(SimpMessagingTemplate template) {
- this.template = template;
- }
-
-// @MessageMapping("/greeting")
-// public String handle(String greeting) {
-// return "[" + LocalDateTime.now() + ": " + greeting;
-// }
-
- @RequestMapping(path="/greetings", method=RequestMethod.POST)
- public void handle(String greeting) {
- String text = "[" + LocalDateTime.now() + "]:" + greeting;
- this.template.convertAndSend("/topic/greeting", text);
- }
-
-}
--- /dev/null
+package de.spring.webservices.rest.controller;
+
+import java.time.LocalDateTime;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.messaging.simp.SimpMessagingTemplate;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RestController
+public class RestGreetingController {
+
+ private SimpMessagingTemplate template;
+
+ @Autowired
+ public RestGreetingController(SimpMessagingTemplate template) {
+ this.template = template;
+ }
+
+ // Sending data to /topic/greeting from REST service.
+ // POST http://localhost:8080/spring-stomp-server/greetings
+
+ @RequestMapping(path="/greetings", method=RequestMethod.POST)
+ public void handle(@RequestBody String greeting) {
+ String text = "[" + LocalDateTime.now() + "]:" + greeting;
+
+ // STOMP clients subscribed to /topic/greeting will receive the data sent by the convertAndSend method.
+ this.template.convertAndSend("/topic/greeting", text);
+ }
+
+}
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/mvc
+ http://www.springframework.org/schema/mvc/spring-mvc.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
<!--
I am declaring my beans without the automatic annotation. :/