Search in sources :

Example 21 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class JournalPendingMessageTest method getQueues.

protected List<Queue> getQueues(final String address) throws Exception {
    final List<Queue> queues = new ArrayList<>();
    for (Binding binding : server.getPostOffice().getDirectBindings(SimpleString.toSimpleString(address)).getBindings()) {
        if (binding.getType() == BindingType.LOCAL_QUEUE) {
            LocalQueueBinding queueBinding = (LocalQueueBinding) binding;
            queues.add(queueBinding.getQueue());
        }
    }
    return queues;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ArrayList(java.util.ArrayList) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 22 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method closeConsumerConnectionsForAddress.

@Override
public boolean closeConsumerConnectionsForAddress(final String address) {
    boolean closed = false;
    checkStarted();
    clearIO();
    try {
        for (Binding binding : postOffice.getMatchingBindings(SimpleString.toSimpleString(address)).getBindings()) {
            if (binding instanceof LocalQueueBinding) {
                Queue queue = ((LocalQueueBinding) binding).getQueue();
                for (Consumer consumer : queue.getConsumers()) {
                    if (consumer instanceof ServerConsumer) {
                        ServerConsumer serverConsumer = (ServerConsumer) consumer;
                        RemotingConnection connection = null;
                        for (RemotingConnection potentialConnection : remotingService.getConnections()) {
                            if (potentialConnection.getID().toString().equals(serverConsumer.getConnectionID())) {
                                connection = potentialConnection;
                            }
                        }
                        if (connection != null) {
                            remotingService.removeConnection(connection.getID());
                            connection.fail(ActiveMQMessageBundle.BUNDLE.consumerConnectionsClosedByManagement(address));
                            closed = true;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.failedToCloseConsumerConnectionsForAddress(address, e);
    } finally {
        blockOnIO();
    }
    return closed;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Consumer(org.apache.activemq.artemis.core.server.Consumer) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ActiveMQAddressDoesNotExistException(org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException)

Example 23 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class QueueImplTest method testTotalIteratorOrder.

@Test
public void testTotalIteratorOrder() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), true));
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    ClientSessionFactory factory = createSessionFactory(locator);
    ClientSession session = addClientSession(factory.createSession(false, true, true));
    session.createQueue(MY_ADDRESS, MY_QUEUE, true);
    ClientProducer producer = addClientProducer(session.createProducer(MY_ADDRESS));
    for (int i = 0; i < 50; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeBytes(new byte[1024]);
        message.putIntProperty("order", i);
        producer.send(message);
    }
    producer.close();
    session.close();
    factory.close();
    locator.close();
    Queue queue = ((LocalQueueBinding) server.getPostOffice().getBinding(new SimpleString(MY_QUEUE))).getQueue();
    LinkedListIterator<MessageReference> totalIterator = queue.browserIterator();
    try {
        int i = 0;
        while (totalIterator.hasNext()) {
            MessageReference ref = totalIterator.next();
            Assert.assertEquals(i++, ref.getMessage().getIntProperty("order").intValue());
        }
    } finally {
        totalIterator.close();
        server.stop();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 24 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQMessageHandlerSecurityTest method testSimpleMessageReceivedOnQueueWithSecuritySucceeds.

@Test
public void testSimpleMessageReceivedOnQueueWithSecuritySucceeds() throws Exception {
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addRole("testuser", "arole");
    Role role = new Role("arole", false, true, false, false, false, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setUser("testuser");
    spec.setPassword("testpassword");
    spec.setSetupAttempts(0);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQServerTestCase method assertRemainingMessages.

protected boolean assertRemainingMessages(final int expected) throws Exception {
    String queueName = "Queue1";
    Binding binding = servers.get(0).getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName));
    if (binding != null && binding instanceof LocalQueueBinding) {
        ((LocalQueueBinding) binding).getQueue().flushExecutor();
    }
    Long messageCount = null;
    for (int i = 0; i < 10; i++) {
        messageCount = servers.get(0).getMessageCountForQueue(queueName);
        if (messageCount.longValue() == expected) {
            break;
        } else {
            Thread.sleep(100);
        }
    }
    ProxyAssertSupport.assertEquals(expected, messageCount.intValue());
    return expected == messageCount.intValue();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)22 Binding (org.apache.activemq.artemis.core.postoffice.Binding)19 Test (org.junit.Test)18 Queue (org.apache.activemq.artemis.core.server.Queue)14 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)8 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)8 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 PostOfficeImpl (org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)4 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3