當前位置: 首頁>>代碼示例>>Java>>正文


Java Payload類代碼示例

本文整理匯總了Java中org.springframework.messaging.handler.annotation.Payload的典型用法代碼示例。如果您正苦於以下問題:Java Payload類的具體用法?Java Payload怎麽用?Java Payload使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Payload類屬於org.springframework.messaging.handler.annotation包,在下文中一共展示了Payload類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: objectMessage

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@RabbitListener(queues = "seqQueue")
public void objectMessage(@Payload UserDTO msg, @Header("my-header") String my_header, Message message) {
    System.out.println("message user:" + msg.getName());
    String myHeader =(String) message.getMessageProperties().getHeaders().get("my-header");

    logger.info("Here is my header:" + myHeader );
    logger.info("my header from annotation:" +my_header);
    try{
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(msg);
        logger.info("here is the message recived: " + json);
    }
    catch (JsonProcessingException exc){
        logger.info("exceptions ",exc);
    }

}
 
開發者ID:capesonlee,項目名稱:tangtang-spring-cloud,代碼行數:18,代碼來源:AmqpReciver.java

示例2: handleMessages

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
/**
 * Receive and send messages via websockets.
 * <p>
 * Note: public and private chats work the same way. The permission handling is
 * done at the SUBSCRIBE event as part of the AuthenticationInterceptor.
 *
 * @param roomId   String
 * @param message  Message
 * @param traveler Traveler
 * @return Message
 * @throws Exception
 */
@MessageMapping("/chat/{roomId}")
public Message handleMessages(@DestinationVariable("roomId") String roomId, @Payload Message message, Traveler traveler) throws Exception {
    System.out.println("Message received for room: " + roomId);
    System.out.println("User: " + traveler.toString());

    // store message in database
    message.setAuthor(traveler);
    message.setChatRoomId(Integer.parseInt(roomId));
    int id = MessageRepository.getInstance().save(message);
    message.setId(id);

    return message;
}
 
開發者ID:trvlrch,項目名稱:trvlr-backend,代碼行數:26,代碼來源:ChatController.java

