本文整理汇总了Java中org.springframework.messaging.MessageHandler.handleMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MessageHandler.handleMessage方法的具体用法?Java MessageHandler.handleMessage怎么用?Java MessageHandler.handleMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.messaging.MessageHandler
的用法示例。
在下文中一共展示了MessageHandler.handleMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted
import org.springframework.messaging.MessageHandler; //导入方法依赖的package包/类
@Test
public void receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted() {
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandlerWithCustomParameter.class);
applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
applicationContext.refresh();
MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
DummyKeyValueHolder messagePayload = new DummyKeyValueHolder("myKey", "A value");
MappingJackson2MessageConverter jsonMapper = new MappingJackson2MessageConverter();
Message<?> message = jsonMapper.toMessage(messagePayload, new MessageHeaders(Collections.singletonMap(QueueMessageHandler.LOGICAL_RESOURCE_ID, "testQueue")));
messageHandler.handleMessage(message);
IncomingMessageHandlerWithCustomParameter messageListener = applicationContext.getBean(IncomingMessageHandlerWithCustomParameter.class);
assertNotNull(messageListener.getLastReceivedMessage());
assertEquals("myKey", messageListener.getLastReceivedMessage().getKey());
assertEquals("A value", messageListener.getLastReceivedMessage().getValue());
}
示例2: receiveAndReplayMessage_withExceptionThrownInSendTo_shouldCallExceptionHandler
import org.springframework.messaging.MessageHandler; //导入方法依赖的package包/类
@Test
public void receiveAndReplayMessage_withExceptionThrownInSendTo_shouldCallExceptionHandler() {
// Arrange
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class);
applicationContext.registerBeanDefinition("queueMessageHandler", getQueueMessageHandlerBeanDefinition());
applicationContext.refresh();
MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
doThrow(new RuntimeException()).when(this.messageTemplate).convertAndSend(anyString(), Optional.ofNullable(any()));
IncomingMessageHandler messageListener = applicationContext.getBean(IncomingMessageHandler.class);
messageListener.setExceptionHandlerCalled(false);
// Act
try {
messageHandler.handleMessage(MessageBuilder.withPayload("testContent").setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receiveAndReply").build());
} catch (MessagingException e) {
// ignore
}
// Assert
assertTrue(messageListener.isExceptionHandlerCalled());
}
示例3: handleInboundMessage
import org.springframework.messaging.MessageHandler; //导入方法依赖的package包/类
@Override
protected void handleInboundMessage(Message<?> message) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (StompCommand.MESSAGE.equals(accessor.getCommand())) {
String destination = accessor.getDestination();
if (destination == null) {
if (logger.isDebugEnabled()) {
logger.debug("Got message on \"system\" connection, with no destination: " +
accessor.getDetailedLogMessage(message.getPayload()));
}
return;
}
if (!getSystemSubscriptions().containsKey(destination)) {
if (logger.isDebugEnabled()) {
logger.debug("Got message on \"system\" connection with no handler: " +
accessor.getDetailedLogMessage(message.getPayload()));
}
return;
}
try {
MessageHandler handler = getSystemSubscriptions().get(destination);
handler.handleMessage(message);
}
catch (Throwable ex) {
if (logger.isDebugEnabled()) {
logger.debug("Error while handling message on \"system\" connection.", ex);
}
}
}
}
示例4: doHandleMessage
import org.springframework.messaging.MessageHandler; //导入方法依赖的package包/类
private void doHandleMessage(MessageHandler handler, Message<?> message) {
try {
handler.handleMessage(message);
}
catch (Throwable t) { // NOSONAR
throw new MessageHandlingException(message, t);
}
}
示例5: receiveMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessage
import org.springframework.messaging.MessageHandler; //导入方法依赖的package包/类
@Test
public void receiveMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessage() {
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class);
applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
applicationContext.refresh();
MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
messageHandler.handleMessage(MessageBuilder.withPayload("testContent").setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive").build());
IncomingMessageHandler messageListener = applicationContext.getBean(IncomingMessageHandler.class);
assertEquals("testContent", messageListener.getLastReceivedMessage());
}
示例6: StaticApplicationContext
import org.springframework.messaging.MessageHandler; //导入方法依赖的package包/类
@Test
public void receiveAndReplyMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessageAndReplySentBackToSendToDestination() {
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class);
applicationContext.registerBeanDefinition("queueMessageHandler", getQueueMessageHandlerBeanDefinition());
applicationContext.refresh();
MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
messageHandler.handleMessage(MessageBuilder.withPayload("testContent").setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receiveAndReply").build());
IncomingMessageHandler messageListener = applicationContext.getBean(IncomingMessageHandler.class);
assertEquals("testContent", messageListener.getLastReceivedMessage());
verify(this.messageTemplate).convertAndSend(eq("sendTo"), eq("TESTCONTENT"));
}