当前位置: 首页>>代码示例>>Java>>正文


Java MessageHandler.handleMessage方法代码示例

本文整理汇总了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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageHandlerTest.java

示例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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:24,代码来源:QueueMessageHandlerTest.java

示例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);
			}
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:StompBrokerRelayMessageHandler.java

示例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);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:9,代码来源:DefaultPollableMessageSource.java

示例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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:14,代码来源:QueueMessageHandlerTest.java

示例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"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:15,代码来源:QueueMessageHandlerTest.java


注:本文中的org.springframework.messaging.MessageHandler.handleMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。