Search in sources :

Example 6 with TransportConnector

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

the class ClientTestSupport method setUp.

@Override
public void setUp() throws Exception {
    final AtomicBoolean connected = new AtomicBoolean(false);
    TransportConnector connector;
    // Start up a broker with a tcp connector.
    try {
        broker = BrokerFactory.createBroker(new URI(this.brokerURL));
        broker.getBrokerName();
        connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) {

            // Hook into the connector so we can assert that the server
            // accepted a connection.
            @Override
            protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException {
                connected.set(true);
                return super.createConnection(transport);
            }
        };
        broker.addConnector(connector);
        broker.start();
    } catch (IOException e) {
        throw new JMSException("Error creating broker " + e);
    } catch (URISyntaxException e) {
        throw new JMSException("Error creating broker " + e);
    }
    URI connectURI;
    connectURI = connector.getServer().getConnectURI();
    // This should create the connection.
    connFactory = new ActiveMQConnectionFactory(connectURI);
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) JMSException(javax.jms.JMSException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransportConnector(org.apache.activemq.broker.TransportConnector)

Example 7 with TransportConnector

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

the class JmsMultipleBrokersTestSupport method bridgeBrokers.

// Overwrite this method to specify how you want to bridge the two brokers
// By default, bridge them using add network connector of the local broker
// and the first connector of the remote broker
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean dynamicOnly, int networkTTL, boolean conduit, boolean failover) throws Exception {
    List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
    URI remoteURI;
    if (!transportConnectors.isEmpty()) {
        remoteURI = transportConnectors.get(0).getConnectUri();
        String uri = "static:(" + remoteURI + ")";
        if (failover) {
            uri = "static:(failover:(" + remoteURI + "))";
        }
        NetworkConnector connector = new DiscoveryNetworkConnector(new URI(uri));
        connector.setName("to-" + remoteBroker.getBrokerName());
        connector.setDynamicOnly(dynamicOnly);
        connector.setNetworkTTL(networkTTL);
        connector.setConduitSubscriptions(conduit);
        localBroker.addNetworkConnector(connector);
        maxSetupTime = 2000;
        return connector;
    } else {
        throw new Exception("Remote broker has no registered connectors.");
    }
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkConnector(org.apache.activemq.network.NetworkConnector) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) URI(java.net.URI) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) TimeoutException(java.util.concurrent.TimeoutException) JMSException(javax.jms.JMSException)

Example 8 with TransportConnector

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

the class MQTTNetworkOfBrokersFailoverTest method createRemoteBroker.

@Override
protected BrokerService createRemoteBroker(PersistenceAdapter persistenceAdapter) throws Exception {
    BrokerService broker = super.createRemoteBroker(persistenceAdapter);
    broker.setPersistent(true);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.setDataDirectory("target/activemq-data");
    TransportConnector tc = broker.addConnector(getDefaultMQTTTransportConnectorUri());
    remoteBrokerMQTTPort = tc.getConnectUri().getPort();
    return broker;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) BrokerService(org.apache.activemq.broker.BrokerService)

Example 9 with TransportConnector

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

the class ConfigTest method testBrokerConfig.

/*
    * This tests configuring the different broker properties using
    * xbeans-spring
    */
