Search in sources :

Example 1 with ResponseMessage

use of com.hry.spring.mvc.websocket.model.ResponseMessage in project spring_boot by hryou0922.

the class BroadcastRabbitMQCtl method broadcast.

// @MessageMapping 指定要接收消息的地址,类似@RequestMapping。除了注解到方法上,也可以注解到类上
@MessageMapping("/receive-rabbitmq")
// @SendTo("/queue/rabbitmq")
@SendTo("/amq/queue/rabbitmq2")
public // @SendTo("/topic/get-response")
ResponseMessage broadcast(RequestMessage requestMessage) {
    logger.info("receive message = {}", JSONObject.toJSONString(requestMessage));
    ResponseMessage responseMessage = new ResponseMessage();
    responseMessage.setResponseMessage("BroadcastRabbitMQCtl receive [" + count.incrementAndGet() + "] records");
    return responseMessage;
}
Also used : ResponseMessage(com.hry.spring.mvc.websocket.model.ResponseMessage) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 2 with ResponseMessage

use of com.hry.spring.mvc.websocket.model.ResponseMessage in project spring_boot by hryou0922.

the class BroadcastSingleCtl method broadcast.

// @MessageMapping 指定要接收消息的地址,类似@RequestMapping。除了注解到方法上,也可以注解到类上
@MessageMapping("/receive-single")
/**
 * 基于WebSocket的STOMP有个属性@SendTo。
 * @SendTo默认 消息将被发送到与传入消息相同的目的地,但是目的地前面附加前缀(默认情况下为“/topic”})。
 * 也可以使用endToUser}批注,可以将将消息定向到特定用户
 * 消息的返回值是通过{@link org.springframework.messaging.converter.MessageConverter}进行转换。
 *
 * 这里使用 @SendToUser,而不是使用 @SendTo
 */
@SendToUser("/topic/getResponse")
public ResponseMessage broadcast(RequestMessage requestMessage) {
    logger.info("receive message = {}", JSONObject.toJSONString(requestMessage));
    ResponseMessage responseMessage = new ResponseMessage();
    responseMessage.setResponseMessage("BroadcastCtlSingle receive [" + count.incrementAndGet() + "] records");
    return responseMessage;
}
Also used : ResponseMessage(com.hry.spring.mvc.websocket.model.ResponseMessage) SendToUser(org.springframework.messaging.simp.annotation.SendToUser) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 3 with ResponseMessage

use of com.hry.spring.mvc.websocket.model.ResponseMessage in project spring_boot by hryou0922.

the class BroadcastCtl method broadcast.

/**
 * @MessageMapping 指定要接收消息的地址,类似@RequestMapping。除了注解到方法上,也可以注解到类上
 * @SendTo默认 消息将被发送到与传入消息相同的目的地
 * 消息的返回值是通过{@link org.springframework.messaging.converter.MessageConverter}进行转换
 * @param requestMessage
 * @return
 */
@MessageMapping("/receive")
@SendTo("/topic/getResponse")
public ResponseMessage broadcast(RequestMessage requestMessage) {
    logger.info("receive message = {}", JSONObject.toJSONString(requestMessage));
    ResponseMessage responseMessage = new ResponseMessage();
    responseMessage.setResponseMessage("BroadcastCtl receive [" + count.incrementAndGet() + "] records");
    return responseMessage;
}
Also used : ResponseMessage(com.hry.spring.mvc.websocket.model.ResponseMessage) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Aggregations

ResponseMessage (com.hry.spring.mvc.websocket.model.ResponseMessage)3 MessageMapping (org.springframework.messaging.handler.annotation.MessageMapping)3 SendTo (org.springframework.messaging.handler.annotation.SendTo)2 SendToUser (org.springframework.messaging.simp.annotation.SendToUser)1