use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class AddressControlImpl method getNumberOfMessages.
@Override
public long getNumberOfMessages() throws Exception {
clearIO();
long totalMsgs = 0;
try {
Bindings bindings = postOffice.getBindingsForAddress(addressInfo.getName());
for (Binding binding : bindings.getBindings()) {
if (binding instanceof QueueBinding) {
totalMsgs += ((QueueBinding) binding).getQueue().getMessageCount();
}
}
return totalMsgs;
} catch (Throwable t) {
throw new IllegalStateException(t.getMessage());
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class PredefinedQueueTest method testDeploySameNames.
@Test
public void testDeploySameNames() throws Exception {
final String testAddress = "testAddress";
final String queueName1 = "queue1";
final String queueName2 = "queue2";
CoreQueueConfiguration queue1 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName1);
CoreQueueConfiguration queue2 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName2);
configuration.addQueueConfiguration(queue1).addQueueConfiguration(queue2);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(configuration, false));
server.start();
Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(testAddress));
Assert.assertEquals(2, bindings.getBindings().size());
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, true, true));
session.start();
ClientProducer producer = addClientProducer(session.createProducer(new SimpleString(testAddress)));
ClientConsumer consumer1 = addClientConsumer(session.createConsumer(queueName1));
ClientConsumer consumer2 = addClientConsumer(session.createConsumer(queueName2));
final int numMessages = 10;
final SimpleString propKey = new SimpleString("testkey");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
message.putIntProperty(propKey, i);
producer.send(message);
}
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(200);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
message = consumer2.receive(200);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
Assert.assertNull(consumer2.receiveImmediate());
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class QueueImpl method expire.
private void expire(final Transaction tx, final MessageReference ref) throws Exception {
SimpleString expiryAddress = addressSettingsRepository.getMatch(address.toString()).getExpiryAddress();
if (expiryAddress != null) {
Bindings bindingList = postOffice.getBindingsForAddress(expiryAddress);
if (bindingList.getBindings().isEmpty()) {
ActiveMQServerLogger.LOGGER.errorExpiringReferencesNoBindings(expiryAddress);
acknowledge(tx, ref, AckReason.EXPIRED);
} else {
move(expiryAddress, tx, ref, true, true);
}
} else {
if (!printErrorExpiring) {
printErrorExpiring = true;
// print this only once
ActiveMQServerLogger.LOGGER.errorExpiringReferencesNoQueue(name);
}
acknowledge(tx, ref, AckReason.EXPIRED);
}
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class FQQNOpenWireTest method testTopic.
@Test
public // however we can test query functionality
void testTopic() throws Exception {
Connection connection = factory.createConnection();
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(multicastAddress.toString());
MessageConsumer consumer1 = session.createConsumer(topic);
MessageConsumer consumer2 = session.createConsumer(topic);
MessageConsumer consumer3 = session.createConsumer(topic);
MessageProducer producer = session.createProducer(topic);
producer.send(session.createMessage());
// each consumer receives one
Message m = consumer1.receive(2000);
assertNotNull(m);
m = consumer2.receive(2000);
assertNotNull(m);
m = consumer3.receive(2000);
assertNotNull(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.postoffice.Bindings in project activemq-artemis by apache.
the class PagingOrderTest method testPageCounter.
@Test
public void testPageCounter() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 500;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
Queue q1 = server.createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true, false);
Queue q2 = server.createQueue(ADDRESS, RoutingType.MULTICAST, new SimpleString("inactive"), null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
final AtomicInteger errors = new AtomicInteger(0);
Thread t1 = new Thread() {
@Override
public void run() {
try {
ServerLocator sl = createInVMNonHALocator();
ClientSessionFactory sf = sl.createSessionFactory();
ClientSession sess = sf.createSession(true, true, 0);
sess.start();
ClientConsumer cons = sess.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage msg = cons.receive(5000);
assertNotNull(msg);
assertEquals(i, msg.getIntProperty("id").intValue());
msg.acknowledge();
}
assertNull(cons.receiveImmediate());
sess.close();
sl.close();
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
t1.start();
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 20 == 0) {
session.commit();
}
}
session.commit();
t1.join();
assertEquals(0, errors.get());
assertEquals(numberOfMessages, getMessageCount(q2));
assertEquals(numberOfMessages, getMessagesAdded(q2));
assertEquals(0, getMessageCount(q1));
assertEquals(numberOfMessages, getMessagesAdded(q1));
session.close();
sf.close();
locator.close();
server.stop();
server.start();
Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
q1 = null;
q2 = null;
for (Binding bind : bindings.getBindings()) {
if (bind instanceof LocalQueueBinding) {
LocalQueueBinding qb = (LocalQueueBinding) bind;
if (qb.getQueue().getName().equals(ADDRESS)) {
q1 = qb.getQueue();
}
if (qb.getQueue().getName().equals(new SimpleString("inactive"))) {
q2 = qb.getQueue();
}
}
}
assertNotNull(q1);
assertNotNull(q2);
assertEquals("q2 msg count", numberOfMessages, getMessageCount(q2));
assertEquals("q2 msgs added", numberOfMessages, getMessagesAdded(q2));
assertEquals("q1 msg count", 0, getMessageCount(q1));
// 0, since nothing was sent to the queue after the server was restarted
assertEquals("q1 msgs added", 0, getMessagesAdded(q1));
}
Aggregations