From 205daa02a83be5e202dc2f92c9f09a87a2f279da Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 30 Mar 2016 02:12:06 +0200 Subject: [PATCH] Sprint STOMP: simple broker (in memory broker) --- .../rest/controller/GreetingController.java | 26 +++++++++++++++++----- .../spring-configuration/spring-configuration.xml | 19 +++++----------- 2 files changed, 26 insertions(+), 19 deletions(-) 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) --> - - - - - - - - - - - - + - - + + -- 2.1.4