Search in sources :

Example 41 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class AbortSlowConsumer0Test method testAbortConsumerOnDeadConnection.

@Test
public void testAbortConsumerOnDeadConnection() throws Exception {
    TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0");
    transportConnector.setBrokerService(broker);
    transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory());
    transportConnector.start();
    SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI());
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl());
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setAll(4);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    Connection c = connectionFactory.createConnection();
    connections.add(c);
    c.start();
    Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
    startProducers(destination, 10);
    messageconsumer.receive(4000).acknowledge();
    assertNotNull(messageconsumer.receive(4000));
    assertNotNull(messageconsumer.receive(4000));
    assertNotNull(messageconsumer.receive(4000));
    // close control command won't get through
    socketProxy.pause();
    ActiveMQDestination amqDest = (ActiveMQDestination) destination;
    ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
    final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
    assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("DestView {} consumerCount {}", destView, destView.getConsumerCount());
            return 0 == destView.getConsumerCount();
        }
    }));
    socketProxy.goOn();
    assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            boolean closed = false;
            try {
                messageconsumer.receive(400);
            } catch (javax.jms.IllegalStateException expected) {
                closed = expected.toString().contains("closed");
            }
            return closed;
        }
    }));
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) Connection(javax.jms.Connection) SocketProxy(org.apache.activemq.util.SocketProxy) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ObjectName(javax.management.ObjectName) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportConnector(org.apache.activemq.broker.TransportConnector) ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy) Session(javax.jms.Session) Test(org.junit.Test)

Example 42 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class kahaDbJdbcLeaseQueueMasterSlaveTest method createSlave.

@Override
protected void createSlave() throws Exception {
    // use a separate thread as the slave will block waiting for
    // the exclusive db lock
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                BrokerService broker = new BrokerService();
                broker.setBrokerName("slave");
                TransportConnector connector = new TransportConnector();
                connector.setUri(new URI(SLAVE_URL));
                broker.addConnector(connector);
                broker.setUseJmx(false);
                broker.setPersistent(true);
                KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
                LeaseDatabaseLocker leaseDatabaseLocker = new LeaseDatabaseLocker();
                leaseDatabaseLocker.setDataSource(getExistingDataSource());
                leaseDatabaseLocker.setStatements(new Statements());
                kahaDBPersistenceAdapter.setLocker(leaseDatabaseLocker);
                configureLocker(kahaDBPersistenceAdapter);
                configureBroker(broker);
                broker.start();
                slave.set(broker);
                slaveStarted.countDown();
            } catch (IllegalStateException expectedOnShutdown) {
            } catch (Exception e) {
                fail("failed to start slave broker, reason:" + e);
            }
        }
    };
    t.start();
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) Statements(org.apache.activemq.store.jdbc.Statements) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) LeaseDatabaseLocker(org.apache.activemq.store.jdbc.LeaseDatabaseLocker) IOException(java.io.IOException) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 43 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class mKahaDbQueueMasterSlaveTest method createSlave.

@Override
protected void createSlave() throws Exception {
    // use a separate thread as the slave will block waiting for
    // the exclusive db lock
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                BrokerService broker = new BrokerService();
                broker.setBrokerName("slave");
                TransportConnector connector = new TransportConnector();
                connector.setUri(new URI(SLAVE_URL));
                broker.addConnector(connector);
                // no need for broker.setMasterConnectorURI(masterConnectorURI)
                // as the db lock provides the slave/master initialisation
                broker.setUseJmx(false);
                broker.setPersistent(true);
                MultiKahaDBPersistenceAdapter mKahaDB = new MultiKahaDBPersistenceAdapter();
                List<FilteredKahaDBPersistenceAdapter> adapters = new LinkedList<>();
                FilteredKahaDBPersistenceAdapter defaultEntry = new FilteredKahaDBPersistenceAdapter();
                defaultEntry.setPersistenceAdapter(new KahaDBPersistenceAdapter());
                defaultEntry.setPerDestination(true);
                adapters.add(defaultEntry);
                mKahaDB.setFilteredPersistenceAdapters(adapters);
                broker.setPersistenceAdapter(mKahaDB);
                broker.start();
                slave.set(broker);
                slaveStarted.countDown();
            } catch (IllegalStateException expectedOnShutdown) {
            } catch (Exception e) {
                fail("failed to start slave broker, reason:" + e);
            }
        }
    };
    t.start();
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) FilteredKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.FilteredKahaDBPersistenceAdapter) MultiKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) LinkedList(java.util.LinkedList) MultiKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter) FilteredKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.FilteredKahaDBPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 44 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class ThreeBrokerTopicNetworkUsingTcpTest method bridgeBrokers.

protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
    List<TransportConnector> remoteTransports = remoteBroker.getTransportConnectors();
    List<TransportConnector> localTransports = localBroker.getTransportConnectors();
    URI remoteURI;
    URI localURI;
    if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
        remoteURI = remoteTransports.get(0).getConnectUri();
        localURI = localTransports.get(0).getConnectUri();
        // Ensure that we are connecting using tcp
        if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
            NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
            config.setBrokerName(localBroker.getBrokerName());
            DemandForwardingBridge bridge = new DemandForwardingBridge(config, TransportFactory.connect(localURI), TransportFactory.connect(remoteURI));
            bridge.setBrokerService(localBroker);
            bridges.add(bridge);
            bridge.start();
        } else {
            throw new Exception("Remote broker or local broker is not using tcp connectors");
        }
    } else {
        throw new Exception("Remote broker or local broker has no registered connectors.");
    }
    maxSetupTime = 2000;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkBridgeConfiguration(org.apache.activemq.network.NetworkBridgeConfiguration) DemandForwardingBridge(org.apache.activemq.network.DemandForwardingBridge) URI(java.net.URI)

Example 45 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class ConnectorXBeanConfigTest method testConnectorConfiguredCorrectly.

public void testConnectorConfiguredCorrectly() throws Exception {
    TransportConnector connector = brokerService.getTransportConnectors().get(0);
    assertEquals(new URI("tcp://localhost:61636"), connector.getUri());
    assertTrue(connector.getTaskRunnerFactory() == brokerService.getTaskRunnerFactory());
    NetworkConnector netConnector = brokerService.getNetworkConnectors().get(0);
    List<ActiveMQDestination> excludedDestinations = netConnector.getExcludedDestinations();
    assertEquals(new ActiveMQQueue("exclude.test.foo"), excludedDestinations.get(0));
    assertEquals(new ActiveMQTopic("exclude.test.bar"), excludedDestinations.get(1));
    List<ActiveMQDestination> dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
    assertEquals(new ActiveMQQueue("include.test.foo"), dynamicallyIncludedDestinations.get(0));
    assertEquals(new ActiveMQTopic("include.test.bar"), dynamicallyIncludedDestinations.get(1));
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) NetworkConnector(org.apache.activemq.network.NetworkConnector) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) URI(java.net.URI) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

TransportConnector (org.apache.activemq.broker.TransportConnector)59 URI (java.net.URI)31 BrokerService (org.apache.activemq.broker.BrokerService)31 NetworkConnector (org.apache.activemq.network.NetworkConnector)10 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)9 DiscoveryNetworkConnector (org.apache.activemq.network.DiscoveryNetworkConnector)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)4 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)4 JMSException (javax.jms.JMSException)3 Session (javax.jms.Session)3 File (java.io.File)2 Principal (java.security.Principal)2 MessageProducer (javax.jms.MessageProducer)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ConnectionContext (org.apache.activemq.broker.ConnectionContext)2 Connector (org.apache.activemq.broker.Connector)2 StubConnection (org.apache.activemq.broker.StubConnection)2