Search in sources :

Example 16 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class AbstractAdaptableMessageListener method handleResult.

/**
	 * Handle the given result object returned from the listener method,
	 * sending a response message back.
	 * @param result the result object to handle (never {@code null})
	 * @param request the original request message
	 * @param session the JMS Session to operate on (may be {@code null})
	 * @throws ReplyFailureException if the response message could not be sent
	 * @see #buildMessage
	 * @see #postProcessResponse
	 * @see #getResponseDestination
	 * @see #sendResponse
	 */
protected void handleResult(Object result, Message request, Session session) {
    if (session != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Listener method returned result [" + result + "] - generating response message for it");
        }
        try {
            Message response = buildMessage(session, result);
            postProcessResponse(request, response);
            Destination destination = getResponseDestination(request, response, session, result);
            sendResponse(session, destination, response);
        } catch (Exception ex) {
            throw new ReplyFailureException("Failed to send reply with payload [" + result + "]", ex);
        }
    } else {
        // No JMS Session available
        if (logger.isWarnEnabled()) {
            logger.warn("Listener method returned result [" + result + "]: not generating response message for it because of no JMS Session given");
        }
    }
}
Also used : Destination(javax.jms.Destination) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageConversionException(org.springframework.jms.support.converter.MessageConversionException)

Example 17 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method processAndReplyWithSendTo.

private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain) throws JMSException {
    String body = "echo text";
    String correlationId = "link-1234";
    Destination replyDestination = new Destination() {
    };
    DestinationResolver destinationResolver = mock(DestinationResolver.class);
    TextMessage reply = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)).willReturn(replyDestination);
    given(session.createTextMessage(body)).willReturn(reply);
    given(session.createProducer(replyDestination)).willReturn(queueSender);
    listener.setDestinationResolver(destinationResolver);
    StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
    inputMessage.setJMSCorrelationID(correlationId);
    listener.onMessage(inputMessage, session);
    verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
    verify(reply).setJMSCorrelationID(correlationId);
    verify(queueSender).send(reply);
    verify(queueSender).close();
}
Also used : Destination(javax.jms.Destination) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) QueueSender(javax.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 18 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JmsResponseTests method resolveDestinationForQueue.

@Test
public void resolveDestinationForQueue() throws JMSException {
    Session session = mock(Session.class);
    DestinationResolver destinationResolver = mock(DestinationResolver.class);
    Destination destination = mock(Destination.class);
    given(destinationResolver.resolveDestinationName(session, "myQueue", false)).willReturn(destination);
    JmsResponse<String> jmsResponse = JmsResponse.forQueue("foo", "myQueue");
    Destination actual = jmsResponse.resolveDestination(destinationResolver, session);
    assertSame(destination, actual);
}
Also used : Destination(javax.jms.Destination) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) Session(javax.jms.Session) Test(org.junit.Test)

Example 19 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertAndSendDefaultDestination.

@Test
public void convertAndSendDefaultDestination() throws JMSException {
    Destination destination = new Destination() {
    };
    messagingTemplate.setDefaultDestination(destination);
    messagingTemplate.convertAndSend("my Payload");
    verify(jmsTemplate).send(eq(destination), messageCreator.capture());
    TextMessage textMessage = createTextMessage(messageCreator.getValue());
    assertEquals("my Payload", textMessage.getText());
}
Also used : Destination(javax.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 20 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method sendAndReceive.

@Test
public void sendAndReceive() {
    Destination destination = new Destination() {
    };
    Message<String> request = createTextMessage();
    javax.jms.Message replyJmsMessage = createJmsTextMessage();
    given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
    Message<?> actual = messagingTemplate.sendAndReceive(destination, request);
    verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
    assertTextMessage(actual);
}
Also used : Destination(javax.jms.Destination) Test(org.junit.Test)

Aggregations

Destination (javax.jms.Destination)137 Test (org.junit.Test)41 TextMessage (javax.jms.TextMessage)38 JMSException (javax.jms.JMSException)33 Message (javax.jms.Message)27 Session (javax.jms.Session)27 MessageProducer (javax.jms.MessageProducer)22 Connection (javax.jms.Connection)15 ConnectionFactory (javax.jms.ConnectionFactory)15 JMSContext (javax.jms.JMSContext)15 CountDownLatch (java.util.concurrent.CountDownLatch)13 MessageConsumer (javax.jms.MessageConsumer)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 ObjectMessage (javax.jms.ObjectMessage)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 MapMessage (javax.jms.MapMessage)7 Queue (javax.jms.Queue)7 Map (java.util.Map)6 HashMap (java.util.HashMap)5 JMSConsumer (javax.jms.JMSConsumer)5