use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class BasicOpenWireTest method createFactories.
protected void createFactories() {
factory = new ActiveMQConnectionFactory(getConnectionUrl());
looseFactory = new ActiveMQConnectionFactory(urlStringLoose);
xaFactory = new ActiveMQXAConnectionFactory(getConnectionUrl());
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class MessageListenerRedeliveryTest method createRetryConnection.
protected Connection createRetryConnection() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlString);
factory.setRedeliveryPolicy(getRedeliveryPolicy());
return factory.createConnection();
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class VirtualTopicToFQQNOpenWireTest method testAutoVirtualTopicFQQN.
@Test
public void testAutoVirtualTopicFQQN() throws Exception {
Connection connection = null;
SimpleString topic = new SimpleString("VirtualTopic.Orders");
this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);
try {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(urlString);
activeMQConnectionFactory.setWatchTopicAdvisories(false);
connection = activeMQConnectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic(topic.toString());
MessageConsumer messageConsumerA = session.createConsumer(session.createQueue("Consumer.A." + topic.toString()));
MessageConsumer messageConsumerB = session.createConsumer(session.createQueue("Consumer.B." + topic.toString()));
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);
assertTrue((messageReceivedA != null && messageReceivedB != null));
String text = messageReceivedA.getText();
assertEquals("This is a text message", text);
messageConsumerA.close();
messageConsumerB.close();
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class OpenWireDivertNonExclusiveTest method testSingleNonExclusiveDivertOpenWirePublisher.
@Test
public // openwire sending, openwire receiving
void testSingleNonExclusiveDivertOpenWirePublisher() throws Exception {
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession coreSession = sf.createSession(false, true, true);
final SimpleString queueName1 = new SimpleString("queue1");
final SimpleString queueName2 = new SimpleString("queue2");
coreSession.createQueue(new SimpleString(forwardAddress), RoutingType.ANYCAST, queueName1, null, false);
coreSession.createQueue(new SimpleString(testAddress), RoutingType.ANYCAST, queueName2, null, false);
coreSession.close();
// use openwire to receive
factory = new ActiveMQConnectionFactory(urlString);
Connection openwireConnection = factory.createConnection();
try {
Session session = openwireConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
openwireConnection.start();
MessageProducer producer = session.createProducer(session.createQueue(testAddress));
final int numMessages = 10;
final String propKey = "testkey";
for (int i = 0; i < numMessages; i++) {
Message message = session.createMessage();
message.setIntProperty(propKey, i);
producer.send(message);
}
Queue q1 = session.createQueue(CompositeAddress.toFullQN(testAddress, "queue1"));
Queue q2 = session.createQueue(CompositeAddress.toFullQN(forwardAddress, "queue2"));
MessageConsumer consumer1 = session.createConsumer(q1);
MessageConsumer consumer2 = session.createConsumer(q2);
System.out.println("receiving ...");
for (int i = 0; i < numMessages; i++) {
Message message = consumer1.receive(TIMEOUT);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey.toString()));
message.acknowledge();
}
Assert.assertNull(consumer1.receive(50));
for (int i = 0; i < numMessages; i++) {
Message message = consumer2.receive(TIMEOUT);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey.toString()));
message.acknowledge();
}
Assert.assertNull(consumer2.receive(50));
} finally {
if (openwireConnection != null) {
openwireConnection.close();
}
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class VerySimpleOenwireTest method testOpenWireExample.
/**
* This is the example shipped with the distribution
*
* @throws Exception
*/
@Test
public void testOpenWireExample() throws Exception {
Connection exConn = null;
SimpleString durableQueue = new SimpleString("exampleQueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
try {
ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
Queue queue = new ActiveMQQueue("exampleQueue");
exConn = exFact.createConnection();
exConn.start();
Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
} finally {
if (exConn != null) {
exConn.close();
}
}
}
Aggregations