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