Search in sources :

Example 6 with MessageMapping

use of org.springframework.messaging.handler.annotation.MessageMapping 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 7 with MessageMapping

use of org.springframework.messaging.handler.annotation.MessageMapping 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 8 with MessageMapping

use of org.springframework.messaging.handler.annotation.MessageMapping 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)

Example 9 with MessageMapping

use of org.springframework.messaging.handler.annotation.MessageMapping in project cas by apereo.

the class QRAuthenticationChannelController method verify.

/**
 * Verify.
 *
 * @param message the message
 * @return the boolean
 */
@MessageMapping("/accept")
public boolean verify(final Message<String> message) {
    val payload = message.getPayload();
    LOGGER.trace("Received payload [{}]", payload);
    val nativeHeaders = Objects.requireNonNull(message.getHeaders().get("nativeHeaders", LinkedMultiValueMap.class));
    if (!nativeHeaders.containsKey(QRAuthenticationConstants.QR_AUTHENTICATION_CHANNEL_ID)) {
        LOGGER.warn("Unable to locate [{}] in the message header", QRAuthenticationConstants.QR_AUTHENTICATION_CHANNEL_ID);
        return false;
    }
    if (!nativeHeaders.containsKey(QRAuthenticationConstants.QR_AUTHENTICATION_DEVICE_ID)) {
        LOGGER.warn("Unable to locate [{}] in the message header", QRAuthenticationConstants.QR_AUTHENTICATION_DEVICE_ID);
        return false;
    }
    val channelId = Objects.requireNonNull(nativeHeaders.get(QRAuthenticationConstants.QR_AUTHENTICATION_CHANNEL_ID)).get(0);
    val endpoint = String.format("%s/%s/verify", QRAuthenticationConstants.QR_SIMPLE_BROKER_DESTINATION_PREFIX, channelId);
    try {
        LOGGER.debug("Current channel id is [{}]", channelId);
        val resultMap = MAPPER.readValue(payload, new TypeReference<Map<String, String>>() {
        });
        val token = resultMap.get(TokenConstants.PARAMETER_NAME_TOKEN);
        val deviceId = Objects.requireNonNull(nativeHeaders.get(QRAuthenticationConstants.QR_AUTHENTICATION_DEVICE_ID)).get(0).toString();
        val validationRequest = QRAuthenticationTokenValidationRequest.builder().deviceId(deviceId).token(token).registeredService(Optional.empty()).build();
        tokenValidatorService.validate(validationRequest);
        LOGGER.debug("Current channel id is [{}]", channelId);
        val body = Map.of("success", Boolean.TRUE.toString(), TokenConstants.PARAMETER_NAME_TOKEN, token, "deviceId", deviceId);
        convertAndSend(endpoint, body);
        return true;
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
        convertAndSend(endpoint, Map.of("error", "cas.authn.qr.fail"));
    }
    return false;
}
Also used : lombok.val(lombok.val) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 10 with MessageMapping

use of org.springframework.messaging.handler.annotation.MessageMapping in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class MessageHandler method broadcasting.

@MessageMapping("/vote/{roomId}")
@SendTo("/from/vote/{roomId}")
public GameResult broadcasting(VoteMessage voteMessage, @DestinationVariable long roomId) throws Exception {
    log.debug("voteMessage arrived: /vote/{}, voteMessage: {}", roomId, voteMessage);
    Room gameRoom = lobby.getRoom(roomId);
    return gameRoom.returnVoteResult(voteMessage);
}
Also used : Room(com.mapia.domain.Room) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Aggregations

MessageMapping (org.springframework.messaging.handler.annotation.MessageMapping)11 SendTo (org.springframework.messaging.handler.annotation.SendTo)6 Room (com.mapia.domain.Room)4 ResponseMessage (com.hry.spring.mvc.websocket.model.ResponseMessage)3 Nullable (org.springframework.lang.Nullable)3 CompositeMessageCondition (org.springframework.messaging.handler.CompositeMessageCondition)2 DestinationPatternsMessageCondition (org.springframework.messaging.handler.DestinationPatternsMessageCondition)2 Map (java.util.Map)1 lombok.val (lombok.val)1 ConnectMapping (org.springframework.messaging.rsocket.annotation.ConnectMapping)1 SimpMessageMappingInfo (org.springframework.messaging.simp.SimpMessageMappingInfo)1 SendToUser (org.springframework.messaging.simp.annotation.SendToUser)1 SubscribeMapping (org.springframework.messaging.simp.annotation.SubscribeMapping)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1