use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class AddressingTest method testAnycastRoutingRoundRobin.
@Test
public void testAnycastRoutingRoundRobin() throws Exception {
SimpleString address = new SimpleString("test.address");
AddressInfo addressInfo = new AddressInfo(address);
addressInfo.addRoutingType(RoutingType.ANYCAST);
server.addOrUpdateAddressInfo(addressInfo);
Queue q1 = server.createQueue(address, RoutingType.ANYCAST, address.concat(".1"), null, true, false, Queue.MAX_CONSUMERS_UNLIMITED, false, true);
Queue q2 = server.createQueue(address, RoutingType.ANYCAST, address.concat(".2"), null, true, false, Queue.MAX_CONSUMERS_UNLIMITED, false, true);
Queue q3 = server.createQueue(address, RoutingType.ANYCAST, address.concat(".3"), null, true, false, Queue.MAX_CONSUMERS_UNLIMITED, false, true);
ClientSession session = sessionFactory.createSession();
session.start();
ClientProducer producer = session.createProducer(address);
ClientConsumer consumer1 = session.createConsumer(q1.getName());
ClientConsumer consumer2 = session.createConsumer(q2.getName());
ClientConsumer consumer3 = session.createConsumer(q3.getName());
List<ClientConsumer> consumers = new ArrayList<>(Arrays.asList(new ClientConsumer[] { consumer1, consumer2, consumer3 }));
List<String> messages = new ArrayList<>();
messages.add("Message1");
messages.add("Message2");
messages.add("Message3");
ClientMessage clientMessage;
for (String message : messages) {
clientMessage = session.createMessage(true);
clientMessage.getBodyBuffer().writeString(message);
producer.send(clientMessage);
}
String m;
for (ClientConsumer consumer : consumers) {
clientMessage = consumer.receive(1000);
m = clientMessage.getBodyBuffer().readString();
messages.remove(m);
}
assertTrue(messages.isEmpty());
// Check we don't receive more messages
int count = 0;
for (ClientConsumer consumer : consumers) {
count = (consumer.receive(1000) == null) ? count : count + 1;
}
assertEquals(0, count);
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class AmqpClientTestSupport method createAddressAndQueues.
protected void createAddressAndQueues(ActiveMQServer server) throws Exception {
// Default Queue
server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getQueueName()), RoutingType.ANYCAST));
server.createQueue(SimpleString.toSimpleString(getQueueName()), RoutingType.ANYCAST, SimpleString.toSimpleString(getQueueName()), null, true, false, -1, false, true);
// Default DLQ
server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getDeadLetterAddress()), RoutingType.ANYCAST));
server.createQueue(SimpleString.toSimpleString(getDeadLetterAddress()), RoutingType.ANYCAST, SimpleString.toSimpleString(getDeadLetterAddress()), null, true, false, -1, false, true);
// Default Topic
server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getTopicName()), RoutingType.MULTICAST));
server.createQueue(SimpleString.toSimpleString(getTopicName()), RoutingType.MULTICAST, SimpleString.toSimpleString(getTopicName()), null, true, false, -1, false, true);
// Additional Test Queues
for (int i = 0; i < getPrecreatedQueueSize(); ++i) {
server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getQueueName(i)), RoutingType.ANYCAST));
server.createQueue(SimpleString.toSimpleString(getQueueName(i)), RoutingType.ANYCAST, SimpleString.toSimpleString(getQueueName(i)), null, true, false, -1, false, true);
}
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class AmqpPurgeOnNoConsumersTest method testQueueReceiverReadMessage.
@Test(timeout = 60000)
public void testQueueReceiverReadMessage() throws Exception {
AmqpConnection connection = null;
String queue = "purgeQueue";
SimpleString ssQueue = new SimpleString(queue);
server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
AmqpClient client = createAmqpClient();
connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
final AmqpReceiver receiver = session.createReceiver(queue);
QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
assertEquals(0, queueView.getMessageCount());
sendMessages(queue, 5, null, true);
Wait.assertEquals(5, queueView::getMessageCount);
receiver.flow(5);
for (int i = 0; i < 4; i++) {
try {
AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
receive.accept();
assertNotNull(receive);
} catch (Exception e) {
e.printStackTrace();
}
}
try {
receiver.close();
} catch (IOException e) {
e.printStackTrace();
}
Wait.assertEquals(0, queueView::getMessageCount);
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
connection.close();
server.stop();
server.start();
queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0, queueView.getMessageCount());
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class AmqpPurgeOnNoConsumersTest method testPurgeQueueCoreRollback.
// I'm adding the core test here to compare semantics between AMQP and core on this test.
@Test(timeout = 60000)
public void testPurgeQueueCoreRollback() throws Exception {
String queue = "purgeQueue";
SimpleString ssQueue = new SimpleString(queue);
server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:5672");
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(session.createQueue("purgeQueue"));
javax.jms.Queue jmsQueue = session.createQueue(queue);
MessageConsumer consumer = session.createConsumer(jmsQueue);
for (int i = 0; i < 10; i++) {
Message message = session.createTextMessage("hello " + i);
producer.send(message);
}
session.commit();
QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
Wait.assertEquals(10, queueView::getMessageCount);
connection.start();
for (int i = 0; i < 10; i++) {
TextMessage txt = (TextMessage) consumer.receive(1000);
assertNotNull(txt);
assertEquals("hello " + i, txt.getText());
}
consumer.close();
session.rollback();
connection.close();
Wait.assertEquals(0, queueView::getMessageCount);
server.stop();
server.start();
queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0, queueView.getMessageCount());
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class AmqpReceiverTest method testClientIdIsSetInSubscriptionList.
@Test(timeout = 60000)
public void testClientIdIsSetInSubscriptionList() throws Exception {
server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("mytopic"), RoutingType.ANYCAST));
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
connection.setContainerId("testClient");
connection.connect();
try {
AmqpSession session = connection.createSession();
Source source = new Source();
source.setDurable(TerminusDurability.UNSETTLED_STATE);
source.setCapabilities(Symbol.getSymbol("topic"));
source.setAddress("mytopic");
session.createReceiver(source, "testSub");
SimpleString fo = new SimpleString("testClient.testSub:mytopic");
assertNotNull(server.locateQueue(fo));
} catch (Exception e) {
e.printStackTrace();
} finally {
connection.close();
}
}
Aggregations