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);
}
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);
}
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);
}
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.");
}
}
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;
}
Aggregations