use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory in project activemq-artemis by apache.
the class OutgoingConnectionNoJTATest method testSimpleMessageSendAndReceiveSessionTransacted.
@Test
public void testSimpleMessageSendAndReceiveSessionTransacted() throws Exception {
setupDLQ(10);
resourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
resourceAdapter.start(ctx);
ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
mcf.setAllowLocalTransactions(true);
mcf.setResourceAdapter(resourceAdapter);
ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
Session s = queueConnection.createSession(true, Session.SESSION_TRANSACTED);
Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
MessageProducer mp = s.createProducer(q);
MessageConsumer consumer = s.createConsumer(q);
Message message = s.createTextMessage("test");
mp.send(message);
s.commit();
queueConnection.start();
TextMessage textMessage = (TextMessage) consumer.receive(1000);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
s.rollback();
textMessage = (TextMessage) consumer.receive(1000);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
s.commit();
textMessage = (TextMessage) consumer.receiveNoWait();
assertNull(textMessage);
}
use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory 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