use of javax.jms.XAQueueConnectionFactory in project activemq-artemis by apache.
the class ConnectionFactoryTest method testFactoryTypes.
@Test
public void testFactoryTypes() throws Exception {
deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE_XA_FALSE", "/CF_QUEUE_XA_FALSE");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.CF, "CF_XA_FALSE", "/CF_XA_FALSE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC", "/CF_GENERIC");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_GENERIC_XA_TRUE", "/CF_GENERIC_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC_XA_FALSE", "/CF_GENERIC_XA_FALSE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC_XA_FALSE", "/CF_TOPIC_XA_FALSE");
ActiveMQConnectionFactory factory = null;
factory = (ActiveMQConnectionFactory) ic.lookup("/ConnectionFactory");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_TRUE");
Assert.assertTrue(factory instanceof XAConnectionFactory);
assertNTypes(factory, 6);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_FALSE");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_TRUE");
Assert.assertTrue(factory instanceof XAConnectionFactory);
assertNTypes(factory, 6);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_FALSE");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE");
Assert.assertTrue(factory instanceof QueueConnectionFactory);
assertNTypes(factory, 3);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
Assert.assertTrue(factory instanceof XAQueueConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_FALSE");
Assert.assertTrue(factory instanceof QueueConnectionFactory);
assertNTypes(factory, 3);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC");
Assert.assertTrue(factory instanceof TopicConnectionFactory);
assertNTypes(factory, 3);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
Assert.assertTrue(factory instanceof XATopicConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_FALSE");
Assert.assertTrue(factory instanceof TopicConnectionFactory);
assertNTypes(factory, 3);
undeployConnectionFactory("ConnectionFactory");
undeployConnectionFactory("CF_QUEUE_XA_TRUE");
undeployConnectionFactory("CF_QUEUE_XA_FALSE");
undeployConnectionFactory("CF_XA_TRUE");
undeployConnectionFactory("CF_XA_FALSE");
undeployConnectionFactory("CF_QUEUE");
undeployConnectionFactory("CF_TOPIC");
undeployConnectionFactory("CF_TOPIC_XA_TRUE");
undeployConnectionFactory("CF_GENERIC");
undeployConnectionFactory("CF_GENERIC_XA_TRUE");
undeployConnectionFactory("CF_GENERIC_XA_FALSE");
undeployConnectionFactory("CF_TOPIC_XA_FALSE");
}
use of javax.jms.XAQueueConnectionFactory in project activemq-artemis by apache.
the class ConnectionFactoryTest method testConnectionTypes.
@Test
public void testConnectionTypes() throws Exception {
deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
Connection genericConnection = null;
XAConnection xaConnection = null;
QueueConnection queueConnection = null;
TopicConnection topicConnection = null;
XAQueueConnection xaQueueConnection = null;
XATopicConnection xaTopicConnection = null;
ConnectionFactory genericFactory = (ConnectionFactory) ic.lookup("/ConnectionFactory");
genericConnection = genericFactory.createConnection();
assertConnectionType(genericConnection, "generic");
XAConnectionFactory xaFactory = (XAConnectionFactory) ic.lookup("/CF_XA_TRUE");
xaConnection = xaFactory.createXAConnection();
assertConnectionType(xaConnection, "xa");
QueueConnectionFactory queueCF = (QueueConnectionFactory) ic.lookup("/CF_QUEUE");
queueConnection = queueCF.createQueueConnection();
assertConnectionType(queueConnection, "queue");
TopicConnectionFactory topicCF = (TopicConnectionFactory) ic.lookup("/CF_TOPIC");
topicConnection = topicCF.createTopicConnection();
assertConnectionType(topicConnection, "topic");
XAQueueConnectionFactory xaQueueCF = (XAQueueConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
xaQueueConnection = xaQueueCF.createXAQueueConnection();
assertConnectionType(xaQueueConnection, "xa-queue");
XATopicConnectionFactory xaTopicCF = (XATopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
xaTopicConnection = xaTopicCF.createXATopicConnection();
assertConnectionType(xaTopicConnection, "xa-topic");
genericConnection.close();
xaConnection.close();
queueConnection.close();
topicConnection.close();
xaQueueConnection.close();
xaTopicConnection.close();
undeployConnectionFactory("ConnectionFactory");
undeployConnectionFactory("CF_QUEUE_XA_TRUE");
undeployConnectionFactory("CF_XA_TRUE");
undeployConnectionFactory("CF_QUEUE");
undeployConnectionFactory("CF_TOPIC");
undeployConnectionFactory("CF_TOPIC_XA_TRUE");
}
use of javax.jms.XAQueueConnectionFactory in project ofbiz-framework by apache.
the class JmsServiceEngine method runXaQueue.
protected Map<String, Object> runXaQueue(ModelService modelService, Map<String, Object> context, Element server) throws GenericServiceException {
String serverName = server.getAttribute("jndi-server-name");
String jndiName = server.getAttribute("jndi-name");
String queueName = server.getAttribute("topic-queue");
String userName = server.getAttribute("username");
String password = server.getAttribute("password");
String clientId = server.getAttribute("client-id");
InitialContext jndi = null;
XAQueueConnectionFactory factory = null;
XAQueueConnection con = null;
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (XAQueueConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested());
} catch (NamingException ne) {
JNDIContextFactory.clearInitialContext(serverName);
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (XAQueueConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge2) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
} catch (NamingException ne2) {
throw new GenericServiceException("JNDI lookup problems.", ne2);
}
}
try {
con = factory.createXAQueueConnection(userName, password);
if (clientId.length() > 1)
con.setClientID(userName);
con.start();
// enlist the XAResource
XAQueueSession session = con.createXAQueueSession();
XAResource resource = session.getXAResource();
if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE)
TransactionUtil.enlistResource(resource);
Queue queue = (Queue) jndi.lookup(queueName);
QueueSession qSession = session.getQueueSession();
QueueSender sender = qSession.createSender(queue);
// create/send the message
Message message = makeMessage(session, modelService, context);
sender.send(message);
if (TransactionUtil.getStatus() != TransactionUtil.STATUS_ACTIVE)
session.commit();
Debug.logInfo("Message sent.", module);
// close the connections
sender.close();
session.close();
con.close();
} catch (GenericTransactionException gte) {
throw new GenericServiceException("Problems enlisting resource w/ transaction manager.", gte.getNested());
} catch (NamingException ne) {
throw new GenericServiceException("Problems with JNDI lookup.", ne);
} catch (JMSException je) {
throw new GenericServiceException("JMS Internal Error.", je);
}
return ServiceUtil.returnSuccess();
}
Aggregations