use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class CommitRollbackTest method testReceiveWithRollbackMultipleConsumersDifferentQueues.
@Test
public void testReceiveWithRollbackMultipleConsumersDifferentQueues() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
ClientSession session = cf.createSession(false, false, false);
sendSession.createQueue(addressA, queueA, false);
sendSession.createQueue(addressB, queueB, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientProducer cp2 = sendSession.createProducer(addressB);
ClientConsumer cc = session.createConsumer(queueA);
ClientConsumer cc2 = session.createConsumer(queueB);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
cp2.send(sendSession.createMessage(false));
}
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = cc.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
cm = cc2.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
}
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Queue q2 = (Queue) server.getPostOffice().getBinding(queueB).getBindable();
Assert.assertEquals(numMessages, q.getDeliveringCount());
cc.close();
cc2.close();
session.rollback();
Assert.assertEquals(0, q2.getDeliveringCount());
Assert.assertEquals(numMessages, getMessageCount(q));
Assert.assertEquals(0, q2.getDeliveringCount());
Assert.assertEquals(numMessages, getMessageCount(q));
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class BlockingSendTest method testSinglePersistentBlockingNonSync.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testSinglePersistentBlockingNonSync() throws Exception {
ActiveMQServer server = createServer(true);
ClientSession session = null;
ClientSessionFactory factory = null;
ServerLocator locator = null;
server.getConfiguration().setJournalSyncNonTransactional(false);
server.getConfiguration().setJournalBufferTimeout_AIO(15000);
server.start();
System.out.println("sync = " + server.getConfiguration().isJournalSyncNonTransactional());
locator = createInVMNonHALocator().setBlockOnDurableSend(true);
factory = createSessionFactory(locator);
session = factory.createSession();
session.createQueue("address", RoutingType.ANYCAST, "queue");
ClientProducer prod = session.createProducer("address");
ClientMessage message = session.createMessage(true);
prod.send(message);
ClientConsumer consumer = session.createConsumer("queue");
session.start();
ClientMessage msg = consumer.receive(5000);
Assert.assertNotNull(msg);
msg.acknowledge();
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class ConsumerFilterTest method testTwoConsumers.
@Test
public void testTwoConsumers() throws Exception {
ClientConsumer consumer2 = session.createConsumer("foo", "animal='elephant'");
// Create and consume message that matches the first consumer's filter
ClientMessage message = session.createMessage(false);
message.putStringProperty("animal", "giraffe");
producer.send(message);
ClientMessage received = consumer.receive(10000);
assertNotNull(received);
assertEquals("giraffe", received.getStringProperty("animal"));
assertNull(consumer.receiveImmediate());
assertNull(consumer2.receiveImmediate());
// Create and consume another message that matches the first consumer's filter
message = session.createMessage(false);
message.putStringProperty("animal", "giraffe");
producer.send(message);
received = consumer.receive(10000);
assertNotNull(received);
assertEquals("giraffe", received.getStringProperty("animal"));
assertNull(consumer.receiveImmediate());
assertNull(consumer2.receiveImmediate());
// Create and consume a message that matches the second consumer's filter
message = session.createMessage(false);
message.putStringProperty("animal", "elephant");
producer.send(message);
received = consumer2.receive(10000);
assertNotNull(received);
assertEquals("elephant", received.getStringProperty("animal"));
assertNull(consumer.receiveImmediate());
assertNull(consumer2.receiveImmediate());
// Create and consume another message that matches the second consumer's filter
message = session.createMessage(false);
message.putStringProperty("animal", "elephant");
producer.send(message);
received = consumer2.receive(1000);
assertNotNull(received);
assertEquals("elephant", received.getStringProperty("animal"));
assertNull(consumer.receiveImmediate());
assertNull(consumer2.receiveImmediate());
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class ConsumerStuckTest method testClientStuckTestWithDirectDelivery.
@Test
public void testClientStuckTestWithDirectDelivery() throws Exception {
ServerLocator locator = createNettyNonHALocator().setConnectionTTL(1000).setClientFailureCheckPeriod(100).setConsumerWindowSize(10 * 1024 * 1024).setCallTimeout(1000);
ClientSessionFactory sf = locator.createSessionFactory();
((ClientSessionFactoryImpl) sf).stopPingingAfterOne();
RemotingConnectionImpl remotingConnection = (RemotingConnectionImpl) sf.getConnection();
ClientSession session = sf.createSession(false, true, true, true);
session.createQueue(QUEUE, QUEUE, null, false);
final int numMessages = 10000;
final ClientConsumer consumer = session.createConsumer(QUEUE);
session.start();
final NettyConnection nettyConnection = (NettyConnection) remotingConnection.getTransportConnection();
Thread tReceive = new Thread() {
@Override
public void run() {
boolean first = true;
try {
while (!Thread.interrupted()) {
ClientMessage received = consumer.receive(500);
System.out.println("Received " + received);
if (first) {
first = false;
nettyConnection.getNettyChannel().config().setAutoRead(false);
}
if (received != null) {
received.acknowledge();
}
}
} catch (Throwable e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
}
};
tReceive.start();
Thread sender = new Thread() {
@Override
public void run() {
try (ServerLocator locator = createNettyNonHALocator();
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, true, true, true);
ClientProducer producer = session.createProducer(QUEUE)) {
for (int i = 0; i < numMessages; i++) {
ClientMessage message = createTextMessage(session, "m" + i);
producer.send(message);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
sender.start();
try {
long timeout = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < timeout && server.getSessions().size() != 2) {
Thread.sleep(10);
}
assertEquals(2, server.getSessions().size());
System.out.println("sessions = " + server.getSessions().size());
assertEquals(2, server.getConnectionCount());
timeout = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < timeout && server.getSessions().size() != 1) {
Thread.sleep(10);
}
System.out.println("Size = " + server.getConnectionCount());
System.out.println("sessions = " + server.getSessions().size());
if (server.getSessions().size() != 1) {
System.out.println(threadDump("Thread dump"));
fail("The cleanup wasn't able to finish cleaning the session. It's probably stuck, look at the thread dump generated by the test for more information");
}
sender.join();
timeout = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < timeout && server.getConnectionCount() != 0) {
Thread.sleep(10);
}
assertEquals(0, server.getConnectionCount());
} finally {
nettyConnection.getNettyChannel().config().setAutoRead(true);
tReceive.interrupt();
tReceive.join();
}
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueue.
@Test
@BMRules(rules = { @BMRule(name = "interrupt", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "xaEnd", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ActiveMQMessageHandlerTest.interrupt();") })
public void testSimpleMessageReceivedOnQueue() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
resourceAdapter = qResourceAdapter;
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
qResourceAdapter.start(ctx);
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setMaxSession(1);
spec.setCallTimeout(1000L);
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
CountDownLatch latch = new CountDownLatch(1);
XADummyEndpoint endpoint = new XADummyEndpoint(latch, false);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
qResourceAdapter.endpointActivation(endpointFactory, spec);
ClientSession session = locator.createSessionFactory().createSession();
ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("teststring");
clientProducer.send(message);
session.close();
latch.await(5, TimeUnit.SECONDS);
assertNotNull(endpoint.lastMessage);
assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
Binding binding = server.getPostOffice().getBinding(SimpleString.toSimpleString(MDBQUEUEPREFIXED));
assertEquals(1, getMessageCount(((Queue) binding.getBindable())));
server.stop();
server.start();
ClientSessionFactory factory = locator.createSessionFactory();
session = factory.createSession(true, true);
session.start();
ClientConsumer consumer = session.createConsumer(MDBQUEUEPREFIXED);
assertNotNull(consumer.receive(5000));
session.close();
}
Aggregations