Search in sources :

Example 26 with Destination

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

the class AbstractPollingMessageListenerContainer method createListenerConsumer.

/**
 * Create a MessageConsumer for the given JMS Session,
 * registering a MessageListener for the specified listener.
 * @param session the JMS Session to work on
 * @return the MessageConsumer
 * @throws jakarta.jms.JMSException if thrown by JMS methods
 * @see #receiveAndExecute
 */
protected MessageConsumer createListenerConsumer(Session session) throws JMSException {
    Destination destination = getDestination();
    if (destination == null) {
        String destinationName = getDestinationName();
        Assert.state(destinationName != null, "No destination set");
        destination = resolveDestinationName(session, destinationName);
    }
    return createConsumer(session, destination);
}
Also used : Destination(jakarta.jms.Destination)

Example 27 with Destination

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

the class SimpleMessageListenerContainer method createListenerConsumer.

/**
 * Create a MessageConsumer for the given JMS Session,
 * registering a MessageListener for the specified listener.
 * @param session the JMS Session to work on
 * @return the MessageConsumer
 * @throws JMSException if thrown by JMS methods
 * @see #executeListener
 */
protected MessageConsumer createListenerConsumer(final Session session) throws JMSException {
    Destination destination = getDestination();
    if (destination == null) {
        String destinationName = getDestinationName();
        Assert.state(destinationName != null, "No destination set");
        destination = resolveDestinationName(session, destinationName);
    }
    MessageConsumer consumer = createConsumer(session, destination);
    if (this.taskExecutor != null) {
        consumer.setMessageListener(message -> this.taskExecutor.execute(() -> processMessage(message, session)));
    } else {
        consumer.setMessageListener(message -> processMessage(message, session));
    }
    return consumer;
}
Also used : Destination(jakarta.jms.Destination) MessageConsumer(jakarta.jms.MessageConsumer)

Example 28 with Destination

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

the class JmsTemplate method execute.

@Override
@Nullable
public <T> T execute(final String destinationName, final ProducerCallback<T> action) throws JmsException {
    Assert.notNull(action, "Callback object must not be null");
    return execute(session -> {
        Destination destination = resolveDestinationName(session, destinationName);
        MessageProducer producer = createProducer(session, destination);
        try {
            return action.doInJms(session, producer);
        } finally {
            JmsUtils.closeMessageProducer(producer);
        }
    }, false);
}
Also used : Destination(jakarta.jms.Destination) MessageProducer(jakarta.jms.MessageProducer) Nullable(org.springframework.lang.Nullable)

Example 29 with Destination

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

the class JmsTemplate method send.

@Override
public void send(final String destinationName, final MessageCreator messageCreator) throws JmsException {
    execute(session -> {
        Destination destination = resolveDestinationName(session, destinationName);
        doSend(session, destination, messageCreator);
        return null;
    }, false);
}
Also used : Destination(jakarta.jms.Destination)

Example 30 with Destination

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

the class MessagingMessageListenerAdapterTests method buildMessageWithStandardMessage.

@Test
public void buildMessageWithStandardMessage() throws JMSException {
    Destination replyTo = new Destination() {
    };
    Message<String> result = MessageBuilder.withPayload("Response").setHeader("foo", "bar").setHeader(JmsHeaders.TYPE, "msg_type").setHeader(JmsHeaders.REPLY_TO, replyTo).build();
    Session session = mock(Session.class);
    given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
    MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
    jakarta.jms.Message replyMessage = listener.buildMessage(session, result);
    verify(session).createTextMessage("Response");
    assertThat(replyMessage).as("reply should never be null").isNotNull();
    assertThat(((TextMessage) replyMessage).getText()).isEqualTo("Response");
    assertThat(replyMessage.getStringProperty("foo")).as("custom header not copied").isEqualTo("bar");
    assertThat(replyMessage.getJMSType()).as("type header not copied").isEqualTo("msg_type");
    assertThat(replyMessage.getJMSReplyTo()).as("replyTo header not copied").isEqualTo(replyTo);
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Aggregations

Destination (jakarta.jms.Destination)41 Test (org.junit.jupiter.api.Test)31 StubTextMessage (org.springframework.jms.StubTextMessage)11 Session (jakarta.jms.Session)8 TextMessage (jakarta.jms.TextMessage)5 JMSException (jakarta.jms.JMSException)3 HashMap (java.util.HashMap)3 DestinationResolutionException (org.springframework.jms.support.destination.DestinationResolutionException)3 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)3 MessageProducer (jakarta.jms.MessageProducer)2 QueueSender (jakarta.jms.QueueSender)2 NamingException (javax.naming.NamingException)2 StubQueue (org.springframework.jms.StubQueue)2 Connection (jakarta.jms.Connection)1 ConnectionFactory (jakarta.jms.ConnectionFactory)1 Message (jakarta.jms.Message)1 MessageConsumer (jakarta.jms.MessageConsumer)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1