本文整理汇总了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);
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}