Search in sources :

Example 11 with QueueSender

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

the class QueueTestMDB method sendReply.

private void sendReply(Queue destination, String messageID, Exception e) throws JMSException {
    QueueConnection conn = qFactory.createQueueConnection();
    try {
        QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(destination);
        ObjectMessage message = session.createObjectMessage(e);
        message.setJMSCorrelationID(messageID);
        sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
    } finally {
        conn.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) ObjectMessage(javax.jms.ObjectMessage) QueueSession(javax.jms.QueueSession)

Example 12 with QueueSender

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

the class HelloMDB method sendReply.

private void sendReply(String msg, Queue destination, String messageID) throws JMSException {
    QueueConnection conn = qFactory.createQueueConnection("guest", "guest");
    try {
        QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        conn.start();
        QueueSender sender = session.createSender(destination);
        TextMessage message = session.createTextMessage(msg);
        message.setJMSCorrelationID(messageID);
        sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
    } finally {
        conn.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 13 with QueueSender

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

the class MessageBean method onMessage.

public void onMessage(Message message) {
    System.out.println("Got message!!!");
    QueueConnection connection = null;
    try {
        System.out.println("Calling hello1 stateless bean");
        hello1.hello("local ejb3.0 stateless");
        System.out.println("Calling hello2 stateful bean");
        hello2.hello("local ejb3.0 stateful");
        hello2.removeMethod();
        try {
            hello2.hello("this call should not go through");
            throw new Exception("bean should have been removed " + "after removeMethod()");
        } catch (NoSuchEJBException e) {
            System.out.println("Successfully caught EJBException after " + " accessing removed SFSB");
        }
        connection = qcFactory.createQueueConnection();
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(clientQueue);
        TextMessage tmessage = session.createTextMessage();
        tmessage.setText("mdb() invoked");
        System.out.println("Sending message");
        sender.send(tmessage);
        System.out.println("message sent");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 14 with QueueSender

use of javax.jms.QueueSender in project brave by openzipkin.

the class TracingMessageProducer method send.

@Override
public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
    checkQueueSender();
    QueueSender qs = (QueueSender) delegate;
    Span span = createAndStartProducerSpan(message, destination(message));
    SpanInScope ws = tracer.withSpanInScope(span);
    Throwable error = null;
    try {
        qs.send(queue, message, deliveryMode, priority, timeToLive);
    } catch (Throwable t) {
        propagateIfFatal(t);
        error = t;
        throw t;
    } finally {
        if (error != null)
            span.error(error);
        span.finish();
        ws.close();
    }
}
Also used : QueueSender(javax.jms.QueueSender) SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 15 with QueueSender

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

the class MessageListenerTransactionIT method testSerialInvocation.

@Test
public void testSerialInvocation() throws Exception {
    final long sleep = 100;
    TestListener listener = new TestListener(expectedTotalCount, sleep);
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(true, /*transacted*/
    Session.CLIENT_ACKNOWLEDGE);
    /*ignored*/
    Queue[] queues = new Queue[DESTINATIONS.length];
    for (int i = 0; i < DESTINATIONS.length; ++i) {
        queues[i] = queueSession.createQueue(QUEUE_NAME + DESTINATIONS[i]);
    }
    MessageConsumer[] consumers = new MessageConsumer[DESTINATIONS.length];
    for (int i = 0; i < DESTINATIONS.length; ++i) {
        consumers[i] = queueSession.createReceiver(queues[i]);
        consumers[i].setMessageListener(listener);
    }
    QueueSender[] senders = new QueueSender[DESTINATIONS.length];
    for (int i = 0; i < DESTINATIONS.length; ++i) {
        senders[i] = queueSession.createSender(queues[i]);
        senders[i].setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage message = queueSession.createTextMessage(MESSAGE + DESTINATIONS[i]);
        for (int j = 0; j < sendCount; ++j) senders[i].send(message);
    }
    for (int i = 0; i < DESTINATIONS.length; ++i) senders[i].close();
    queueSession.commit();
    // wait for the messages to be received; max wait time expectedTotalCount*sleep*2
    long maxWait = expectedTotalCount * sleep * 2;
    synchronized (listener) {
        int rcvd;
        while (maxWait > 0 && (rcvd = listener.getReceived()) < expectedTotalCount) {
            long startWait = System.currentTimeMillis();
            // wait for a bit more
            listener.wait((expectedTotalCount - rcvd) * sleep);
            maxWait -= (System.currentTimeMillis() - startWait);
        }
    }
    for (int i = 0; i < DESTINATIONS.length; ++i) consumers[i].close();
    // acknowledge the messages
    Message last = listener.getMessage();
    if (last != null) {
        last.acknowledge();
    }
    if (listener.getFailures() != 0) {
        fail("The listener was not invoked serially");
    }
    if (listener.getReceived() != expectedTotalCount) {
        fail("Received " + listener.getReceived() + " messages, but expected " + expectedTotalCount);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) QueueSender(javax.jms.QueueSender) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

QueueSender (javax.jms.QueueSender)59 QueueSession (javax.jms.QueueSession)54 Queue (javax.jms.Queue)36 TextMessage (javax.jms.TextMessage)28 QueueReceiver (javax.jms.QueueReceiver)25 JMSException (javax.jms.JMSException)14 Message (javax.jms.Message)14 QueueConnection (javax.jms.QueueConnection)14 Test (org.junit.jupiter.api.Test)14 Serializable (java.io.Serializable)11 ObjectMessage (javax.jms.ObjectMessage)10 Test (org.junit.Test)8 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)5 InitialContext (javax.naming.InitialContext)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MapMessage (javax.jms.MapMessage)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 IFSAQueue (com.ing.ifsa.IFSAQueue)3 GetResponse (com.rabbitmq.client.GetResponse)3