use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class QueueCommandTest method testCreateCoreQueueWithFilter.
@Test
public void testCreateCoreQueueWithFilter() throws Exception {
String queueName = "queue2";
String filerString = "color='green'";
CreateQueue command = new CreateQueue();
command.setName(queueName);
command.setFilter("color='green'");
command.setAutoCreateAddress(true);
command.setMulticast(true);
command.setAnycast(false);
command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
checkExecutionPassed(command);
Queue queue = server.locateQueue(new SimpleString(queueName));
assertNotNull(queue);
assertEquals(new SimpleString(filerString), queue.getFilter().getFilterString());
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class AcknowledgeTest method testAsyncConsumerAck.
@Test
public void testAsyncConsumerAck() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
final ClientSession session = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientConsumer cc = session.createConsumer(queueA);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
}
final CountDownLatch latch = new CountDownLatch(numMessages);
session.start();
cc.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(final ClientMessage message) {
try {
message.acknowledge();
} catch (ActiveMQException e) {
try {
session.close();
} catch (ActiveMQException e1) {
e1.printStackTrace();
}
}
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Assert.assertEquals(0, q.getDeliveringCount());
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class AcknowledgeTest method testReceiveAckLastMessageOnly.
@Test
public void testReceiveAckLastMessageOnly() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator().setAckBatchSize(0).setBlockOnAcknowledge(true);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
ClientSession session = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientConsumer cc = session.createConsumer(queueA);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
}
session.start();
ClientMessage cm = null;
for (int i = 0; i < numMessages; i++) {
cm = cc.receive(5000);
Assert.assertNotNull(cm);
}
cm.acknowledge();
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Assert.assertEquals(0, q.getDeliveringCount());
session.close();
sendSession.close();
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class AcknowledgeTest method testAsyncConsumerAckLastMessageOnly.
@Test
public void testAsyncConsumerAckLastMessageOnly() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
final ClientSession session = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientConsumer cc = session.createConsumer(queueA);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
}
final CountDownLatch latch = new CountDownLatch(numMessages);
session.start();
cc.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(final ClientMessage message) {
if (latch.getCount() == 1) {
try {
message.acknowledge();
} catch (ActiveMQException e) {
try {
session.close();
} catch (ActiveMQException e1) {
e1.printStackTrace();
}
}
}
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Assert.assertEquals(0, q.getDeliveringCount());
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class AutoDeleteJmsDestinationTest method testAutoDeleteNegative.
@Test
public void testAutoDeleteNegative() throws Exception {
server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoDeleteQueues(false));
Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = ActiveMQJMSClient.createQueue("test");
MessageProducer producer = session.createProducer(queue);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
TextMessage mess = session.createTextMessage("msg" + i);
producer.send(mess);
}
producer.close();
MessageConsumer messageConsumer = session.createConsumer(queue);
connection.start();
for (int i = 0; i < numMessages - 1; i++) {
Message m = messageConsumer.receive(5000);
Assert.assertNotNull(m);
}
session.close();
// ensure the queue is still there
Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString("test")).getBindable();
Assert.assertEquals(1, q.getMessageCount());
Assert.assertEquals(numMessages, q.getMessagesAdded());
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageConsumer = session.createConsumer(queue);
Message m = messageConsumer.receive(5000);
Assert.assertNotNull(m);
connection.close();
// ensure the queue was not removed
Assert.assertNotNull(server.getPostOffice().getBinding(new SimpleString("test")));
}
Aggregations