Search in sources :

Example 1 with PollingMessageListenerContainer

use of org.apache.cxf.transport.jms.util.PollingMessageListenerContainer 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 2 with PollingMessageListenerContainer

use of org.apache.cxf.transport.jms.util.PollingMessageListenerContainer in project cxf by apache.

the class JMSConduit method setupReplyDestination.

private void setupReplyDestination(Session session) throws JMSException {
    if (staticReplyDestination == null) {
        synchronized (this) {
            if (staticReplyDestination == null) {
                staticReplyDestination = jmsConfig.getReplyDestination(session);
                String messageSelector = JMSFactory.getMessageSelector(jmsConfig, conduitId);
                if (jmsConfig.getMessageSelector() != null) {
                    messageSelector += (messageSelector != null && !messageSelector.isEmpty() ? " AND " : "") + jmsConfig.getMessageSelector();
                }
                if (messageSelector == null && !jmsConfig.isPubSubDomain()) {
                    // An option for this might be a good idea for people who do not plan to share queues.
                    return;
                }
                AbstractMessageListenerContainer container;
                if (jmsConfig.isOneSessionPerConnection()) {
                    container = new PollingMessageListenerContainer(jmsConfig, true, this);
                } else {
                    container = new MessageListenerContainer(getConnection(), staticReplyDestination, this);
                }
                container.setTransactionManager(jmsConfig.getTransactionManager());
                container.setTransacted(jmsConfig.isSessionTransacted());
                container.setDurableSubscriptionName(jmsConfig.getDurableSubscriptionName());
                container.setMessageSelector(messageSelector);
                Object executor = bus.getProperty(JMSFactory.JMS_CONDUIT_EXECUTOR);
                if (executor instanceof Executor) {
                    container.setExecutor((Executor) executor);
                }
                container.start();
                jmsListener = container;
                addBusListener();
            }
        }
    }
}
Also used : Executor(java.util.concurrent.Executor) PollingMessageListenerContainer(org.apache.cxf.transport.jms.util.PollingMessageListenerContainer) MessageListenerContainer(org.apache.cxf.transport.jms.util.MessageListenerContainer) PollingMessageListenerContainer(org.apache.cxf.transport.jms.util.PollingMessageListenerContainer) AbstractMessageListenerContainer(org.apache.cxf.transport.jms.util.AbstractMessageListenerContainer) AbstractMessageListenerContainer(org.apache.cxf.transport.jms.util.AbstractMessageListenerContainer)

Aggregations

Executor (java.util.concurrent.Executor)2 PollingMessageListenerContainer (org.apache.cxf.transport.jms.util.PollingMessageListenerContainer)2 Destination (javax.jms.Destination)1 ExceptionListener (javax.jms.ExceptionListener)1 JMSException (javax.jms.JMSException)1 Session (javax.jms.Session)1 AbstractMultiplexDestination (org.apache.cxf.transport.AbstractMultiplexDestination)1 AbstractMessageListenerContainer (org.apache.cxf.transport.jms.util.AbstractMessageListenerContainer)1 MessageListenerContainer (org.apache.cxf.transport.jms.util.MessageListenerContainer)1