use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class AddressSettingsTest method testOverrideHierarchyWithDLA.
@Test
public void testOverrideHierarchyWithDLA() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1);
AddressSettings addressSettings2 = new AddressSettings().setMaxDeliveryAttempts(1);
AddressSettings addressSettings3 = new AddressSettings().setDeadLetterAddress(dlaC).setMaxDeliveryAttempts(1);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(addressA2.toString(), addressSettings);
repos.addMatch("add.*", addressSettings2);
repos.addMatch("#", addressSettings3);
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, false);
session.createQueue(addressA2, queueA, false);
session.createQueue(addressB2, queueB, false);
session.createQueue(addressC, queueC, false);
session.createQueue(dlaA, dlqA, false);
session.createQueue(dlaB, dlqB, false);
session.createQueue(dlaC, dlqC, false);
ClientSession sendSession = sf.createSession(false, true, true);
ClientMessage cm = sendSession.createMessage(true);
ClientMessage cm2 = sendSession.createMessage(true);
ClientMessage cm3 = sendSession.createMessage(true);
ClientProducer cp1 = sendSession.createProducer(addressA2);
ClientProducer cp2 = sendSession.createProducer(addressB2);
ClientProducer cp3 = sendSession.createProducer(addressC);
cp1.send(cm);
cp2.send(cm2);
cp3.send(cm3);
ClientConsumer dlqCrec = session.createConsumer(dlqC);
ClientConsumer cc1 = session.createConsumer(queueA);
ClientConsumer cc2 = session.createConsumer(queueB);
ClientConsumer cc3 = session.createConsumer(queueC);
session.start();
ClientMessage message = cc1.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
message = cc2.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
message = cc3.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
session.rollback();
cc1.close();
cc2.close();
cc3.close();
message = dlqCrec.receive(5000);
Assert.assertNotNull(message);
message = dlqCrec.receive(5000);
Assert.assertNotNull(message);
message = dlqCrec.receive(5000);
Assert.assertNotNull(message);
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class AddressSettingsTest method test2LevelHierarchyWithDLA.
@Test
public void test2LevelHierarchyWithDLA() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dlaA).setMaxDeliveryAttempts(1);
AddressSettings addressSettings2 = new AddressSettings().setDeadLetterAddress(dlaB).setMaxDeliveryAttempts(1);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(addressA.toString(), addressSettings);
repos.addMatch("#", addressSettings2);
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, false);
session.createQueue(addressA, queueA, false);
session.createQueue(addressB, queueB, false);
session.createQueue(dlaA, dlqA, false);
session.createQueue(dlaB, dlqB, false);
ClientSession sendSession = sf.createSession(false, true, true);
ClientMessage cm = sendSession.createMessage(true);
cm.getBodyBuffer().writeString("A");
ClientMessage cm2 = sendSession.createMessage(true);
cm2.getBodyBuffer().writeString("B");
ClientProducer cp1 = sendSession.createProducer(addressA);
ClientProducer cp2 = sendSession.createProducer(addressB);
cp1.send(cm);
cp2.send(cm2);
ClientConsumer dlqARec = session.createConsumer(dlqA);
ClientConsumer dlqBrec = session.createConsumer(dlqB);
ClientConsumer cc1 = session.createConsumer(queueA);
ClientConsumer cc2 = session.createConsumer(queueB);
session.start();
ClientMessage message = cc1.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
message = cc2.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
session.rollback();
cc1.close();
cc2.close();
message = dlqARec.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("A", message.getBodyBuffer().readString());
message = dlqBrec.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("B", message.getBodyBuffer().readString());
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class AddressSettingsTest method testSimpleHierarchyWithDLA.
@Test
public void testSimpleHierarchyWithDLA() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dlaA).setMaxDeliveryAttempts(1);
AddressSettings addressSettings2 = new AddressSettings().setDeadLetterAddress(dlaB).setMaxDeliveryAttempts(1);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(addressA.toString(), addressSettings);
repos.addMatch(addressB.toString(), addressSettings2);
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, false);
session.createQueue(addressA, queueA, false);
session.createQueue(addressB, queueB, false);
session.createQueue(dlaA, dlqA, false);
session.createQueue(dlaB, dlqB, false);
ClientSession sendSession = sf.createSession(false, true, true);
ClientMessage cm = sendSession.createMessage(true);
cm.getBodyBuffer().writeString("A");
ClientMessage cm2 = sendSession.createMessage(true);
cm2.getBodyBuffer().writeString("B");
ClientProducer cp1 = sendSession.createProducer(addressA);
ClientProducer cp2 = sendSession.createProducer(addressB);
cp1.send(cm);
cp2.send(cm2);
ClientConsumer dlqARec = session.createConsumer(dlqA);
ClientConsumer dlqBrec = session.createConsumer(dlqB);
ClientConsumer cc1 = session.createConsumer(queueA);
ClientConsumer cc2 = session.createConsumer(queueB);
session.start();
ClientMessage message = cc1.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
message = cc2.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
session.rollback();
cc1.close();
cc2.close();
message = dlqARec.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("A", message.getBodyBuffer().readString());
message = dlqBrec.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("B", message.getBodyBuffer().readString());
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class CoreClientTest method testCoreClient.
private void testCoreClient(final boolean netty, ServerLocator serverLocator) throws Exception {
final SimpleString QUEUE = new SimpleString("CoreClientTestQueue");
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultConfig(netty), false));
server.start();
ServerLocator locator = serverLocator == null ? createNonHALocator(netty) : serverLocator;
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(QUEUE, QUEUE, null, false);
ClientProducer producer = session.createProducer(QUEUE);
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putStringProperty("foo", "bar");
// One way around the setting destination problem is as follows -
// Remove destination as an attribute from client producer.
// The destination always has to be set explicitly before sending a message
message.setAddress(QUEUE);
message.getBodyBuffer().writeString("testINVMCoreClient");
producer.send(message);
}
CoreClientTest.log.info("sent messages");
ClientConsumer consumer = session.createConsumer(QUEUE);
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message2 = consumer.receive();
ActiveMQBuffer buffer = message2.getBodyBuffer();
Assert.assertEquals("testINVMCoreClient", buffer.readString());
message2.acknowledge();
}
sf.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class DeliveryOrderTest method testSendDeliveryOrderOnCommit.
@Test
public void testSendDeliveryOrderOnCommit() throws Exception {
ClientSession sendSession = cf.createSession(false, false, true);
ClientProducer cp = sendSession.createProducer(addressA);
int numMessages = 1000;
sendSession.createQueue(addressA, queueA, false);
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = sendSession.createMessage(false);
cm.getBodyBuffer().writeInt(i);
cp.send(cm);
if (i % 10 == 0) {
sendSession.commit();
}
sendSession.commit();
}
ClientConsumer c = sendSession.createConsumer(queueA);
sendSession.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = c.receive(5000);
Assert.assertNotNull(cm);
Assert.assertEquals(i, cm.getBodyBuffer().readInt());
}
sendSession.close();
}
Aggregations