From: Gustavo Martin Morcuende Date: Wed, 30 Mar 2016 00:12:06 +0000 (+0200) Subject: Sprint STOMP: simple broker (in memory broker) X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=205daa02a83be5e202dc2f92c9f09a87a2f279da;p=JavaForFun Sprint STOMP: simple broker (in memory broker) --- diff --git a/SpringJava/STOMP/spring-stomp-server/src/main/java/de/spring/webservices/rest/controller/GreetingController.java b/SpringJava/STOMP/spring-stomp-server/src/main/java/de/spring/webservices/rest/controller/GreetingController.java index 930aaf8..58c6da4 100644 --- a/SpringJava/STOMP/spring-stomp-server/src/main/java/de/spring/webservices/rest/controller/GreetingController.java +++ b/SpringJava/STOMP/spring-stomp-server/src/main/java/de/spring/webservices/rest/controller/GreetingController.java @@ -2,16 +2,32 @@ package de.spring.webservices.rest.controller; import java.time.LocalDateTime; -import org.springframework.messaging.handler.annotation.MessageMapping; +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 { - @MessageMapping("/greeting") - public String handle(String greeting) { - return "[" + LocalDateTime.now() + ": " + greeting; + 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); + } + } diff --git a/SpringJava/STOMP/spring-stomp-server/src/main/resources/spring-configuration/spring-configuration.xml b/SpringJava/STOMP/spring-stomp-server/src/main/resources/spring-configuration/spring-configuration.xml index 892d490..5917c07 100644 --- a/SpringJava/STOMP/spring-stomp-server/src/main/resources/spring-configuration/spring-configuration.xml +++ b/SpringJava/STOMP/spring-stomp-server/src/main/resources/spring-configuration/spring-configuration.xml @@ -16,32 +16,23 @@ in this way annotations like @Service, @Endpoint, etc, etc) --> - - - - - - - - - - - - + - - + +