use of javax.jms.TextMessage in project wildfly by wildfly.
the class TopicMDB method onMessage.
public void onMessage(final Message m) {
try {
TextMessage message = (TextMessage) m;
Destination replyTo = m.getJMSReplyTo();
context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, message.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.jms.TextMessage in project wildfly by wildfly.
the class ExportImportJournalTestCase method sendMessage.
protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
TextMessage message = context.createTextMessage(text);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
context.createProducer().send(destination, message);
}
}
use of javax.jms.TextMessage in project beam by apache.
the class JmsIOTest method testReadMessages.
@Test
public void testReadMessages() throws Exception {
// produce message
Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(session.createQueue(QUEUE));
TextMessage message = session.createTextMessage("This Is A Test");
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.close();
session.close();
connection.close();
// read from the queue
PCollection<JmsRecord> output = pipeline.apply(JmsIO.read().withConnectionFactory(connectionFactory).withQueue(QUEUE).withUsername(USERNAME).withPassword(PASSWORD).withMaxNumRecords(5));
PAssert.thatSingleton(output.apply("Count", Count.<JmsRecord>globally())).isEqualTo(new Long(5));
pipeline.run();
connection = connectionFactory.createConnection(USERNAME, PASSWORD);
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
Message msg = consumer.receiveNoWait();
assertNull(msg);
}
use of javax.jms.TextMessage in project spring-boot by spring-projects.
the class ArtemisAutoConfigurationTests method embeddedWithPersistentMode.
@Test
public void embeddedWithPersistentMode() throws IOException, JMSException {
File dataFolder = this.folder.newFolder();
// Start the server and post a message to some queue
load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
final String msgId = UUID.randomUUID().toString();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
jmsTemplate.send("TestQueue", new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(msgId);
}
});
// Shutdown the broker
this.context.close();
// Start the server again and check if our message is still here
load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
JmsTemplate jmsTemplate2 = this.context.getBean(JmsTemplate.class);
jmsTemplate2.setReceiveTimeout(1000L);
Message message = jmsTemplate2.receive("TestQueue");
assertThat(message).isNotNull();
assertThat(((TextMessage) message).getText()).isEqualTo(msgId);
}
use of javax.jms.TextMessage 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();
}
Aggregations