Search in sources :

Example 1 with QueueSender

use of javax.jms.QueueSender 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)

Example 2 with QueueSender

use of javax.jms.QueueSender in project opennms by OpenNMS.

the class DaemonContextIT method canUseEmbeddedActiveMQBroker.

/**
 * Verifies that the embedded ActiveMQ broker bootstraps successfully
 * and is accessible using the provided connection factory.
 */
@Test
public void canUseEmbeddedActiveMQBroker() throws Throwable {
    QueueConnection connection = activeMQConnectionFactory.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    TextMessage message = session.createTextMessage();
    message.setText("ping");
    QueueSender sender = session.createSender(session.createQueue("pong"));
    sender.send(message);
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 3 with QueueSender

use of javax.jms.QueueSender in project Payara by payara.

the class UnitTest method testTimer.

@Test
public void testTimer() throws Exception {
    QueueConnection queueConnection = null;
    QueueSession queueSession = null;
    try {
        InitialContext ic = new InitialContext();
        QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("jms/TestQueueConnectionFactory");
        javax.jms.Queue queue = (javax.jms.Queue) ic.lookup("jms/TestQueue");
        queueConnection = qcf.createQueueConnection();
        queueConnection.start();
        queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender sender = queueSession.createSender(queue);
        String str = "Hi From BHAVANI";
        TextMessage msg = queueSession.createTextMessage(str);
        sender.send(msg);
        Thread.sleep(5000);
        byte[] message = new byte[msg.getText().length()];
        File savedFile = new File(System.getProperty("java.io.tmpdir"), "embedded_mdb_onmessage.txt");
        FileInputStream is = new FileInputStream(savedFile);
        is.read(message);
        String savedMsg = new String(message);
        if (!savedMsg.equals(str)) {
            throw new Exception("Sent message [" + str + " ] does not match the received message [" + savedMsg + "]");
        } else {
            System.out.println("Sent message [" + str + " ]  matches the received message [" + savedMsg + "]");
        }
        savedFile.delete();
    } finally {
        try {
            queueSession.close();
            queueConnection.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) FileInputStream(java.io.FileInputStream) QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) File(java.io.File) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 4 with QueueSender

use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.

the class SimpleBrowseQueueMessageIT method messageTestBase.

private void messageTestBase(MessageTestType mtt, String selector, int numExpected) throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        drainQueue(queueSession, queue);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queueSender.send(mtt.gen(queueSession, (Serializable) queue));
    } finally {
        reconnect();
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    {
        // Browse queue before receiving message
        QueueBrowser queueBrowser = queueSession.createBrowser(queue, selector);
        Enumeration<?> e = queueBrowser.getEnumeration();
        int numE = 0;
        Message msg = null;
        while (e.hasMoreElements()) {
            ++numE;
            msg = (Message) e.nextElement();
            mtt.check(msg, (Serializable) queue);
        }
        assertEquals(numExpected, numE, "Wrong number of messages on browse queue");
    }
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
Also used : Serializable(java.io.Serializable) Enumeration(java.util.Enumeration) Message(javax.jms.Message) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) QueueBrowser(javax.jms.QueueBrowser)

Example 5 with QueueSender

use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.

the class SimpleQueueMessageIT method messageTestBase.

private void messageTestBase(MessageTestType mtt) throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        drainQueue(queueSession, queue);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queueSender.send(mtt.gen(queueSession, (Serializable) queue));
    } finally {
        reconnect();
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
Also used : Serializable(java.io.Serializable) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Aggregations

QueueSender (javax.jms.QueueSender)52 QueueSession (javax.jms.QueueSession)48 Queue (javax.jms.Queue)31 TextMessage (javax.jms.TextMessage)24 QueueReceiver (javax.jms.QueueReceiver)22 Message (javax.jms.Message)14 QueueConnection (javax.jms.QueueConnection)14 JMSException (javax.jms.JMSException)13 Test (org.junit.jupiter.api.Test)12 Serializable (java.io.Serializable)10 ObjectMessage (javax.jms.ObjectMessage)10 Test (org.junit.Test)8 InitialContext (javax.naming.InitialContext)5 MapMessage (javax.jms.MapMessage)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 GetResponse (com.rabbitmq.client.GetResponse)3 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)3 Enumeration (java.util.Enumeration)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3