Search in sources :

Example 1 with TransportConnector

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

the class ActiveMQConnectionFactoryTest method assertCreateConnection.

protected void assertCreateConnection(String uri) throws Exception {
    // Start up a broker with a tcp connector.
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    TransportConnector connector = broker.addConnector(uri);
    broker.start();
    URI temp = new URI(uri);
    // URI connectURI = connector.getServer().getConnectURI();
    // TODO this sometimes fails when using the actual local host name
    URI currentURI = new URI(connector.getPublishableConnectString());
    // sometimes the actual host name doesn't work in this test case
    // e.g. on OS X so lets use the original details but just use the actual
    // port
    URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), temp.getPath(), temp.getQuery(), temp.getFragment());
    LOG.info("connection URI is: " + connectURI);
    // This should create the connection.
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI);
    connection = (ActiveMQConnection) cf.createConnection();
    assertNotNull(connection);
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 2 with TransportConnector

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

the class ActiveMQXAConnectionFactoryTest method assertCreateConnection.

protected void assertCreateConnection(String uri) throws Exception {
    // Start up a broker with a tcp connector.
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    TransportConnector connector = broker.addConnector(uri);
    broker.start();
    URI temp = new URI(uri);
    // URI connectURI = connector.getServer().getConnectURI();
    // TODO this sometimes fails when using the actual local host name
    URI currentURI = new URI(connector.getPublishableConnectString());
    // sometimes the actual host name doesn't work in this test case
    // e.g. on OS X so lets use the original details but just use the actual
    // port
    URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), temp.getPath(), temp.getQuery(), temp.getFragment());
    LOG.info("connection URI is: " + connectURI);
    // This should create the connection.
    ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(connectURI);
    Connection connection = cf.createConnection();
    assertXAConnection(connection);
    assertNotNull(connection);
    connection.close();
    connection = cf.createXAConnection();
    assertXAConnection(connection);
    assertNotNull(connection);
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) XAQueueConnection(javax.jms.XAQueueConnection) XAConnection(javax.jms.XAConnection) XATopicConnection(javax.jms.XATopicConnection) Connection(javax.jms.Connection) TransportConnection(org.apache.activemq.broker.TransportConnection) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 3 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 4 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 5 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)

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