use of jakarta.jms.TextMessage in project spring-boot by spring-projects.
the class ArtemisAutoConfigurationTests method embeddedWithPersistentMode.
@Test
void embeddedWithPersistentMode(@TempDir Path temp) throws IOException {
File dataDirectory = Files.createTempDirectory(temp, null).toFile();
final String messageId = UUID.randomUUID().toString();
// Start the server and post a message to some queue
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).withPropertyValues("spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataDirectory.getAbsolutePath()).run((context) -> context.getBean(JmsTemplate.class).send("TestQueue", (session) -> session.createTextMessage(messageId))).run((context) -> {
// Start the server again and check if our message is still here
JmsTemplate jmsTemplate2 = context.getBean(JmsTemplate.class);
jmsTemplate2.setReceiveTimeout(1000L);
Message message = jmsTemplate2.receive("TestQueue");
assertThat(message).isNotNull();
assertThat(((TextMessage) message).getText()).isEqualTo(messageId);
});
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertAndSendDefaultDestinationName.
@Test
public void convertAndSendDefaultDestinationName() throws JMSException {
this.messagingTemplate.setDefaultDestinationName("myQueue");
this.messagingTemplate.convertAndSend("my Payload");
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
assertThat(textMessage.getText()).isEqualTo("my Payload");
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsTemplateTests method doTestSendAndReceive.
private void doTestSendAndReceive(boolean explicitDestination, boolean useDefaultDestination, long timeout) throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
String destinationName = "testDestination";
if (useDefaultDestination) {
if (explicitDestination) {
template.setDefaultDestination(this.queue);
} else {
template.setDefaultDestinationName(destinationName);
}
}
template.setReceiveTimeout(timeout);
Session localSession = getLocalSession();
TemporaryQueue replyDestination = mock(TemporaryQueue.class);
MessageProducer messageProducer = mock(MessageProducer.class);
given(localSession.createProducer(this.queue)).willReturn(messageProducer);
given(localSession.createTemporaryQueue()).willReturn(replyDestination);
MessageConsumer messageConsumer = mock(MessageConsumer.class);
given(localSession.createConsumer(replyDestination)).willReturn(messageConsumer);
TextMessage request = mock(TextMessage.class);
MessageCreator messageCreator = mock(MessageCreator.class);
given(messageCreator.createMessage(localSession)).willReturn(request);
TextMessage reply = mock(TextMessage.class);
if (timeout == JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT) {
given(messageConsumer.receiveNoWait()).willReturn(reply);
} else if (timeout == JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT) {
given(messageConsumer.receive()).willReturn(reply);
} else {
given(messageConsumer.receive(timeout)).willReturn(reply);
}
Message message = null;
if (useDefaultDestination) {
message = template.sendAndReceive(messageCreator);
} else if (explicitDestination) {
message = template.sendAndReceive(this.queue, messageCreator);
} else {
message = template.sendAndReceive(destinationName, messageCreator);
}
// replyTO set on the request
verify(request).setJMSReplyTo(replyDestination);
assertThat(message).as("Reply message not received").isSameAs(reply);
verify(this.connection).start();
verify(this.connection).close();
verify(localSession).close();
verify(messageConsumer).close();
verify(messageProducer).close();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsTemplateTests method doTestSendDestination.
/**
* Common method for testing a send method that uses the MessageCreator
* callback but with different QOS options.
* @param ignoreQOS test using default QOS options.
*/
private void doTestSendDestination(boolean explicitDestination, boolean useDefaultDestination, boolean ignoreQOS, boolean disableIdAndTimestamp) throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
String destinationName = "testDestination";
if (useDefaultDestination) {
if (explicitDestination) {
template.setDefaultDestination(this.queue);
} else {
template.setDefaultDestinationName(destinationName);
}
}
if (disableIdAndTimestamp) {
template.setMessageIdEnabled(false);
template.setMessageTimestampEnabled(false);
}
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
given(this.session.createTextMessage("just testing")).willReturn(textMessage);
if (!ignoreQOS) {
template.setQosSettings(this.qosSettings);
}
if (useDefaultDestination) {
template.send(session -> session.createTextMessage("just testing"));
} else {
if (explicitDestination) {
template.send(this.queue, (MessageCreator) session -> session.createTextMessage("just testing"));
} else {
template.send(destinationName, (MessageCreator) session -> session.createTextMessage("just testing"));
}
}
if (useTransactedTemplate()) {
verify(this.session).commit();
}
if (disableIdAndTimestamp) {
verify(messageProducer).setDisableMessageID(true);
verify(messageProducer).setDisableMessageTimestamp(true);
}
if (ignoreQOS) {
verify(messageProducer).send(textMessage);
} else {
verify(messageProducer).send(textMessage, this.qosSettings.getDeliveryMode(), this.qosSettings.getPriority(), this.qosSettings.getTimeToLive());
}
verify(messageProducer).close();
verify(this.session).close();
verify(this.connection).close();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method createTextMessage.
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
Session mock = mock(Session.class);
given(mock.createTextMessage(any())).willAnswer((Answer<TextMessage>) invocation -> new StubTextMessage((String) invocation.getArguments()[0]));
jakarta.jms.Message message = creator.createMessage(mock);
verify(mock).createTextMessage(any());
return (TextMessage) message;
}
Aggregations