use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class ActiveMQServerImpl method bindingQuery.
@Override
public BindingQueryResult bindingQuery(SimpleString address) throws Exception {
if (address == null) {
throw ActiveMQMessageBundle.BUNDLE.addressIsNull();
}
CompositeAddress addressKey = new CompositeAddress(address.toString());
String realAddress = addressKey.isFqqn() ? addressKey.getAddress() : addressKey.getQueueName();
AddressSettings addressSettings = getAddressSettingsRepository().getMatch(realAddress);
boolean autoCreateQeueus = addressSettings.isAutoCreateQueues();
boolean autoCreateAddresses = addressSettings.isAutoCreateAddresses();
boolean defaultPurgeOnNoConsumers = addressSettings.isDefaultPurgeOnNoConsumers();
int defaultMaxConsumers = addressSettings.getDefaultMaxConsumers();
boolean defaultExclusive = addressSettings.isDefaultExclusiveQueue();
boolean defaultLastValie = addressSettings.isDefaultLastValueQueue();
List<SimpleString> names = new ArrayList<>();
// make an exception for the management address (see HORNETQ-29)
ManagementService managementService = getManagementService();
SimpleString bindAddress = new SimpleString(realAddress);
if (managementService != null) {
if (bindAddress.equals(managementService.getManagementAddress())) {
return new BindingQueryResult(true, null, names, autoCreateQeueus, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers, defaultExclusive, defaultLastValie);
}
}
Bindings bindings = getPostOffice().getMatchingBindings(bindAddress);
for (Binding binding : bindings.getBindings()) {
if (binding.getType() == BindingType.LOCAL_QUEUE || binding.getType() == BindingType.REMOTE_QUEUE) {
if (addressKey.isFqqn()) {
names.add(new SimpleString(addressKey.getAddress()).concat(CompositeAddress.SEPARATOR).concat(binding.getUniqueName()));
} else {
names.add(binding.getUniqueName());
}
}
}
AddressInfo info = getAddressInfo(bindAddress);
return new BindingQueryResult(info != null, info, names, autoCreateQeueus, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers, defaultExclusive, defaultLastValie);
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class ActiveMQServerImpl method destroyQueue.
@Override
public void destroyQueue(final SimpleString queueName, final SecurityAuth session, final boolean checkConsumerCount, final boolean removeConsumers, final boolean autoDeleteAddress) throws Exception {
if (postOffice == null) {
return;
}
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeDestroyQueue(queueName, session, checkConsumerCount, removeConsumers, autoDeleteAddress) : null);
addressSettingsRepository.clearCache();
Binding binding = postOffice.getBinding(queueName);
if (binding == null) {
throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(queueName);
}
SimpleString address = binding.getAddress();
Queue queue = (Queue) binding.getBindable();
// This check is only valid if checkConsumerCount == true
if (checkConsumerCount && queue.getConsumerCount() != 0) {
throw ActiveMQMessageBundle.BUNDLE.cannotDeleteQueue(queue.getName(), queueName, binding.getClass().getName());
}
if (session != null) {
if (queue.isDurable()) {
// make sure the user has privileges to delete this queue
securityStore.check(address, queueName, CheckType.DELETE_DURABLE_QUEUE, session);
} else {
securityStore.check(address, queueName, CheckType.DELETE_NON_DURABLE_QUEUE, session);
}
}
queue.deleteQueue(removeConsumers);
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterDestroyQueue(queue, address, session, checkConsumerCount, removeConsumers, autoDeleteAddress) : null);
AddressInfo addressInfo = getAddressInfo(address);
if (autoDeleteAddress && postOffice != null && addressInfo != null && addressInfo.isAutoCreated()) {
try {
removeAddressInfo(address, session);
} catch (ActiveMQDeleteAddressException e) {
// Could be thrown if the address has bindings or is not deletable.
}
}
callPostQueueDeletionCallbacks(address, queueName);
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class ConsumerWindowSizeTest method testNoWindowRoundRobin.
private void testNoWindowRoundRobin(final boolean largeMessages) throws Exception {
ActiveMQServer server = createServer(false, isNetty());
ClientSession sessionA = null;
ClientSession sessionB = null;
try {
final int numberOfMessages = 100;
server.start();
locator.setConsumerWindowSize(-1);
if (largeMessages) {
locator.setMinLargeMessageSize(100);
}
ClientSessionFactory sf = createSessionFactory(locator);
sessionA = sf.createSession(false, true, true);
SimpleString ADDRESS = new SimpleString("some-queue");
sessionA.createQueue(ADDRESS, ADDRESS, true);
sessionB = sf.createSession(false, true, true);
sessionA.start();
sessionB.start();
ClientConsumerInternal consA = (ClientConsumerInternal) sessionA.createConsumer(ADDRESS);
ClientConsumerInternal consB = (ClientConsumerInternal) sessionB.createConsumer(ADDRESS);
{
// We can only guarantee round robing with WindowSize = -1, after the ServerConsumer object received
// SessionConsumerFlowCreditMessage(-1)
// Since that is done asynchronously we verify that the information was received before we proceed on
// sending messages or else the distribution won't be
// even as expected by the test
Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
Assert.assertEquals(1, bindings.getBindings().size());
for (Binding binding : bindings.getBindings()) {
Collection<Consumer> consumers = ((QueueBinding) binding).getQueue().getConsumers();
for (Consumer consumer : consumers) {
ServerConsumerImpl consumerImpl = (ServerConsumerImpl) consumer;
long timeout = System.currentTimeMillis() + 5000;
while (timeout > System.currentTimeMillis() && consumerImpl.getAvailableCredits() != null) {
Thread.sleep(10);
}
Assert.assertNull(consumerImpl.getAvailableCredits());
}
}
}
ClientProducer prod = sessionA.createProducer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage msg = createTextMessage(sessionA, "Msg" + i);
if (largeMessages) {
msg.getBodyBuffer().writeBytes(new byte[600]);
}
prod.send(msg);
}
long timeout = System.currentTimeMillis() + TIMEOUT * 1000;
boolean foundA = false;
boolean foundB = false;
do {
foundA = consA.getBufferSize() == numberOfMessages / 2;
foundB = consB.getBufferSize() == numberOfMessages / 2;
Thread.sleep(10);
} while ((!foundA || !foundB) && System.currentTimeMillis() < timeout);
Assert.assertTrue("ConsumerA didn't receive the expected number of messages on buffer (consA=" + consA.getBufferSize() + ", consB=" + consB.getBufferSize() + ") foundA = " + foundA + " foundB = " + foundB, foundA);
Assert.assertTrue("ConsumerB didn't receive the expected number of messages on buffer (consA=" + consA.getBufferSize() + ", consB=" + consB.getBufferSize() + ") foundA = " + foundA + " foundB = " + foundB, foundB);
} finally {
try {
if (sessionA != null) {
sessionA.close();
}
if (sessionB != null) {
sessionB.close();
}
} catch (Exception ignored) {
}
}
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class JMSTopicConsumerTest method testTemporarySubscriptionDeleted.
@Test(timeout = 60000)
public void testTemporarySubscriptionDeleted() throws Exception {
Connection connection = createConnection();
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber myNonDurSub = session.createSubscriber(topic);
assertNotNull(myNonDurSub);
Bindings bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(2, bindingsForAddress.getBindings().size());
session.close();
final CountDownLatch latch = new CountDownLatch(1);
server.getRemotingService().getConnections().iterator().next().addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
connection.close();
latch.await(5, TimeUnit.SECONDS);
bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(1, bindingsForAddress.getBindings().size());
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.
the class TopicCleanupTest method testWildcardSubscriber.
@Test
public void testWildcardSubscriber() throws Exception {
ActiveMQTopic topic = (ActiveMQTopic) createTopic("topic.A");
Connection conn = cf.createConnection();
conn.start();
try {
Session consumerStarSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumerStar = consumerStarSession.createConsumer(ActiveMQJMSClient.createTopic("topic.*"));
Session consumerASession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumerA = consumerASession.createConsumer(topic);
Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producerA = producerSession.createProducer(topic);
TextMessage msg1 = producerSession.createTextMessage("text");
producerA.send(msg1);
consumerStar.close();
consumerA.close();
producerA.send(msg1);
conn.close();
boolean foundStrayRoutingBinding = false;
Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(topic.getAddress()));
Map<SimpleString, List<Binding>> routingNames = ((BindingsImpl) bindings).getRoutingNameBindingMap();
for (SimpleString key : routingNames.keySet()) {
if (!key.toString().equals(topic.getAddress())) {
foundStrayRoutingBinding = true;
assertEquals(0, ((LocalQueueBinding) routingNames.get(key).get(0)).getQueue().getMessageCount());
}
}
assertFalse(foundStrayRoutingBinding);
} finally {
jmsServer.stop();
jmsServer.start();
try {
conn.close();
} catch (Throwable igonred) {
}
}
}
Aggregations