Search in sources :

Example 1 with ClusterConnection

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

the class ActiveMQServerControlImpl method listNetworkTopology.

@Override
public String listNetworkTopology() throws Exception {
    checkStarted();
    clearIO();
    try {
        JsonArrayBuilder brokers = JsonLoader.createArrayBuilder();
        ClusterManager clusterManager = server.getClusterManager();
        if (clusterManager != null) {
            Set<ClusterConnection> clusterConnections = clusterManager.getClusterConnections();
            for (ClusterConnection clusterConnection : clusterConnections) {
                Topology topology = clusterConnection.getTopology();
                Collection<TopologyMemberImpl> members = topology.getMembers();
                for (TopologyMemberImpl member : members) {
                    JsonObjectBuilder obj = JsonLoader.createObjectBuilder();
                    TransportConfiguration live = member.getLive();
                    if (live != null) {
                        obj.add("nodeID", member.getNodeId()).add("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
                        TransportConfiguration backup = member.getBackup();
                        if (backup != null) {
                            obj.add("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
                        }
                    }
                    brokers.add(obj);
                }
            }
        }
        return brokers.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JsonArrayBuilder(javax.json.JsonArrayBuilder) Topology(org.apache.activemq.artemis.core.client.impl.Topology) JsonObjectBuilder(javax.json.JsonObjectBuilder) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 2 with ClusterConnection

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

the class RemotingServiceImpl method createAcceptor.

@Override
public Acceptor createAcceptor(TransportConfiguration info) {
    Acceptor acceptor = null;
    try {
        AcceptorFactory factory = server.getServiceRegistry().getAcceptorFactory(info.getName(), info.getFactoryClassName());
        Map<String, ProtocolManagerFactory> selectedProtocolFactories = new ConcurrentHashMap<>();
        @SuppressWarnings("deprecation") String protocol = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOL_PROP_NAME, null, info.getParams());
        if (protocol != null) {
            ActiveMQServerLogger.LOGGER.warnDeprecatedProtocol();
            locateProtocols(protocol, info, selectedProtocolFactories);
        }
        String protocols = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOLS_PROP_NAME, null, info.getParams());
        if (protocols != null) {
            locateProtocols(protocols, info, selectedProtocolFactories);
        }
        ClusterConnection clusterConnection = lookupClusterConnection(info);
        // If empty: we get the default list
        if (selectedProtocolFactories.isEmpty()) {
            selectedProtocolFactories = protocolMap;
        }
        Map<String, ProtocolManager> selectedProtocols = new ConcurrentHashMap<>();
        for (Entry<String, ProtocolManagerFactory> entry : selectedProtocolFactories.entrySet()) {
            selectedProtocols.put(entry.getKey(), entry.getValue().createProtocolManager(server, info.getExtraParams(), incomingInterceptors, outgoingInterceptors));
        }
        acceptor = factory.createAcceptor(info.getName(), clusterConnection, info.getParams(), new DelegatingBufferHandler(), this, threadPool, scheduledThreadPool, selectedProtocols);
        if (defaultInvmSecurityPrincipal != null && acceptor.isUnsecurable()) {
            acceptor.setDefaultActiveMQPrincipal(defaultInvmSecurityPrincipal);
        }
        acceptors.put(info.getName(), acceptor);
        if (managementService != null) {
            acceptor.setNotificationService(managementService);
            managementService.registerAcceptor(acceptor, info);
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.errorCreatingAcceptor(e, info.getFactoryClassName());
    }
    return acceptor;
}
Also used : Acceptor(org.apache.activemq.artemis.spi.core.remoting.Acceptor) ProtocolManagerFactory(org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory) CoreProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ProtocolManager(org.apache.activemq.artemis.spi.core.protocol.ProtocolManager) AcceptorFactory(org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with ClusterConnection

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

the class AMQPConnectionCallback method getFailoverList.

public URI getFailoverList() {
    ClusterManager clusterManager = server.getClusterManager();
    ClusterConnection clusterConnection = clusterManager.getDefaultConnection(null);
    if (clusterConnection != null) {
        TopologyMemberImpl member = clusterConnection.getTopology().getMember(server.getNodeID().toString());
        return member.toBackupURI();
    }
    return null;
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 4 with ClusterConnection

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

the class TopologyClusterTestBase method waitForClusterConnections.

protected void waitForClusterConnections(final int node, final int expected) throws Exception {
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalArgumentException("No server at " + node);
    }
    ClusterManager clusterManager = server.getClusterManager();
    long start = System.currentTimeMillis();
    int nodesCount;
    do {
        nodesCount = 0;
        for (ClusterConnection clusterConn : clusterManager.getClusterConnections()) {
            Map<String, String> nodes = clusterConn.getNodes();
            for (String id : nodes.keySet()) {
                if (clusterConn.isNodeActive(id)) {
                    nodesCount++;
                }
            }
        }
        if (nodesCount == expected) {
            return;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < ActiveMQTestBase.WAIT_TIMEOUT);
    log.error(clusterDescription(servers[node]));
    Assert.assertEquals("Timed out waiting for cluster connections for server " + node, expected, nodesCount);
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 5 with ClusterConnection

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

the class ExpireWhileLoadBalanceTest method testSend.

@Test
public void testSend() throws Exception {
    waitForTopology(getServer(0), 3);
    waitForTopology(getServer(1), 3);
    waitForTopology(getServer(2), 3);
    SimpleString expiryQueue = SimpleString.toSimpleString("expiryQueue");
    AddressSettings as = new AddressSettings();
    as.setDeadLetterAddress(expiryQueue);
    as.setExpiryAddress(expiryQueue);
    for (int i = 0; i <= 2; i++) {
        createQueue(i, "queues.testaddress", "queue0", null, true);
        getServer(i).createQueue(expiryQueue, RoutingType.ANYCAST, expiryQueue, null, true, false);
        getServer(i).getAddressSettingsRepository().addMatch("#", as);
    }
    // this will pause all the cluster bridges
    for (ClusterConnection clusterConnection : getServer(0).getClusterManager().getClusterConnections()) {
        for (MessageFlowRecord record : ((ClusterConnectionImpl) clusterConnection).getRecords().values()) {
            record.getBridge().pause();
        }
    }
    ClientSessionFactory sf = sfs[0];
    ClientSession session = sf.createSession(false, false);
    ClientProducer producer = session.createProducer("queues.testaddress");
    for (int i = 0; i < 1000; i++) {
        ClientMessage message = session.createMessage(true);
        message.setExpiration(500);
        producer.send(message);
    }
    session.commit();
    session.start();
    ClientConsumer consumer = session.createConsumer("expiryQueue");
    for (int i = 0; i < 1000; i++) {
        ClientMessage message = consumer.receive(2000);
        Assert.assertNotNull(message);
        message.acknowledge();
    }
    session.commit();
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)16 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)6 Topology (org.apache.activemq.artemis.core.client.impl.Topology)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)5 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 XAException (javax.transaction.xa.XAException)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 MessageFlowRecord (org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord)2 Test (org.junit.Test)2 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 JMSException (javax.jms.JMSException)1