use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class SimpleOpenWireTest method testMixedOpenWireExample.
@Test
public void testMixedOpenWireExample() throws Exception {
Connection openConn = null;
SimpleString durableQueue = new SimpleString("exampleQueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
ActiveMQConnectionFactory openCF = new ActiveMQConnectionFactory();
Queue queue = new ActiveMQQueue("exampleQueue");
openConn = openCF.createConnection();
openConn.start();
Session openSession = openConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = openSession.createProducer(queue);
TextMessage message = openSession.createTextMessage("This is a text message");
producer.send(message);
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory artemisCF = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory();
Connection artemisConn = artemisCF.createConnection();
Session artemisSession = artemisConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
artemisConn.start();
MessageConsumer messageConsumer = artemisSession.createConsumer(artemisSession.createQueue("exampleQueue"));
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
openConn.close();
artemisConn.close();
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class SimpleOpenWireTest 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(durableQueueName);
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();
}
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class SimpleOpenWireTest method testMixedOpenWireExample2.
// simple test sending openwire, consuming core
@Test
public void testMixedOpenWireExample2() throws Exception {
Connection conn1 = null;
SimpleString durableQueue = new SimpleString("exampleQueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory artemisCF = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory();
conn1 = artemisCF.createConnection();
conn1.start();
Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session1.createProducer(queue);
for (int i = 0; i < 10; i++) {
TextMessage message = session1.createTextMessage("This is a text message");
producer.send(message);
}
ActiveMQConnectionFactory openCF = new ActiveMQConnectionFactory();
Connection conn2 = openCF.createConnection();
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
MessageConsumer messageConsumer = sess2.createConsumer(sess2.createQueue("exampleQueue"));
for (int i = 0; i < 10; i++) {
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
}
conn1.close();
conn2.close();
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class OpenWireJMSClusteredTestBase method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
setupServer(0, true, true);
setupServer(1, true, true);
setupClusterConnection("cluster0", "", MessageLoadBalancingType.ON_DEMAND, 1, true, 0, 1);
setupClusterConnection("cluster1", "", MessageLoadBalancingType.ON_DEMAND, 1, true, 1, 0);
startServers(0, 1);
waitForTopology(servers[0], 2);
waitForTopology(servers[1], 2);
setupSessionFactory(0, true);
setupSessionFactory(1, true);
String uri1 = getServerUri(0);
String uri2 = getServerUri(1);
openWireCf1 = new ActiveMQConnectionFactory(uri1);
openWireCf2 = new ActiveMQConnectionFactory(uri2);
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ProducerFlowControlSendFailTest method testPublishWithTX.
@Test
public void testPublishWithTX() throws Exception {
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) getConnectionFactory();
// with sendFail, there must be no flowControllwindow
// sendFail is an alternative flow control mechanism that does not block
factory.setUseAsyncSend(true);
this.flowControlConnection = (ActiveMQConnection) factory.createConnection();
this.flowControlConnection.start();
final Session session = this.flowControlConnection.createSession(true, Session.SESSION_TRANSACTED);
final MessageProducer producer = session.createProducer(queueA);
int successSent = 0;
boolean exception = false;
try {
for (int i = 0; i < 5000; i++) {
producer.send(session.createTextMessage("Test message"));
session.commit();
successSent++;
}
} catch (Exception e) {
exception = true;
// with async send, there will be no exceptions
e.printStackTrace();
}
Assert.assertTrue(exception);
// resourceException on second message, resumption if we
// can receive 10
MessageConsumer consumer = session.createConsumer(queueA);
TextMessage msg;
for (int idx = 0; idx < successSent; ++idx) {
msg = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(msg);
System.out.println("Received " + msg);
if (msg != null) {
msg.acknowledge();
}
session.commit();
}
consumer.close();
}
Aggregations