Search in sources :

Example 56 with TextMessage

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();
    }
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage)

Example 57 with TextMessage

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);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 58 with TextMessage

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);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 59 with TextMessage

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);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsTemplate(org.springframework.jms.core.JmsTemplate) JMSException(javax.jms.JMSException) File(java.io.File) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 60 with TextMessage

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

Aggregations

TextMessage (javax.jms.TextMessage)231 Test (org.junit.Test)92 Session (javax.jms.Session)75 MessageProducer (javax.jms.MessageProducer)71 Message (javax.jms.Message)70 JMSException (javax.jms.JMSException)64 Connection (javax.jms.Connection)44 Destination (javax.jms.Destination)44 MessageConsumer (javax.jms.MessageConsumer)44 ObjectMessage (javax.jms.ObjectMessage)25 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)20 StubTextMessage (org.springframework.jms.StubTextMessage)18 ConnectionFactory (javax.jms.ConnectionFactory)13 QueueConnection (javax.jms.QueueConnection)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 MapMessage (javax.jms.MapMessage)11 Topic (javax.jms.Topic)11 JMSContext (javax.jms.JMSContext)9