@Test
public void testBrokerConfig() throws Exception {
    ActiveMQTopic dest;
    BrokerService broker;
    File journalFile = new File(JOURNAL_ROOT);
    recursiveDelete(journalFile);
    // Create broker from resource
    // System.out.print("Creating broker... ");
    broker = createBroker("org/apache/activemq/config/example.xml");
    LOG.info("Success");
    try {
        // Check broker configuration
        // System.out.print("Checking broker configurations... ");
        assertEquals("Broker Config Error (brokerName)", "brokerConfigTest", broker.getBrokerName());
        assertEquals("Broker Config Error (populateJMSXUserID)", false, broker.isPopulateJMSXUserID());
        assertEquals("Broker Config Error (useLoggingForShutdownErrors)", true, broker.isUseLoggingForShutdownErrors());
        assertEquals("Broker Config Error (useJmx)", true, broker.isUseJmx());
        assertEquals("Broker Config Error (persistent)", false, broker.isPersistent());
        assertEquals("Broker Config Error (useShutdownHook)", false, broker.isUseShutdownHook());
        assertEquals("Broker Config Error (deleteAllMessagesOnStartup)", true, broker.isDeleteAllMessagesOnStartup());
        LOG.info("Success");
        // Check specific vm transport
        // System.out.print("Checking vm connector... ");
        assertEquals("Should have a specific VM Connector", "vm://javacoola", broker.getVmConnectorURI().toString());
        LOG.info("Success");
        // Check transport connectors list
        // System.out.print("Checking transport connectors... ");
        List<TransportConnector> connectors = broker.getTransportConnectors();
        assertTrue("Should have created at least 3 connectors", connectors.size() >= 3);
        assertTrue("1st connector should be TcpTransportServer", connectors.get(0).getServer() instanceof TcpTransportServer);
        assertTrue("2nd connector should be TcpTransportServer", connectors.get(1).getServer() instanceof TcpTransportServer);
        assertTrue("3rd connector should be TcpTransportServer", connectors.get(2).getServer() instanceof TcpTransportServer);
        // Check network connectors
        // System.out.print("Checking network connectors... ");
        List<NetworkConnector> networkConnectors = broker.getNetworkConnectors();
        assertEquals("Should have a single network connector", 1, networkConnectors.size());
        LOG.info("Success");
        // Check dispatch policy configuration
        // System.out.print("Checking dispatch policies... ");
        dest = new ActiveMQTopic("Topic.SimpleDispatch");
        assertTrue("Should have a simple dispatch policy for " + dest.getTopicName(), broker.getDestinationPolicy().getEntryFor(dest).getDispatchPolicy() instanceof SimpleDispatchPolicy);
        dest = new ActiveMQTopic("Topic.RoundRobinDispatch");
        assertTrue("Should have a round robin dispatch policy for " + dest.getTopicName(), broker.getDestinationPolicy().getEntryFor(dest).getDispatchPolicy() instanceof RoundRobinDispatchPolicy);
        dest = new ActiveMQTopic("Topic.StrictOrderDispatch");
        assertTrue("Should have a strict order dispatch policy for " + dest.getTopicName(), broker.getDestinationPolicy().getEntryFor(dest).getDispatchPolicy() instanceof StrictOrderDispatchPolicy);
        LOG.info("Success");
        // Check subscription policy configuration
        // System.out.print("Checking subscription recovery policies... ");
        SubscriptionRecoveryPolicy subsPolicy;
        dest = new ActiveMQTopic("Topic.FixedSizedSubs");
        subsPolicy = broker.getDestinationPolicy().getEntryFor(dest).getSubscriptionRecoveryPolicy();
        assertTrue("Should have a fixed sized subscription recovery policy for " + dest.getTopicName(), subsPolicy instanceof FixedSizedSubscriptionRecoveryPolicy);
        assertEquals("FixedSizedSubsPolicy Config Error (maximumSize)", 2000000, ((FixedSizedSubscriptionRecoveryPolicy) subsPolicy).getMaximumSize());
        assertEquals("FixedSizedSubsPolicy Config Error (useSharedBuffer)", false, ((FixedSizedSubscriptionRecoveryPolicy) subsPolicy).isUseSharedBuffer());
        dest = new ActiveMQTopic("Topic.LastImageSubs");
        subsPolicy = broker.getDestinationPolicy().getEntryFor(dest).getSubscriptionRecoveryPolicy();
        assertTrue("Should have a last image subscription recovery policy for " + dest.getTopicName(), subsPolicy instanceof LastImageSubscriptionRecoveryPolicy);
        dest = new ActiveMQTopic("Topic.NoSubs");
        subsPolicy = broker.getDestinationPolicy().getEntryFor(dest).getSubscriptionRecoveryPolicy();
        assertTrue("Should have no subscription recovery policy for " + dest.getTopicName(), subsPolicy instanceof NoSubscriptionRecoveryPolicy);
        dest = new ActiveMQTopic("Topic.TimedSubs");
        subsPolicy = broker.getDestinationPolicy().getEntryFor(dest).getSubscriptionRecoveryPolicy();
        assertTrue("Should have a timed subscription recovery policy for " + dest.getTopicName(), subsPolicy instanceof TimedSubscriptionRecoveryPolicy);
        assertEquals("TimedSubsPolicy Config Error (recoverDuration)", 25000, ((TimedSubscriptionRecoveryPolicy) subsPolicy).getRecoverDuration());
        LOG.info("Success");
        // Check usage manager
        // System.out.print("Checking memory manager configurations... ");
        SystemUsage systemUsage = broker.getSystemUsage();
        assertTrue("Should have a SystemUsage", systemUsage != null);
        assertEquals("SystemUsage Config Error (MemoryUsage.limit)", 1024 * 1024 * 10, systemUsage.getMemoryUsage().getLimit());
        assertEquals("SystemUsage Config Error (MemoryUsage.percentUsageMinDelta)", 20, systemUsage.getMemoryUsage().getPercentUsageMinDelta());
        assertEquals("SystemUsage Config Error (TempUsage.limit)", 1024 * 1024 * 100, systemUsage.getTempUsage().getLimit());
        assertEquals("SystemUsage Config Error (StoreUsage.limit)", 1024 * 1024 * 1024, systemUsage.getStoreUsage().getLimit());
        assertEquals("SystemUsage Config Error (StoreUsage.name)", "foo", systemUsage.getStoreUsage().getName());
        assertNotNull(systemUsage.getStoreUsage().getStore());
        assertTrue(systemUsage.getStoreUsage().getStore() instanceof MemoryPersistenceAdapter);
        LOG.info("Success");
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) RoundRobinDispatchPolicy(org.apache.activemq.broker.region.policy.RoundRobinDispatchPolicy) StrictOrderDispatchPolicy(org.apache.activemq.broker.region.policy.StrictOrderDispatchPolicy) SystemUsage(org.apache.activemq.usage.SystemUsage) TcpTransportServer(org.apache.activemq.transport.tcp.TcpTransportServer) FixedSizedSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.FixedSizedSubscriptionRecoveryPolicy) NoSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.NoSubscriptionRecoveryPolicy) FixedSizedSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.FixedSizedSubscriptionRecoveryPolicy) NoSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.NoSubscriptionRecoveryPolicy) TimedSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.TimedSubscriptionRecoveryPolicy) SubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.SubscriptionRecoveryPolicy) LastImageSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.LastImageSubscriptionRecoveryPolicy) TransportConnector(org.apache.activemq.broker.TransportConnector) TimedSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.TimedSubscriptionRecoveryPolicy) SimpleDispatchPolicy(org.apache.activemq.broker.region.policy.SimpleDispatchPolicy) LastImageSubscriptionRecoveryPolicy(org.apache.activemq.broker.region.policy.LastImageSubscriptionRecoveryPolicy) NetworkConnector(org.apache.activemq.network.NetworkConnector) BrokerService(org.apache.activemq.broker.BrokerService) File(java.io.File) Test(org.junit.Test)

Example 10 with TransportConnector

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

the class CheckDuplicateMessagesOnDuplexTest method createLocalBroker.

private void createLocalBroker() throws Exception {
    localBroker = new BrokerService();
    localBroker.setBrokerName("LOCAL");
    localBroker.setUseJmx(true);
    localBroker.setSchedulePeriodForDestinationPurge(5000);
    ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector(false);
    localBroker.setManagementContext(managementContext);
    PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/local");
    localBroker.setPersistenceAdapter(persistenceAdapter);
    List<TransportConnector> transportConnectors = new ArrayList<>();
    DebugTransportFactory tf = new DebugTransportFactory();
    TransportServer transport = tf.doBind(URI.create("nio://127.0.0.1:23539"));
    TransportConnector transportConnector = new TransportConnector(transport);
    transportConnector.setName("tc");
    transportConnector.setAuditNetworkProducers(true);
    transportConnectors.add(transportConnector);
    localBroker.setTransportConnectors(transportConnectors);
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) ArrayList(java.util.ArrayList) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) TcpTransportServer(org.apache.activemq.transport.tcp.TcpTransportServer) TransportServer(org.apache.activemq.transport.TransportServer) BrokerService(org.apache.activemq.broker.BrokerService) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

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