Search in sources :

Example 41 with Message

use of javax.jms.Message in project jmeter by apache.

the class Receiver method run.

@Override
public void run() {
    active = true;
    Message reply;
    while (active) {
        reply = null;
        try {
            reply = consumer.receive(5000);
            if (reply != null) {
                String messageKey;
                final MessageAdmin admin = MessageAdmin.getAdmin();
                if (useResMsgIdAsCorrelId) {
                    messageKey = reply.getJMSMessageID();
                    synchronized (admin) {
                        // synchronize with FixedQueueExecutor
                        admin.putReply(messageKey, reply);
                    }
                } else {
                    messageKey = reply.getJMSCorrelationID();
                    if (messageKey == null) {
                        // JMSMessageID cannot be null
                        log.warn("Received message with correlation id null. Discarding message ...");
                    } else {
                        admin.putReply(messageKey, reply);
                    }
                }
            }
        } catch (JMSException e1) {
            log.error("Error handling receive", e1);
        }
    }
    Utils.close(consumer, log);
    Utils.close(session, log);
    Utils.close(conn, log);
}
Also used : Message(javax.jms.Message) JMSException(javax.jms.JMSException)

Example 42 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class MessageDrivenTimeoutTestCase method sendMessage.

static Queue sendMessage(String text, String queueJndi, InitialContext initCtx) throws Exception {
    QueueConnection connection = getConnection(initCtx);
    connection.start();
    Queue replyDestination = null;
    try {
        final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        final Message message = session.createTextMessage(text);
        replyDestination = (Queue) initCtx.lookup(TransactionTimeoutQueueSetupTask.REPLY_QUEUE_JNDI_NAME);
        message.setJMSReplyTo(replyDestination);
        final Destination destination = (Destination) initCtx.lookup(queueJndi);
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
        producer.close();
    } finally {
        connection.close();
    }
    return replyDestination;
}
Also used : Destination(javax.jms.Destination) QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Example 43 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class TransactionScopedJMSContextTestCase method sendAndReceiveWithContext.

@Test
public void sendAndReceiveWithContext() throws JMSException, InterruptedException {
    int numThreads = 5;
    int numMessages = 10;
    launcher.start(numThreads, numMessages);
    int receivedMessages = 0;
    try (JMSContext context = factory.createContext()) {
        JMSConsumer consumer = context.createConsumer(queue);
        Message m;
        do {
            m = consumer.receive(1000);
            if (m != null) {
                receivedMessages++;
            }
        } while (m != null);
    }
    assertEquals(numThreads * numMessages, receivedMessages);
}
Also used : JMSConsumer(javax.jms.JMSConsumer) Message(javax.jms.Message) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 44 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class InjectedJMSContextTestCase method tearDown.

@After
public void tearDown() throws JMSException {
    // drain the queue to remove any pending messages from it
    try (JMSContext context = factory.createContext()) {
        JMSConsumer consumer = context.createConsumer(queue);
        Message m;
        do {
            m = consumer.receiveNoWait();
        } while (m != null);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) Message(javax.jms.Message) JMSContext(javax.jms.JMSContext) After(org.junit.After)

Example 45 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class ContainerManagedTransactionNotSupportedTestCase method doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException.

private void doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException(Destination destination) throws Exception {
    try (JMSContext context = cf.createContext()) {
        TemporaryQueue replyTo = context.createTemporaryQueue();
        String text = UUID.randomUUID().toString();
        TextMessage message = context.createTextMessage(text);
        message.setJMSReplyTo(replyTo);
        context.createProducer().send(destination, message);
        Message reply = context.createConsumer(replyTo).receive(adjust(2000));
        assertNotNull(reply);
        assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
        assertTrue("messageDrivenContext.setRollbackOnly() did not throw the expected IllegalStateException", reply.getBooleanProperty(EXCEPTION_PROP_NAME));
    }
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Aggregations

Message (javax.jms.Message)230 TextMessage (javax.jms.TextMessage)103 Test (org.junit.Test)91 Session (javax.jms.Session)86 JMSException (javax.jms.JMSException)77 MessageProducer (javax.jms.MessageProducer)64 ObjectMessage (javax.jms.ObjectMessage)52 MessageConsumer (javax.jms.MessageConsumer)50 Connection (javax.jms.Connection)45 BytesMessage (javax.jms.BytesMessage)37 Destination (javax.jms.Destination)30 MapMessage (javax.jms.MapMessage)26 Queue (javax.jms.Queue)20 ConnectionFactory (javax.jms.ConnectionFactory)18 QueueSession (javax.jms.QueueSession)17 MessageCreator (org.springframework.jms.core.MessageCreator)15 MessageListener (javax.jms.MessageListener)12 Map (java.util.Map)10 StreamMessage (javax.jms.StreamMessage)10 TemporaryQueue (javax.jms.TemporaryQueue)9