Search in sources :

Example 71 with Destination

use of javax.jms.Destination in project cxf by apache.

the class JMSDestination method createTargetDestinationListener.

private JMSListenerContainer createTargetDestinationListener() {
    Session session = null;
    try {
        ExceptionListener exListener = new ExceptionListener() {

            public void onException(JMSException exception) {
                if (!shutdown) {
                    LOG.log(Level.WARNING, "Exception on JMS connection. Trying to reconnect", exception);
                    restartConnection();
                }
            }
        };
        PollingMessageListenerContainer container;
        if (!jmsConfig.isOneSessionPerConnection()) {
            connection = JMSFactory.createConnection(jmsConfig);
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = jmsConfig.getTargetDestination(session);
            container = new PollingMessageListenerContainer(connection, destination, this, exListener);
        } else {
            container = new PollingMessageListenerContainer(jmsConfig, false, this);
        }
        container.setConcurrentConsumers(jmsConfig.getConcurrentConsumers());
        container.setTransactionManager(jmsConfig.getTransactionManager());
        container.setMessageSelector(jmsConfig.getMessageSelector());
        container.setTransacted(jmsConfig.isSessionTransacted());
        container.setDurableSubscriptionName(jmsConfig.getDurableSubscriptionName());
        container.setPubSubNoLocal(jmsConfig.isPubSubNoLocal());
        Object executor = bus.getProperty(JMSFactory.JMS_DESTINATION_EXECUTOR);
        if (executor instanceof Executor) {
            container.setExecutor((Executor) executor);
        }
        container.setJndiEnvironment(jmsConfig.getJndiEnvironment());
        container.start();
        suspendedContinuations.setListenerContainer(container);
        if (!jmsConfig.isOneSessionPerConnection()) {
            connection.start();
        }
        return container;
    } catch (JMSException e) {
        ResourceCloser.close(connection);
        this.connection = null;
        throw JMSUtil.convertJmsException(e);
    } finally {
        ResourceCloser.close(session);
    }
}
Also used : AbstractMultiplexDestination(org.apache.cxf.transport.AbstractMultiplexDestination) Destination(javax.jms.Destination) Executor(java.util.concurrent.Executor) PollingMessageListenerContainer(org.apache.cxf.transport.jms.util.PollingMessageListenerContainer) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 72 with Destination

use of javax.jms.Destination in project cxf by apache.

the class PollingMessageListenerContainer method createConsumer.

private MessageConsumer createConsumer(final Connection connection, final Session session) throws JMSException {
    final MessageConsumer consumer;
    if (jmsConfig != null && jmsConfig.isOneSessionPerConnection()) {
        Destination destination;
        if (!isReply()) {
            destination = jmsConfig.getTargetDestination(session);
        } else {
            destination = jmsConfig.getReplyDestination(session);
        }
        consumer = createConsumer(destination, session);
        connection.start();
    } else {
        consumer = createConsumer(session);
    }
    return consumer;
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer)

Example 73 with Destination

use of javax.jms.Destination in project apex-malhar by apache.

the class JMSTestBase method produceMsg.

public void produceMsg(String text) throws Exception {
    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
    // Create a Connection
    Connection connection = connectionFactory.createConnection();
    connection.start();
    // Create a Session
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    // Create the destination (Topic or Queue)
    Destination destination = session.createQueue("TEST.FOO");
    // Create a MessageProducer from the Session to the Topic or Queue
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    // Create a messages
    TextMessage message = session.createTextMessage(text);
    producer.send(message);
    // Clean up
    session.close();
    connection.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 74 with Destination

use of javax.jms.Destination in project apex-malhar by apache.

the class JMSObjectInputOperatorTest method produceMsg.

private void produceMsg() throws Exception {
    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
    // Create a Connection
    testMeta.connection = connectionFactory.createConnection();
    testMeta.connection.start();
    // Create a Session
    testMeta.session = testMeta.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the destination (Topic or Queue)
    Destination destination = testMeta.session.createQueue("TEST.FOO");
    // Create a MessageProducer from the Session to the Topic or Queue
    testMeta.producer = testMeta.session.createProducer(destination);
    testMeta.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination)

Example 75 with Destination

use of javax.jms.Destination in project tomee by apache.

the class JmsTest method testProxy.

public void testProxy() throws Exception {
    // Create a Session
    final Connection connection = connectionFactory.createConnection();
    try {
        connection.start();
        final Destination requestQueue = createListener(connection);
        createSender(connection, requestQueue);
    } finally {
        MdbUtil.close(connection);
    }
}
Also used : Destination(javax.jms.Destination) Connection(javax.jms.Connection)

Aggregations

Destination (javax.jms.Destination)178 Test (org.junit.Test)51 TextMessage (javax.jms.TextMessage)47 Session (javax.jms.Session)46 JMSException (javax.jms.JMSException)45 Connection (javax.jms.Connection)32 MessageProducer (javax.jms.MessageProducer)31 Message (javax.jms.Message)30 ConnectionFactory (javax.jms.ConnectionFactory)24 MessageConsumer (javax.jms.MessageConsumer)24 JMSContext (javax.jms.JMSContext)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ObjectMessage (javax.jms.ObjectMessage)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 InitialContext (javax.naming.InitialContext)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 Queue (javax.jms.Queue)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 MapMessage (javax.jms.MapMessage)7 HashMap (java.util.HashMap)6