use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.
the class AmqpFullyQualifiedNameTest method testTopic.
@Test(timeout = 60000)
public // however we can test query functionality
void testTopic() throws Exception {
SimpleString queueName = new SimpleString("someAddress");
server.createQueue(multicastAddress, RoutingType.MULTICAST, queueName, null, false, false);
Connection connection = createConnection(false);
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic fqqn = session.createTopic(multicastAddress.toString() + "::" + queueName);
MessageConsumer consumer1 = session.createConsumer(fqqn);
MessageConsumer consumer2 = session.createConsumer(fqqn);
Topic topic = session.createTopic(multicastAddress.toString());
MessageProducer producer = session.createProducer(topic);
producer.send(session.createMessage());
// each consumer receives one
Message m = consumer1.receive(2000);
assertNotNull(m);
// Subscribing to FQQN is akin to shared subscription
m = consumer2.receive(2000);
assertNull(m);
Bindings bindings = server.getPostOffice().getBindingsForAddress(multicastAddress);
for (Binding b : bindings.getBindings()) {
System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding) b).getQueue().getDeliveringMessages());
SimpleString qName = b.getUniqueName();
// do FQQN query
QueueQueryResult result = server.queueQuery(CompositeAddress.toFullQN(multicastAddress, qName));
assertTrue(result.isExists());
assertEquals(result.getName(), CompositeAddress.toFullQN(multicastAddress, qName));
// do qname query
result = server.queueQuery(qName);
assertTrue(result.isExists());
assertEquals(result.getName(), qName);
}
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.
the class AmqpFullyQualifiedNameTest method testQueue.
@Test
public void testQueue() throws Exception {
server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ2, null, true, false, -1, false, true);
server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ3, null, true, false, -1, false, true);
Connection connection = createConnection();
try {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue q1 = session.createQueue(CompositeAddress.toFullQN(anycastAddress, anycastQ1).toString());
javax.jms.Queue q2 = session.createQueue(CompositeAddress.toFullQN(anycastAddress, anycastQ2).toString());
javax.jms.Queue q3 = session.createQueue(CompositeAddress.toFullQN(anycastAddress, anycastQ3).toString());
// send 3 messages to anycastAddress
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession coreSession = cf.createSession();
// send 3 messages
ClientProducer coreProducer = coreSession.createProducer(anycastAddress);
sendMessages(coreSession, coreProducer, 3);
MessageConsumer consumer1 = session.createConsumer(q1);
MessageConsumer consumer2 = session.createConsumer(q2);
MessageConsumer consumer3 = session.createConsumer(q3);
// each consumer receives one
assertNotNull(consumer1.receive(2000));
assertNotNull(consumer2.receive(2000));
assertNotNull(consumer3.receive(2000));
Queue queue1 = getProxyToQueue(anycastQ1.toString());
Wait.assertEquals(0, queue1::getMessageCount);
Queue queue2 = getProxyToQueue(anycastQ2.toString());
Wait.assertEquals(0, queue2::getMessageCount);
Queue queue3 = getProxyToQueue(anycastQ3.toString());
Wait.assertEquals(0, queue3::getMessageCount);
connection.close();
// queues are empty now
for (SimpleString q : new SimpleString[] { anycastQ1, anycastQ2, anycastQ3 }) {
// FQQN query
final QueueQueryResult query = server.queueQuery(CompositeAddress.toFullQN(anycastAddress, q));
assertTrue(query.isExists());
assertEquals(anycastAddress, query.getAddress());
assertEquals(CompositeAddress.toFullQN(anycastAddress, q), query.getName());
assertEquals("Message not consumed", 0, query.getMessageCount());
// try query again using qName
QueueQueryResult qNameQuery = server.queueQuery(q);
assertEquals(q, qNameQuery.getName());
}
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.
the class QueueCommandTest method testUpdateCoreQueueCannotLowerMaxConsumers.
@Test
public void testUpdateCoreQueueCannotLowerMaxConsumers() throws Exception {
final String queueName = "updateQueue";
final SimpleString queueNameString = new SimpleString(queueName);
final String addressName = "address";
final SimpleString addressSimpleString = new SimpleString(addressName);
final int oldMaxConsumers = 2;
final RoutingType oldRoutingType = RoutingType.MULTICAST;
final boolean oldPurgeOnNoConsumers = false;
final AddressInfo addressInfo = new AddressInfo(addressSimpleString, oldRoutingType);
server.addAddressInfo(addressInfo);
server.createQueue(addressSimpleString, oldRoutingType, queueNameString, null, true, false, oldMaxConsumers, oldPurgeOnNoConsumers, false);
server.locateQueue(queueNameString).addConsumer(new DummyServerConsumer());
server.locateQueue(queueNameString).addConsumer(new DummyServerConsumer());
final int newMaxConsumers = 1;
final UpdateQueue updateQueue = new UpdateQueue();
updateQueue.setName(queueName);
updateQueue.setMaxConsumers(newMaxConsumers);
updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
checkExecutionFailure(updateQueue, "AMQ119210");
final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
assertEquals("maxConsumers", oldMaxConsumers, queueQueryResult.getMaxConsumers());
}
use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.
the class FullQualifiedQueueTest method testMulticastQueues.
@Test
public void testMulticastQueues() throws Exception {
server.createQueue(multicastAddress, RoutingType.MULTICAST, multicastQ1, null, true, false, -1, false, true);
server.createQueue(multicastAddress, RoutingType.MULTICAST, multicastQ2, null, true, false, -1, false, true);
server.createQueue(multicastAddress, RoutingType.MULTICAST, multicastQ3, null, true, false, -1, false, true);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession session = cf.createSession();
session.start();
// send 3 messages
ClientProducer producer = session.createProducer(multicastAddress);
sendMessages(session, producer, 1);
ClientConsumer consumer1 = session.createConsumer(toFullQN(multicastAddress, multicastQ1));
ClientConsumer consumer2 = session.createConsumer(toFullQN(multicastAddress, multicastQ2));
ClientConsumer consumer3 = session.createConsumer(toFullQN(multicastAddress, multicastQ3));
session.start();
// each consumer receives one
ClientMessage m = consumer1.receive(2000);
assertNotNull(m);
m.acknowledge();
m = consumer2.receive(2000);
assertNotNull(m);
m.acknowledge();
m = consumer3.receive(2000);
assertNotNull(m);
m.acknowledge();
session.commit();
// queues are empty now
for (SimpleString q : new SimpleString[] { multicastQ1, multicastQ2, multicastQ3 }) {
QueueQueryResult query = server.queueQuery(toFullQN(multicastAddress, q));
assertTrue(query.isExists());
assertEquals(multicastAddress, query.getAddress());
assertEquals(toFullQN(multicastAddress, q), query.getName());
assertEquals(0, query.getMessageCount());
}
}
use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.
the class AMQSession method checkAutoCreateQueue.
private boolean checkAutoCreateQueue(SimpleString queueName, boolean isTemporary) throws Exception {
boolean hasQueue = true;
if (!connection.containsKnownDestination(queueName)) {
BindingQueryResult bindingQuery = server.bindingQuery(queueName);
QueueQueryResult queueBinding = server.queueQuery(queueName);
try {
if (!queueBinding.isExists()) {
if (bindingQuery.isAutoCreateQueues()) {
SimpleString queueNameToUse = queueName;
SimpleString addressToUse = queueName;
RoutingType routingTypeToUse = RoutingType.ANYCAST;
if (CompositeAddress.isFullyQualified(queueName.toString())) {
CompositeAddress compositeAddress = CompositeAddress.getQueueName(queueName.toString());
addressToUse = new SimpleString(compositeAddress.getAddress());
queueNameToUse = new SimpleString(compositeAddress.getQueueName());
if (bindingQuery.getAddressInfo() != null) {
routingTypeToUse = bindingQuery.getAddressInfo().getRoutingType();
} else {
AddressSettings as = server.getAddressSettingsRepository().getMatch(addressToUse.toString());
routingTypeToUse = as.getDefaultAddressRoutingType();
}
}
coreSession.createQueue(addressToUse, queueNameToUse, routingTypeToUse, null, isTemporary, true);
connection.addKnownDestination(queueName);
} else {
hasQueue = false;
}
}
} catch (ActiveMQQueueExistsException e) {
// In case another thread created the queue before us but after we did the binding query
hasQueue = true;
}
}
return hasQueue;
}
Aggregations