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);
+ }
+
}
in this way annotations like @Service, @Endpoint, etc, etc)
-->
<context:component-scan base-package="de.spring.stomp"/>
-
- <!-- SockJS -->
- <websocket:handlers allowed-origins="*">
- <websocket:mapping path="/myHandler" handler="sockJsHandler"/>
- <!-- Using SockJS protocol -->
- <websocket:sockjs/>
- <websocket:handshake-interceptors>
- <bean class="org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor"/>
- </websocket:handshake-interceptors>
- </websocket:handlers>
- <bean id="sockJsHandler" class="org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler"/>
-
+
<bean class="org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean">
<property name="maxTextMessageBufferSize" value="8192"/>
<property name="maxBinaryMessageBufferSize" value="8192"/>
</bean>
-
<!-- STOMP -->
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/portfolio">
<websocket:sockjs/>
</websocket:stomp-endpoint>
- <!-- Full-featured broker, see: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-handle-broker-relay -->
+ <!--
+ Full-featured broker, see: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-handle-broker-relay
<websocket:stomp-broker-relay prefix="/topic,/queue" />
+ -->
+ <websocket:simple-broker prefix="/topic, /queue"/>
</websocket:message-broker>
</beans>