示例3: validateStreamListenerMessageHandler

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
protected static void validateStreamListenerMessageHandler(Method method) {
    int methodArgumentsLength = method.getParameterTypes().length;
    if (methodArgumentsLength > 1) {
        int numAnnotatedMethodParameters = 0;
        int numPayloadAnnotations = 0;
        for (int parameterIndex = 0; parameterIndex < methodArgumentsLength; parameterIndex++) {
            MethodParameter methodParameter = MethodParameter.forExecutable(method, parameterIndex);
            if (methodParameter.hasParameterAnnotations()) {
                numAnnotatedMethodParameters++;
            }
            if (methodParameter.hasParameterAnnotation(Payload.class)) {
                numPayloadAnnotations++;
            }
        }
        if (numPayloadAnnotations > 0) {
            Assert.isTrue(methodArgumentsLength == numAnnotatedMethodParameters && numPayloadAnnotations <= 1,
                    StreamListenerErrorMessages.AMBIGUOUS_MESSAGE_HANDLER_METHOD_ARGUMENTS);
        }
    }
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream,代碼行數:21,代碼來源:StreamListenerMethodUtils.java

示例4: executeBulbActuation

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
/**
    * Client must call <code>/core/bulbs/actuation</code> due to app destination 
    * prefix is set to <code>core</code> - see WebSocketConfig for more details
    * 
    * @param cmd JSON encoded {@link DtoBulbActuatorCmd} expected here
    * @param principal 
    */
   @ApiOperation(value = "Control a single, specific bulb.", httpMethod = "POST")
   @RequestMapping (method= RequestMethod.POST, value = "/bulbs/actuation")
   @MessageMapping({"/bulbs/actuation"})
public void executeBulbActuation(
           @Valid @Payload @RequestBody @ApiParam DtoBulbActuatorCmd cmd,
           Principal principal) {

       String userApiKey =  ((BulbsContextUser)((Authentication)principal).getPrincipal()).getApiKey();

       BulbActuatorCommand bCmd =
               new ConverterBulbActuatorCmd().reverseConvert(cmd);
       bCmd.setUserApiKey(userApiKey);

       try {
           actuatorService.executeDeferred(bCmd);
       } catch (BulbBridgeHwException ex) {
           log.error(ex.getMessage(), ex);
       }
}
 
開發者ID:datenstrudel,項目名稱:bulbs-core,代碼行數:27,代碼來源:WebSocketBulbsCoreCtrl.java

示例5: executeGroupActuation

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@ApiOperation(value = "Control a group of bulbs.", httpMethod = "POST")
    @RequestMapping (method= RequestMethod.POST, value = "/groups/actuation")
    @MessageMapping({"/groups/actuation"})
    public void executeGroupActuation(
            @Valid @Payload @RequestBody DtoGroupActuatorCmd cmd,
            Principal principal) {

        String userApiKey =  ((BulbsContextUser)((Authentication)principal).getPrincipal()).getApiKey();
//        DtoGroupActuatorCmd cmd = gson.fromJson(
//                new String( (byte[]) body.getPayload()),
//                DtoGroupActuatorCmd.class);
        GroupActuatorCommand gCmd =
                new ConverterGroupActuatorCmd().reverseConvert(cmd);
        gCmd.setUserApiKey(userApiKey);

        try {
            actuatorService.executeDeferred(gCmd);
        } catch (BulbBridgeHwException ex) {
            log.error(ex.getMessage(), ex);
        }
    }
 
開發者ID:datenstrudel,項目名稱:bulbs-core,代碼行數:22,代碼來源:WebSocketBulbsCoreCtrl.java

示例6: executePresetActuation

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@ApiOperation(value = "Start a preset.", httpMethod = "POST")
   @RequestMapping (method= RequestMethod.POST, value = "/presets/actuation")
   @MessageMapping({"/presets/actuation"})
public void executePresetActuation(
           @Valid @Payload @RequestBody DtoPresetActuatorCmd cmd,
           Principal principal) {

       String userApiKey =  ((BulbsContextUser)((Authentication)principal).getPrincipal()).getApiKey();
       PresetActuatorCommand presetCmd =
               converterFactory.converterForDomain(PresetActuatorCommand.class).reverseConvert(cmd);
       presetCmd.setUserApiKey(userApiKey);

       try {
           actuatorService.execute(presetCmd);
       } catch (BulbBridgeHwException ex) {
           log.error(ex.getMessage(), ex);
       }
}
 
開發者ID:datenstrudel,項目名稱:bulbs-core,代碼行數:19,代碼來源:WebSocketBulbsCoreCtrl.java

示例7: executeCancelActuation

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@ApiOperation(value = "Stop transitions of bulbs.", httpMethod = "POST")
   @RequestMapping (method= RequestMethod.POST, value = "/bulbs/actuation/cancel")
   @MessageMapping({"/bulbs/actuation/cancel"})
public void executeCancelActuation(
           @Valid @Payload @RequestBody DtoActuationCancelCmd cmd,
           Principal principal) {

       String userApiKey =  ((BulbsContextUser)((Authentication)principal).getPrincipal()).getApiKey();
       ActuationCancelCommand cancelCmd =
               converterFactory.converterForDomain(ActuationCancelCommand.class).reverseConvert(cmd);
       cancelCmd.setUserApiKey(userApiKey);

       try {
           actuatorService.execute(cancelCmd);
       } catch (BulbBridgeHwException ex) {
           log.error(ex.getMessage(), ex);
       }
}
 
開發者ID:datenstrudel,項目名稱:bulbs-core,代碼行數:19,代碼來源:WebSocketBulbsCoreCtrl.java

示例8: process

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@RabbitHandler
public void process(@Payload CrispyBunOrder order) {
    StringBuffer SB = new StringBuffer();
    SB.append("New Order Received : \n");
    SB.append("OrderId : " + order.getOrderId());
    SB.append("\nItemId : " + order.getItemId());
    SB.append("\nUserName : " + order.getUserName());
    SB.append("\nDate : " + order.getOrderPlacedTime());
    System.out.println(SB.toString());
}
 
開發者ID:PacktPublishing,項目名稱:Practical-Microservices,代碼行數:11,代碼來源:EventConsumerApplication.java

示例9: sendActivity

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(SecurityUtils.getCurrentUserLogin());
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    Instant instant = Instant.ofEpochMilli(Calendar.getInstance().getTimeInMillis());
    activityDTO.setTime(dateTimeFormatter.format(ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault())));
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:13,代碼來源:ActivityService.java

