Search in sources :

Example 6 with MessageFlowRecord

use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.

the class ClusteredBridgeReconnectTest method testReconnectBridge.

@Test
public void testReconnectBridge() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
    startServers(0, 1);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, true);
    createQueue(1, "queues.testaddress", "queue0", null, true);
    addConsumer(0, 0, "queue0", null);
    addConsumer(1, 1, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 1, 1, false);
    waitForBindings(1, "queues.testaddress", 1, 1, false);
    ClientSession session0 = sfs[0].createSession();
    ClientSession session1 = sfs[0].createSession();
    session0.start();
    session1.start();
    ClientProducer producer = session0.createProducer("queues.testaddress");
    int NUMBER_OF_MESSAGES = 100;
    Assert.assertEquals(1, servers[0].getClusterManager().getClusterConnections().size());
    ClusterConnectionImpl connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
    Assert.assertEquals(1, connection.getRecords().size());
    MessageFlowRecord record = connection.getRecords().values().toArray(new MessageFlowRecord[1])[0];
    ClusterConnectionBridge bridge = (ClusterConnectionBridge) record.getBridge();
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        ClientMessage msg = session0.createMessage(true);
        producer.send(msg);
        session0.commit();
        if (i == 17) {
            bridge.getSessionFactory().getConnection().fail(new ActiveMQException("failed once!"));
        }
    }
    int cons0Count = 0, cons1Count = 0;
    while (true) {
        ClientMessage msg = consumers[0].getConsumer().receive(1000);
        if (msg == null) {
            break;
        }
        cons0Count++;
        msg.acknowledge();
        session0.commit();
    }
    while (true) {
        ClientMessage msg = consumers[1].getConsumer().receive(1000);
        if (msg == null) {
            break;
        }
        cons1Count++;
        msg.acknowledge();
        session1.commit();
    }
    Assert.assertEquals("cons0 = " + cons0Count + ", cons1 = " + cons1Count, NUMBER_OF_MESSAGES, cons0Count + cons1Count);
    session0.commit();
    session1.commit();
    connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
    Assert.assertEquals(1, connection.getRecords().size());
    Assert.assertNotNull(bridge.getSessionFactory());
    stopServers(0, 1);
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClusterConnectionBridge(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl) Test(org.junit.Test)

Example 7 with MessageFlowRecord

use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.

the class ClusterConnectionImpl method stop.

@Override
public void stop() throws Exception {
    if (!started) {
        return;
    }
    stopping = true;
    if (logger.isDebugEnabled()) {
        logger.debug(this + "::stopping ClusterConnection");
    }
    if (serverLocator != null) {
        serverLocator.removeClusterTopologyListener(this);
    }
    logger.debug("Cluster connection being stopped for node" + nodeManager.getNodeId() + ", server = " + this.server + " serverLocator = " + serverLocator);
    synchronized (this) {
        for (MessageFlowRecord record : records.values()) {
            try {
                record.close();
            } catch (Exception ignore) {
            }
        }
    }
    if (managementService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("name"), name);
        Notification notification = new Notification(nodeManager.getNodeId().toString(), CoreNotificationType.CLUSTER_CONNECTION_STOPPED, props);
        managementService.sendNotification(notification);
    }
    executor.execute(new Runnable() {

        @Override
        public void run() {
            synchronized (ClusterConnectionImpl.this) {
                closeLocator(serverLocator);
                serverLocator = null;
            }
        }
    });
    started = false;
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 8 with MessageFlowRecord

use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.

the class ClusterConnectionImpl method removeRecord.

@Override
public void removeRecord(String targetNodeID) {
    logger.debug("Removing record for: " + targetNodeID);
    MessageFlowRecord record = records.remove(targetNodeID);
    try {
        if (record != null) {
            record.close();
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.failedToRemoveRecord(e);
    }
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 9 with MessageFlowRecord

use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.

the class ClusterConnectionConfigTest method makeSureForwardingFlowControl.

private void makeSureForwardingFlowControl(int producerWindow, int... indices) throws NoSuchFieldException, IllegalAccessException {
    for (int i : indices) {
        ClusterConnectionImpl cc = (ClusterConnectionImpl) servers[i].getClusterManager().getClusterConnection("cluster" + i);
        Map<String, MessageFlowRecord> map = cc.getRecords();
        assertEquals(1, map.size());
        MessageFlowRecord record = map.entrySet().iterator().next().getValue();
        // NoSuchFieldException
        Field f = record.getClass().getDeclaredField("targetLocator");
        f.setAccessible(true);
        ServerLocatorInternal targetLocator = (ServerLocatorInternal) f.get(record);
        assertEquals(producerWindow, targetLocator.getProducerWindowSize());
    }
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) Field(java.lang.reflect.Field) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Example 10 with MessageFlowRecord

use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.

the class OneWayChainClusterTest method testChainClusterConnections.

@Test
public void testChainClusterConnections() throws Exception {
    setupClusterConnection("cluster0-1", 0, 1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster1-2", 1, 2, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster2-3", 2, 3, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster3-4", 3, 4, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster4-X", 4, -1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    startServers(0, 1, 2, 3, 4);
    Set<ClusterConnection> connectionSet = getServer(0).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ClusterConnectionImpl ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    long timeout = System.currentTimeMillis() + 5000;
    Map<String, MessageFlowRecord> records = null;
    while (timeout > System.currentTimeMillis()) {
        records = ccon.getRecords();
        if (records != null && records.size() == 1) {
            break;
        }
    }
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(1).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(2).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(3).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(4).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl) Test(org.junit.Test)

Aggregations

MessageFlowRecord (org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)4 Test (org.junit.Test)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)2 ClusterConnectionBridge (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Field (java.lang.reflect.Field)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocatorInternal (org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)1 Binding (org.apache.activemq.artemis.core.postoffice.Binding)1 Queue (org.apache.activemq.artemis.core.server.Queue)1 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)1 Notification (org.apache.activemq.artemis.core.server.management.Notification)1