當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。