示例10: receiveCustomerCreatedEvent

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@StreamListener(ApplicationProcessChannels.CUSTOMER_CREATED)
public void receiveCustomerCreatedEvent(@Payload CustomerCreatedEvent customerCreatedEvent) {
    Customer customer = restTemplate.getForObject(customerCreatedEvent.getCustomerUrl(), Customer.class);
    CreditApplicationStatus status = creditApplicationStatusRepository.findByApplicationNumber(customer.getApplicationNumber());
    status.setCustomerEntered(customer.getUpdated());
    creditApplicationStatusRepository.save(status);
}
 
開發者ID:mploed,項目名稱:event-driven-spring-boot,代碼行數:8,代碼來源:IncomingMessageListener.java

示例11: receiveScoringNegativeEvent

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@StreamListener(ApplicationProcessChannels.SCORING_NEGATIVE)
public void receiveScoringNegativeEvent(@Payload ScoringDoneEvent scoringDoneEvent) {
    CreditApplicationStatus status = creditApplicationStatusRepository.findByApplicationNumber(scoringDoneEvent.getApplicationNumber());
    status.setScoringResult("DECLINED");
    status.setScoringDoneDate(scoringDoneEvent.getCreationTime());
    creditApplicationStatusRepository.save(status);
}
 
開發者ID:mploed,項目名稱:event-driven-spring-boot,代碼行數:8,代碼來源:IncomingMessageListener.java

示例12: receiveScoringPositiveEvent

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@StreamListener(ApplicationProcessChannels.SCORING_POSITIVE)
public void receiveScoringPositiveEvent(@Payload ScoringDoneEvent scoringDoneEvent) {
    CreditApplicationStatus status = creditApplicationStatusRepository.findByApplicationNumber(scoringDoneEvent.getApplicationNumber());
    status.setScoringResult("ACCEPTABLE");
    status.setScoringDoneDate(scoringDoneEvent.getCreationTime());
    creditApplicationStatusRepository.save(status);
}
 
開發者ID:mploed,項目名稱:event-driven-spring-boot,代碼行數:8,代碼來源:IncomingMessageListener.java

示例13: receiveCustomerCreatedEvent

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@StreamListener(ScoringChannels.CUSTOMER_CREATED)
public void receiveCustomerCreatedEvent(@Payload CustomerCreatedEvent customerCreatedEvent) {
    LOGGER.info("Received Customer Created Event: " + customerCreatedEvent.toString());
    Customer customer = restTemplate.getForObject(customerCreatedEvent.getCustomerUrl(), Customer.class);

    LOGGER.info("Received Customer from Event: " + customer.toString());
    ScoringResult scoringResult = loadOrInitializeScoringResult(customer.getApplicationNumber());

    scoringResult.setLegitCity(customer.isCityLegit());
    scoringResult.setLastUpdate(new Date());
    ScoringResult savedScoringResult = scoringResultRepository.save(scoringResult);

    notifyInCaseOfFinalizedScoring(savedScoringResult);
}
 
開發者ID:mploed,項目名稱:event-driven-spring-boot,代碼行數:15,代碼來源:IncomingMessageListener.java

示例14: sendActivity

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    activityDTO.setTime(Instant.now());
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:11,代碼來源:ActivityService.java

示例15: todoCreated

import org.springframework.messaging.handler.annotation.Payload; //導入依賴的package包/類
@StreamListener(
        target = Sink.INPUT,
        condition = "headers['type']=='TodoCreatedEvent'"
)
public void todoCreated(@Payload TodoCreatedEvent event) throws Exception {
    LOG.info("Todo created");
    LOG.info("when = " + event.when());
    LOG.info("todo = " + event.getTodo().toString());

    String uuid = UUID.randomUUID().toString();
    Email email = new Email("Alexsandro", "test"+Instant.now().getEpochSecond()+"@gmail.com", EmailState.CREATED);
    EmailCreateCommand command = new EmailCreateCommand(uuid, email);
    commanderHandler.create(command);
}
 
開發者ID:apssouza22,項目名稱:java-microservice,代碼行數:15,代碼來源:EventInput.java


注:本文中的org.springframework.messaging.handler.annotation.Payload類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。