use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusterConnectionImpl method nodeUP.
@Override
public void nodeUP(final TopologyMember topologyMember, final boolean last) {
if (stopping) {
return;
}
final String nodeID = topologyMember.getNodeId();
if (logger.isDebugEnabled()) {
String ClusterTestBase = "receiving nodeUP for nodeID=";
logger.debug(this + ClusterTestBase + nodeID + " connectionPair=" + topologyMember);
}
if (nodeID.equals(nodeManager.getNodeId().toString())) {
if (logger.isTraceEnabled()) {
logger.trace(this + "::informing about backup to itself, nodeUUID=" + nodeManager.getNodeId() + ", connectorPair=" + topologyMember + ", this = " + this);
}
return;
}
// if the node is more than 1 hop away, we do not create a bridge for direct cluster connection
if (allowDirectConnectionsOnly && !allowableConnections.contains(topologyMember.getLive().newTransportConfig(TRANSPORT_CONFIG_NAME))) {
return;
}
// and empty static connectors to create bridges... ulgy!
if (serverLocator == null) {
return;
}
/*we don't create bridges to backups*/
if (topologyMember.getLive() == null) {
if (logger.isTraceEnabled()) {
logger.trace(this + " ignoring call with nodeID=" + nodeID + ", topologyMember=" + topologyMember + ", last=" + last);
}
return;
}
synchronized (recordsGuard) {
try {
MessageFlowRecord record = records.get(nodeID);
if (record == null) {
if (logger.isDebugEnabled()) {
logger.debug(this + "::Creating record for nodeID=" + nodeID + ", topologyMember=" + topologyMember);
}
// New node - create a new flow record
final SimpleString queueName = new SimpleString(storeAndForwardPrefix + name + "." + nodeID);
Binding queueBinding = postOffice.getBinding(queueName);
Queue queue;
if (queueBinding != null) {
queue = (Queue) queueBinding.getBindable();
} else {
// Add binding in storage so the queue will get reloaded on startup and we can find it - it's never
// actually routed to at that address though
queue = server.createQueue(queueName, RoutingType.MULTICAST, queueName, null, true, false, -1, false, true);
}
// There are a few things that will behave differently when it's an internal queue
// such as we don't hold groupIDs inside the SnF queue
queue.setInternalQueue(true);
createNewRecord(topologyMember.getUniqueEventID(), nodeID, topologyMember.getLive(), queueName, queue, true);
} else {
if (logger.isTraceEnabled()) {
logger.trace(this + " ignored nodeUp record for " + topologyMember + " on nodeID=" + nodeID + " as the record already existed");
}
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorUpdatingTopology(e);
}
}
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusterConnectionImpl method describe.
@Override
public String describe() {
StringWriter str = new StringWriter();
PrintWriter out = new PrintWriter(str);
out.println(this);
out.println("***************************************");
out.println(name + " connected to");
for (MessageFlowRecord messageFlow : records.values()) {
out.println("\t Bridge = " + messageFlow.getBridge());
out.println("\t Flow Record = " + messageFlow);
}
out.println("***************************************");
return str.toString();
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusterConnectionImpl method disconnectRecord.
@Override
public void disconnectRecord(String targetNodeID) {
logger.debug("Disconnecting record for: " + targetNodeID);
MessageFlowRecord record = records.get(targetNodeID);
try {
if (record != null) {
record.disconnectBindings();
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToDisconnectBindings(e);
}
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusteredBridgeReconnectTest method testReconnectBridge.
@Test
@BMRules(rules = { @BMRule(name = "enter", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.enterConnect();"), @BMRule(name = "exit", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.exitConnect();"), @BMRule(name = "send", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl", targetMethod = "send(org.apache.activemq.artemis.core.protocol.core.Packet)", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.send();") })
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) {
shouldFail = true;
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();
stopServers(0, 1);
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord 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