Search in sources :

Example 1 with ClientProtocolManagerFactory

use of org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory in project wildfly by wildfly.

the class ExternalJMSQueueService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    NamingStore namingStore = namingStoreInjector.getOptionalValue();
    if (namingStore != null) {
        final Queue managementQueue = config.getManagementQueue();
        final NamingContext storeBaseContext = new NamingContext(namingStore, null);
        try {
            ConnectionFactory cf = (ConnectionFactory) storeBaseContext.lookup(pcfInjector.getValue().getBindInfo().getAbsoluteJndiName());
            if (cf instanceof ActiveMQRAConnectionFactory) {
                final ActiveMQRAConnectionFactory raCf = (ActiveMQRAConnectionFactory) cf;
                final ServerLocator locator = raCf.getDefaultFactory().getServerLocator();
                final ClientProtocolManagerFactory protocolManagerFactory = locator.getProtocolManagerFactory();
                sessionFactory = locator.createSessionFactory();
                ClusterTopologyListener listener = new ClusterTopologyListener() {

                    @Override
                    public void nodeUP(TopologyMember member, boolean last) {
                        try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(false, member.getLive())) {
                            factory.getServerLocator().setProtocolManagerFactory(protocolManagerFactory);
                            MessagingLogger.ROOT_LOGGER.infof("Creating queue %s on node UP %s - %s", queueName, member.getNodeId(), member.getLive().toJson());
                            config.createQueue(factory, managementQueue, queueName);
                        } catch (JMSException | StartException ex) {
                            MessagingLogger.ROOT_LOGGER.errorf(ex, "Creating queue %s on node UP %s failed", queueName, member.getLive().toJson());
                            throw new RuntimeException(ex);
                        }
                        if (member.getBackup() != null) {
                            try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(false, member.getBackup())) {
                                factory.getServerLocator().setProtocolManagerFactory(protocolManagerFactory);
                                MessagingLogger.ROOT_LOGGER.infof("Creating queue %s on backup node UP %s - %s", queueName, member.getNodeId(), member.getBackup().toJson());
                                config.createQueue(factory, managementQueue, queueName);
                            } catch (JMSException | StartException ex) {
                                throw new RuntimeException(ex);
                            }
                        }
                    }

                    @Override
                    public void nodeDown(long eventUID, String nodeID) {
                    }
                };
                locator.addClusterTopologyListener(listener);
                Collection<TopologyMemberImpl> members = locator.getTopology().getMembers();
                if (members == null || members.isEmpty()) {
                    config.createQueue(cf, managementQueue, queueName);
                }
            } else {
                config.createQueue(cf, managementQueue, queueName);
            }
        } catch (Exception ex) {
            MessagingLogger.ROOT_LOGGER.errorf(ex, "Error starting the external queue service %s", ex.getMessage());
            throw new StartException(ex);
        } finally {
            try {
                storeBaseContext.close();
            } catch (NamingException ex) {
                MessagingLogger.ROOT_LOGGER.tracef(ex, "Error closing the naming context %s", ex.getMessage());
            }
        }
    }
    queue = ActiveMQDestination.createQueue(queueName);
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterTopologyListener(org.apache.activemq.artemis.api.core.client.ClusterTopologyListener) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) JMSException(javax.jms.JMSException) NamingContext(org.jboss.as.naming.NamingContext) NamingException(javax.naming.NamingException) StartException(org.jboss.msc.service.StartException) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ClientProtocolManagerFactory(org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory) StartException(org.jboss.msc.service.StartException) NamingException(javax.naming.NamingException) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) Queue(javax.jms.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 2 with ClientProtocolManagerFactory

use of org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory in project wildfly by wildfly.

the class ExternalJMSTopicService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    NamingStore namingStore = namingStoreInjector.getOptionalValue();
    if (namingStore != null) {
        final Queue managementQueue = config.getManagementQueue();
        final NamingContext storeBaseContext = new NamingContext(namingStore, null);
        try {
            ConnectionFactory cf = (ConnectionFactory) storeBaseContext.lookup(pcfInjector.getValue().getBindInfo().getAbsoluteJndiName());
            if (cf instanceof ActiveMQRAConnectionFactory) {
                final ActiveMQRAConnectionFactory raCf = (ActiveMQRAConnectionFactory) cf;
                final ServerLocator locator = raCf.getDefaultFactory().getServerLocator();
                final ClientProtocolManagerFactory protocolManagerFactory = locator.getProtocolManagerFactory();
                sessionFactory = locator.createSessionFactory();
                ClusterTopologyListener listener = new ClusterTopologyListener() {

                    @Override
                    public void nodeUP(TopologyMember member, boolean last) {
                        try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(false, member.getLive())) {
                            factory.getServerLocator().setProtocolManagerFactory(protocolManagerFactory);
                            MessagingLogger.ROOT_LOGGER.infof("Creating topic %s on node UP %s - %s", topicName, member.getNodeId(), member.getLive().toJson());
                            config.createTopic(factory, managementQueue, topicName);
                        } catch (JMSException | StartException ex) {
                            MessagingLogger.ROOT_LOGGER.errorf(ex, "Creating topic %s on node UP %s failed", topicName, member.getLive().toJson());
                            throw new RuntimeException(ex);
                        }
                        if (member.getBackup() != null) {
                            try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(false, member.getBackup())) {
                                factory.getServerLocator().setProtocolManagerFactory(protocolManagerFactory);
                                MessagingLogger.ROOT_LOGGER.infof("Creating topic %s on backup node UP %s - %s", topicName, member.getNodeId(), member.getBackup().toJson());
                                config.createTopic(factory, managementQueue, topicName);
                            } catch (JMSException | StartException ex) {
                                throw new RuntimeException(ex);
                            }
                        }
                    }

                    @Override
                    public void nodeDown(long eventUID, String nodeID) {
                    }
                };
                locator.addClusterTopologyListener(listener);
                Collection<TopologyMemberImpl> members = locator.getTopology().getMembers();
                if (members == null || members.isEmpty()) {
                    config.createTopic(cf, managementQueue, topicName);
                }
            } else {
                config.createTopic(cf, managementQueue, topicName);
            }
        } catch (Exception ex) {
            MessagingLogger.ROOT_LOGGER.errorf(ex, "Error starting the external queue service %s", ex.getMessage());
            throw new StartException(ex);
        } finally {
            try {
                storeBaseContext.close();
            } catch (NamingException ex) {
                MessagingLogger.ROOT_LOGGER.tracef(ex, "Error closing the naming context %s", ex.getMessage());
            }
        }
    }
    topic = ActiveMQDestination.createTopic(topicName);
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterTopologyListener(org.apache.activemq.artemis.api.core.client.ClusterTopologyListener) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) JMSException(javax.jms.JMSException) NamingContext(org.jboss.as.naming.NamingContext) NamingException(javax.naming.NamingException) StartException(org.jboss.msc.service.StartException) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ClientProtocolManagerFactory(org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory) StartException(org.jboss.msc.service.StartException) NamingException(javax.naming.NamingException) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) Queue(javax.jms.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Aggregations

ConnectionFactory (javax.jms.ConnectionFactory)2 JMSException (javax.jms.JMSException)2 Queue (javax.jms.Queue)2 NamingException (javax.naming.NamingException)2 ClusterTopologyListener (org.apache.activemq.artemis.api.core.client.ClusterTopologyListener)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 TopologyMember (org.apache.activemq.artemis.api.core.client.TopologyMember)2 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)2 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)2 ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)2 ClientProtocolManagerFactory (org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory)2 NamingContext (org.jboss.as.naming.NamingContext)2 NamingStore (org.jboss.as.naming.NamingStore)2 StartException (org.jboss.msc.service.StartException)2