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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations