use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class CustomConnectionFactoryNameTest method testConnectionFactoriesAreConfigured.
public void testConnectionFactoriesAreConfigured() throws NamingException {
super.testConnectionFactoriesArePresent();
ActiveMQConnectionFactory factory1 = (ActiveMQConnectionFactory) context.lookup("jms/Connection");
assertNull(factory1.getClientID());
ActiveMQConnectionFactory factory2 = (ActiveMQConnectionFactory) context.lookup("jms/DURABLE_SUB_CONNECTION_FACTORY");
assertEquals("testclient", factory2.getClientID());
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class InitialContextTest method testConnectionFactoryPolicyConfig.
public void testConnectionFactoryPolicyConfig() throws Exception {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put(Context.PROVIDER_URL, "tcp://localhost:65432");
properties.put("prefetchPolicy.queuePrefetch", "777");
properties.put("redeliveryPolicy.maximumRedeliveries", "15");
properties.put("redeliveryPolicy.backOffMultiplier", "32");
InitialContext context = new InitialContext(properties);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
assertEquals(777, connectionFactory.getPrefetchPolicy().getQueuePrefetch());
assertEquals(15, connectionFactory.getRedeliveryPolicy().getMaximumRedeliveries());
assertEquals(32d, connectionFactory.getRedeliveryPolicy().getBackOffMultiplier());
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class InitialContextTest method testUsingStandardJNDIKeys.
public void testUsingStandardJNDIKeys() throws Exception {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
String expected = "tcp://localhost:65432";
properties.put(Context.PROVIDER_URL, expected);
InitialContext context = new InitialContext(properties);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
assertEquals("the brokerURL should match", expected, connectionFactory.getBrokerURL());
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class FQQNOpenWireTest method testFQNConsumer.
@Test
public void testFQNConsumer() throws Exception {
Connection exConn = null;
SimpleString durableQueue = new SimpleString("myqueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
try {
ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
exConn = exFact.createConnection();
exConn.start();
Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(durableQueue.toString());
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
Destination destinationFQN = session.createQueue(CompositeAddress.toFullQN(durableQueue, durableQueue).toString());
MessageConsumer messageConsumer = session.createConsumer(destinationFQN);
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
} finally {
if (exConn != null) {
exConn.close();
}
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class FQQNOpenWireTest method testVirtualTopicFQQNAutoCreateQAndAddress.
@Test
public void testVirtualTopicFQQNAutoCreateQAndAddress() throws Exception {
Connection exConn = null;
SimpleString topic = new SimpleString("VirtualTopic.Orders");
SimpleString subscriptionQ = new SimpleString("Consumer.A");
// defaults are false via test setUp
this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);
try {
ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
exFact.setWatchTopicAdvisories(false);
exConn = exFact.createConnection();
exConn.start();
Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic(topic.toString());
MessageProducer producer = session.createProducer(destination);
Destination destinationFQN = session.createQueue(CompositeAddress.toFullQN(topic, subscriptionQ).toString());
MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
// only one consumer should get the message
TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);
assertTrue((messageReceivedA == null || messageReceivedB == null));
String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
assertEquals("This is a text message", text);
messageConsumerA.close();
messageConsumerB.close();
} finally {
if (exConn != null) {
exConn.close();
}
}
}
Aggregations