Search in sources :

Example 1 with SocketProxy

use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.

the class BrokerQueueNetworkWithDisconnectTest method bridgeBrokers.

@Override
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();
        if (useSocketProxy) {
            socketProxy = new SocketProxy(remoteURI);
            remoteURI = socketProxy.getUrl();
        }
        DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:(" + remoteURI + "?wireFormat.maxInactivityDuration=" + inactiveDuration + "&wireFormat.maxInactivityDurationInitalDelay=" + inactiveDuration + ")?useExponentialBackOff=false"));
        connector.setDynamicOnly(dynamicOnly);
        connector.setNetworkTTL(networkTTL);
        localBroker.addNetworkConnector(connector);
        maxSetupTime = 2000;
        if (useDuplexNetworkBridge) {
            connector.setDuplex(true);
        }
        return connector;
    } else {
        throw new Exception("Remote broker has no registered connectors.");
    }
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) SocketProxy(org.apache.activemq.util.SocketProxy) URI(java.net.URI) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector)

Example 2 with SocketProxy

use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.

the class NetworkAsyncStartTest method testAsyncNetworkStartupWithSlowConnectionCreation.

public void testAsyncNetworkStartupWithSlowConnectionCreation() throws Exception {
    final BrokerService brokerA = brokers.get("BrokerA").broker;
    SocketProxy proxyToB = new SocketProxy();
    // don't accept any connections so limited to one connection with backlog
    proxyToB.setPauseAtStart(true);
    proxyToB.setAcceptBacklog(1);
    proxyToB.setTarget(new URI(brokerBUri));
    proxyToB.open();
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, proxyToB.getUrl().toString());
    bridgeBroker(brokerA, brokerCUri);
    Executor e = Executors.newCachedThreadPool();
    e.execute(new Runnable() {

        @Override
        public void run() {
            LOG.info("starting A");
            try {
                brokerA.setNetworkConnectorStartAsync(true);
                brokerA.start();
            } catch (Exception e) {
                LOG.error("start failed", e);
            }
        }
    });
    LOG.info("starting transport connector on C");
    BrokerService brokerC = brokers.get("BrokerC").broker;
    brokerC.addConnector(brokerCUri);
    brokerC.start();
    final long maxWaitMillis = 20 * 1000;
    assertTrue("got bridge to C in 10 seconds", waitForBridgeFormation(brokerA, 1, 7, maxWaitMillis));
}
Also used : Executor(java.util.concurrent.Executor) SocketProxy(org.apache.activemq.util.SocketProxy) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 3 with SocketProxy

use of org.apache.activemq.util.SocketProxy 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 4 with SocketProxy

use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.

the class DurableSubscriberWithNetworkDisconnectTest method bridgeBrokers.

@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean l_dynamicOnly, int networkTTL, boolean l_conduit, boolean l_failover) throws Exception {
    List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
    URI remoteURI;
    if (!transportConnectors.isEmpty()) {
        remoteURI = transportConnectors.get(0).getConnectUri();
        if (useSocketProxy) {
            socketProxy = new SocketProxy(remoteURI);
            remoteURI = socketProxy.getUrl();
        }
        String options = "";
        if (failover) {
            options = "static:(failover:(" + remoteURI;
        } else {
            options = "static:(" + remoteURI;
        }
        if (inactivity) {
            options += "?wireFormat.maxInactivityDuration=" + inactiveDuration + "&wireFormat.maxInactivityDurationInitalDelay=" + inactiveDuration + ")";
        } else {
            options += ")";
        }
        if (failover) {
            options += "?maxReconnectAttempts=0)";
        }
        options += "?useExponentialBackOff=" + exponentialBackOff;
        DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI(options));
        connector.setDynamicOnly(dynamicOnly);
        connector.setNetworkTTL(networkTTL);
        localBroker.addNetworkConnector(connector);
        maxSetupTime = 2000;
        if (useDuplexNetworkBridge) {
            connector.setDuplex(true);
        }
        return connector;
    } else {
        throw new Exception("Remote broker has no registered connectors.");
    }
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) SocketProxy(org.apache.activemq.util.SocketProxy) URI(java.net.URI) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) JMSException(javax.jms.JMSException)

