use of org.apache.activemq.artemis.core.postoffice.QueueBinding 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.QueueBinding in project activemq-artemis by apache.
the class QueueConfigRestartTest method testQueueConfigLastValueAndRestart.
@Test
public void testQueueConfigLastValueAndRestart() throws Exception {
ActiveMQServer server = createServer(true);
server.start();
SimpleString address = new SimpleString("test.address");
SimpleString queue = new SimpleString("test.queue");
server.createQueue(address, RoutingType.MULTICAST, queue, null, null, true, false, false, false, false, 10, true, false, true, true);
QueueBinding queueBinding1 = (QueueBinding) server.getPostOffice().getBinding(queue);
Assert.assertTrue(queueBinding1.getQueue().isLastValue());
server.stop();
server.start();
QueueBinding queueBinding2 = (QueueBinding) server.getPostOffice().getBinding(queue);
Assert.assertTrue(queueBinding2.getQueue().isLastValue());
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class QueueConfigRestartTest method testQueueConfigPurgeOnNoConsumerAndRestart.
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testQueueConfigPurgeOnNoConsumerAndRestart() throws Exception {
ActiveMQServer server = createServer(true);
server.start();
SimpleString address = new SimpleString("test.address");
SimpleString queue = new SimpleString("test.queue");
server.createQueue(address, RoutingType.MULTICAST, queue, null, null, true, false, false, 10, true, true);
QueueBinding queueBinding1 = (QueueBinding) server.getPostOffice().getBinding(queue);
Assert.assertTrue(queueBinding1.getQueue().isPurgeOnNoConsumers());
server.stop();
server.start();
QueueBinding queueBinding2 = (QueueBinding) server.getPostOffice().getBinding(queue);
Assert.assertTrue(queueBinding2.getQueue().isPurgeOnNoConsumers());
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class ServerSessionImpl method createConsumer.
@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
final SimpleString unPrefixedQueueName = removePrefix(queueName);
Binding binding = postOffice.getBinding(unPrefixedQueueName);
if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
}
SimpleString address = removePrefix(binding.getAddress());
if (browseOnly) {
try {
securityCheck(address, queueName, CheckType.BROWSE, this);
} catch (Exception e) {
securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
}
} else {
try {
securityCheck(address, queueName, CheckType.CONSUME, this);
} catch (Exception e) {
securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
}
}
Filter filter = FilterImpl.createFilter(filterString);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
}
ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
consumers.put(consumer.getID(), consumer);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
}
if (!browseOnly) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
Queue theQueue = (Queue) binding.getBindable();
props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
// HORNETQ-946
props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
if (filterString != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
}
Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
if (logger.isDebugEnabled()) {
logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
}
managementService.sendNotification(notification);
}
return consumer;
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class ActiveMQTestBase method getMessageCount.
/**
* @param address
* @param postOffice
* @return
* @throws Exception
*/
protected int getMessageCount(final PostOffice postOffice, final String address) throws Exception {
int messageCount = 0;
List<QueueBinding> bindings = getLocalQueueBindings(postOffice, address);
for (QueueBinding qBinding : bindings) {
qBinding.getQueue().flushExecutor();
messageCount += getMessageCount(qBinding.getQueue());
}
return messageCount;
}
Aggregations