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);
}
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);
}
Aggregations