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