Example 5 with SocketProxy

use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.

the class FailoverTransactionTest method testFailoverConnectionSendReplyLost.

@Test
@BMRules(rules = { @BMRule(name = "set no return response and stop the broker", targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", targetMethod = "processMessage", targetLocation = "EXIT", action = "org.apache.activemq.transport.failover.FailoverTransactionTest.holdResponseAndStopProxyOnFirstSend($0)") })
public void testFailoverConnectionSendReplyLost() throws Exception {
    LOG.info(this + " running test testFailoverConnectionSendReplyLost");
    broker = createBroker();
    proxy = new SocketProxy();
    firstSend = true;
    startBrokerWithDurableQueue();
    proxy.setTarget(new URI(url));
    proxy.open();
    doByteman.set(true);
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + proxy.getUrl().toASCIIString() + ")?jms.watchTopicAdvisories=false");
    configureConnectionFactory(cf);
    Connection connection = cf.createConnection();
    connection.start();
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final Queue destination = session.createQueue(QUEUE_NAME);
    MessageConsumer consumer = session.createConsumer(destination);
    final CountDownLatch sendDoneLatch = new CountDownLatch(1);
    // proxy connection will die on send reply so this will hang on failover reconnect till open
    new Thread() {

        @Override
        public void run() {
            LOG.info("doing async send...");
            try {
                produceMessage(session, destination);
            } catch (JMSException e) {
                // assertTrue(e instanceof TransactionRolledBackException);
                LOG.info("got send exception: ", e);
            }
            sendDoneLatch.countDown();
            LOG.info("done async send");
        }
    }.start();
    // will be closed by the plugin
    Assert.assertTrue("proxy was closed", proxy.waitUntilClosed(30));
    LOG.info("restarting proxy");
    proxy.open();
    Assert.assertTrue("message sent through failover", sendDoneLatch.await(30, TimeUnit.SECONDS));
    Message msg = consumer.receive(20000);
    LOG.info("Received: " + msg);
    Assert.assertNotNull("we got the message", msg);
    Assert.assertNull("we got just one message", consumer.receive(2000));
    consumer.close();
    connection.close();
    // ensure no dangling messages with fresh broker etc
    broker.stop();
    LOG.info("Checking for remaining/hung messages with restart..");
    broker = createBroker();
    broker.start();
    // after restart, ensure no dangling messages
    cf = new ActiveMQConnectionFactory("failover:(" + url + ")");
    configureConnectionFactory(cf);
    connection = cf.createConnection();
    connection.start();
    Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    consumer = session2.createConsumer(destination);
    msg = consumer.receive(1000);
    if (msg == null) {
        msg = consumer.receive(5000);
    }
    LOG.info("Received: " + msg);
    Assert.assertNull("no messges left dangling but got: " + msg, msg);
    connection.close();
    proxy.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) OpenWireConnection(org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) JMSException(javax.jms.JMSException) SocketProxy(org.apache.activemq.util.SocketProxy) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) Queue(javax.jms.Queue) Session(javax.jms.Session) ServerSession(javax.jms.ServerSession) Test(org.junit.Test) OpenwireArtemisBaseTest(org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

SocketProxy (org.apache.activemq.util.SocketProxy)8 URI (java.net.URI)6 Test (org.junit.Test)4 TransportConnector (org.apache.activemq.broker.TransportConnector)3 Group (io.fabric8.groups.Group)2 GroupListener (io.fabric8.groups.GroupListener)2 NodeState (io.fabric8.groups.NodeState)2 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Connection (javax.jms.Connection)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2 ObjectName (javax.management.ObjectName)2 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)2