use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class JmsConsumerTest method testPreCommitAcksSetOnConnectionFactory.
@Test
public void testPreCommitAcksSetOnConnectionFactory() throws Exception {
((ActiveMQConnectionFactory) cf).setPreAcknowledge(true);
conn = cf.createConnection();
Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
MessageConsumer consumer = session.createConsumer(jBossQueue);
int noOfMessages = 100;
for (int i = 0; i < noOfMessages; i++) {
producer.send(session.createTextMessage("m" + i));
}
conn.start();
for (int i = 0; i < noOfMessages; i++) {
Message m = consumer.receive(500);
Assert.assertNotNull(m);
}
// Messages should all have been acked since we set pre ack on the cf
SimpleString queueName = new SimpleString(JmsConsumerTest.Q_NAME);
Queue queue = server.locateQueue(queueName);
Wait.assertEquals(0, queue::getDeliveringCount);
Wait.assertEquals(0, queue::getMessageCount);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class JmsConsumerTest method testBrowserOnly.
@Test
public void testBrowserOnly() throws Exception {
((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
int noOfMessages = 10;
for (int i = 0; i < noOfMessages; i++) {
TextMessage textMessage = session.createTextMessage("m" + i);
textMessage.setIntProperty("i", i);
producer.send(textMessage);
}
QueueBrowser browser = session.createBrowser(jBossQueue);
Enumeration enumMessages = browser.getEnumeration();
for (int i = 0; i < noOfMessages; i++) {
Assert.assertTrue(enumMessages.hasMoreElements());
TextMessage msg = (TextMessage) enumMessages.nextElement();
Assert.assertNotNull(msg);
Assert.assertEquals(i, msg.getIntProperty("i"));
}
Assert.assertFalse(enumMessages.hasMoreElements());
conn.close();
// Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this
// point
// which can cause delivering count to flip to 1
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class JmsConsumerTest method testShareDuraleWithJMSContext.
@Test
public void testShareDuraleWithJMSContext() throws Exception {
((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
JMSContext conn = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
JMSConsumer consumer = conn.createSharedDurableConsumer(topic, "c1");
JMSProducer producer = conn.createProducer();
for (int i = 0; i < 100; i++) {
producer.setProperty("count", i).send(topic, "test" + i);
}
JMSContext conn2 = conn.createContext(JMSContext.AUTO_ACKNOWLEDGE);
JMSConsumer consumer2 = conn2.createSharedDurableConsumer(topic, "c1");
for (int i = 0; i < 50; i++) {
String txt = consumer.receiveBody(String.class, 5000);
System.out.println("TXT:" + txt);
Assert.assertNotNull(txt);
txt = consumer.receiveBody(String.class, 5000);
System.out.println("TXT:" + txt);
Assert.assertNotNull(txt);
}
Assert.assertNull(consumer.receiveNoWait());
Assert.assertNull(consumer2.receiveNoWait());
boolean exceptionHappened = false;
try {
conn.unsubscribe("c1");
} catch (Exception e) {
e.printStackTrace();
exceptionHappened = true;
}
Assert.assertTrue(exceptionHappened);
consumer.close();
consumer2.close();
conn2.close();
conn.unsubscribe("c1");
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class JmsConsumerTest method testBrowserAndConsumerSimultaneous.
@Test
public void testBrowserAndConsumerSimultaneous() throws Exception {
((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
QueueBrowser browser = session.createBrowser(jBossQueue);
Enumeration enumMessages = browser.getEnumeration();
MessageConsumer consumer = session.createConsumer(jBossQueue);
int noOfMessages = 10;
for (int i = 0; i < noOfMessages; i++) {
TextMessage textMessage = session.createTextMessage("m" + i);
textMessage.setIntProperty("i", i);
producer.send(textMessage);
}
conn.start();
for (int i = 0; i < noOfMessages; i++) {
TextMessage msg = (TextMessage) enumMessages.nextElement();
Assert.assertNotNull(msg);
Assert.assertEquals(i, msg.getIntProperty("i"));
conn.start();
TextMessage recvMessage = (TextMessage) consumer.receiveNoWait();
Assert.assertNotNull(recvMessage);
conn.stop();
Assert.assertEquals(i, msg.getIntProperty("i"));
}
Assert.assertNull(consumer.receiveNoWait());
Assert.assertFalse(enumMessages.hasMoreElements());
conn.close();
// Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this
// point
// which can cause delivering count to flip to 1
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class JMSServerStartStopTest method testStopStart1.
@Test
public void testStopStart1() throws Exception {
final int numMessages = 5;
for (int j = 0; j < numMessages; j++) {
JMSServerStartStopTest.log.info("Iteration " + j);
jmsServer.start();
ActiveMQConnectionFactory jbcf = createConnectionFactory();
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
Connection conn = jbcf.createConnection();
try {
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = sess.createQueue("myJMSQueue");
MessageProducer producer = sess.createProducer(queue);
TextMessage tm = sess.createTextMessage("message" + j);
producer.send(tm);
} finally {
conn.close();
jbcf.close();
jmsServer.stop();
}
}
jmsServer.start();
jbcf = createConnectionFactory();
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
conn = jbcf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = sess.createQueue("myJMSQueue");
MessageConsumer consumer = sess.createConsumer(queue);
conn.start();
for (int i = 0; i < numMessages; i++) {
TextMessage tm = (TextMessage) consumer.receive(10000);
Assert.assertNotNull("not null", tm);
Assert.assertEquals("message" + i, tm.getText());
}
conn.close();
jbcf.close();
}
Aggregations