Search in sources :

Example 36 with QueueSender

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

the class MDBLifecycleCallback 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 == null ? "SUCCESS" : 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 37 with QueueSender

use of javax.jms.QueueSender in project openolat by klemens.

the class JmsIndexer method indexDocument.

@Override
public void indexDocument(String type, Long key) {
    QueueSender sender;
    QueueSession session;
    try {
        JmsIndexWork workUnit = new JmsIndexWork(JmsIndexWork.INDEX, type, key);
        session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        ObjectMessage message = session.createObjectMessage();
        message.setObject(workUnit);
        sender = session.createSender(getJmsQueue());
        sender.send(message);
        session.close();
    } catch (JMSException e) {
        log.error("", e);
    }
}
Also used : QueueSender(javax.jms.QueueSender) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) QueueSession(javax.jms.QueueSession)

Example 38 with QueueSender

use of javax.jms.QueueSender in project openolat by klemens.

the class JmsIndexer method indexDocument.

@Override
public void indexDocument(String type, List<Long> keyList) {
    QueueSender sender;
    QueueSession session;
    try {
        JmsIndexWork workUnit = new JmsIndexWork(JmsIndexWork.INDEX, type, keyList);
        session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        ObjectMessage message = session.createObjectMessage();
        message.setObject(workUnit);
        sender = session.createSender(getJmsQueue());
        sender.send(message);
        session.close();
    } catch (JMSException e) {
        log.error("", e);
    }
}
Also used : QueueSender(javax.jms.QueueSender) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) QueueSession(javax.jms.QueueSession)

Example 39 with QueueSender

use of javax.jms.QueueSender in project openolat by klemens.

the class CertificatesManagerImpl method sendJmsCertificateFile.

private void sendJmsCertificateFile(Certificate certificate, CertificateTemplate template, Float score, Boolean passed, boolean sendMail) {
    QueueSender sender;
    QueueSession session = null;
    try {
        JmsCertificateWork workUnit = new JmsCertificateWork();
        workUnit.setCertificateKey(certificate.getKey());
        if (template != null) {
            workUnit.setTemplateKey(template.getKey());
        }
        workUnit.setPassed(passed);
        workUnit.setScore(score);
        workUnit.setSendMail(sendMail);
        session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        ObjectMessage message = session.createObjectMessage();
        message.setObject(workUnit);
        sender = session.createSender(getJmsQueue());
        sender.send(message);
    } catch (JMSException e) {
        log.error("", e);
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (JMSException e) {
            // last hope
            }
        }
    }
}
Also used : JmsCertificateWork(org.olat.course.certificate.model.JmsCertificateWork) QueueSender(javax.jms.QueueSender) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) QueueSession(javax.jms.QueueSession)

Example 40 with QueueSender

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

the class RabbitMQRedeliverOnNackIT method testRMQRedeliverOnNack.

/**
 * Test that Rabbit re-delivers a received message which has been rolled-back.
 * @throws Exception on test failure
 */
@Test
public void testRMQRedeliverOnNack() throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, /*not transacted*/
        Session.CLIENT_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage message = queueSession.createTextMessage(MESSAGE);
        queueSender.send(message);
    } finally {
        reconnect();
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(true, /*transacted*/
    Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    TextMessage message = (TextMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
    assertNotNull(message, "No message delivered initially");
    assertEquals(MESSAGE, message.getText(), "Wrong message delivered initially");
    queueSession.rollback();
    message = (TextMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
    assertNotNull(message, "No message delivered after rollback");
    assertEquals(MESSAGE, message.getText(), "Wrong message redelivered");
    assertTrue(message.getJMSRedelivered(), "Message not marked 'redelivered'");
    queueSession.commit();
}
Also used : QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) 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