tabish121 commented on code in PR #6000: URL: https://github.com/apache/activemq-artemis/pull/6000#discussion_r2453114816
########## tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/AMQPRoutingTypeMismatchTest.java: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.tests.integration.amqp.connect; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import java.lang.invoke.MethodHandles; + +import org.apache.activemq.artemis.api.core.QueueConfiguration; +import org.apache.activemq.artemis.api.core.RoutingType; +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.config.CoreAddressConfiguration; +import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBridgeAddressPolicyElement; +import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBridgeBrokerConnectionElement; +import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBridgeQueuePolicyElement; +import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectConfiguration; +import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPReceiverBrokerConnectionElement; +import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.server.Queue; +import org.apache.activemq.artemis.core.settings.impl.AddressSettings; +import org.apache.activemq.artemis.tests.integration.amqp.AmqpTestSupport; +import org.apache.activemq.artemis.tests.util.CFUtil; +import org.apache.activemq.artemis.tests.util.Wait; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.activemq.artemis.protocol.amqp.connect.bridge.AMQPBridgeConstants.LINK_ATTACH_TIMEOUT; +import static org.apache.activemq.artemis.protocol.amqp.connect.bridge.AMQPBridgeConstants.LINK_RECOVERY_INITIAL_DELAY; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +public class AMQPRoutingTypeMismatchTest extends AmqpTestSupport { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + protected static final int AMQP_PORT_2 = 5673; + public static final int TIME_BEFORE_RESTART = 1000; + + @Test + public void testMismatchOnReceiver() throws Exception { + + ActiveMQServer server = createServer(AMQP_PORT, false); + server.getConfiguration().getAddressSettings().clear(); + server.getConfiguration().addAddressSetting("#", new AddressSettings().setDeadLetterAddress(SimpleString.of("topic.DLQ")).setRedeliveryDelay(0).setMaxDeliveryAttempts(1)); + server.getConfiguration().addQueueConfiguration(QueueConfiguration.of("topic.DLQ").setRoutingType(RoutingType.ANYCAST)); + server.getConfiguration().addAddressConfiguration(new CoreAddressConfiguration().setName(getName()).addRoutingType(RoutingType.MULTICAST)); + server.setIdentity("Server1"); + server.start(); + + ConnectionFactory factory = CFUtil.createConnectionFactory("AMQP", "tcp://localhost:" + AMQP_PORT); + + long nmessages = 10; + + try (Connection connection = factory.createConnection()) { + connection.setClientID("myID"); + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageConsumer consumer = session.createDurableConsumer(session.createTopic(getName()), "myTopic"); + MessageProducer producer = session.createProducer(session.createTopic(getName())); + for (int i = 0; i < nmessages; i++) { + producer.send(session.createTextMessage("hello")); + } + session.commit(); + connection.start(); + for (int i = 0; i < nmessages; i++) { + assertNotNull(consumer.receive(5000)); + } + session.rollback(); + assertNull(consumer.receive(100)); + } + + Queue dlq = server.locateQueue("topic.DLQ"); + Wait.assertEquals(nmessages, dlq::getMessageCount, 5000, 100); + + ActiveMQServer server2 = createServer(AMQP_PORT_2, false); + server2.getConfiguration().getAddressSettings().clear(); + server2.getConfiguration().addAddressSetting("#", new AddressSettings().setDeadLetterAddress(SimpleString.of("topic.DLQ")).setRedeliveryDelay(0).setMaxDeliveryAttempts(1)); + server2.getConfiguration().addQueueConfiguration(QueueConfiguration.of("topic.DLQ").setRoutingType(RoutingType.ANYCAST)); + server2.setIdentity("Server2"); + AMQPBrokerConnectConfiguration amqpConnection = new AMQPBrokerConnectConfiguration("test", "tcp://localhost:" + AMQP_PORT); + amqpConnection.addReceiver((AMQPReceiverBrokerConnectionElement) new AMQPReceiverBrokerConnectionElement().setMatchAddress("#.DLQ")); + server2.getConfiguration().addAMQPConnection(amqpConnection); + server2.start(); + + Queue dlqServer2 = server2.locateQueue("topic.DLQ"); + Wait.assertEquals(nmessages, dlqServer2::getMessageCount, 5000, 100); + } + + + @Test + public void testMismatchOnBridge() throws Exception { + + ActiveMQServer server = createServer(AMQP_PORT, false); + server.getConfiguration().getAddressSettings().clear(); + server.getConfiguration().addAddressSetting("#", new AddressSettings().setDeadLetterAddress(SimpleString.of("topic.DLQ")).setRedeliveryDelay(0).setMaxDeliveryAttempts(1)); + server.getConfiguration().addQueueConfiguration(QueueConfiguration.of("topic.DLQ").setRoutingType(RoutingType.ANYCAST)); + server.getConfiguration().addAddressConfiguration(new CoreAddressConfiguration().setName(getName()).addRoutingType(RoutingType.MULTICAST)); + server.setIdentity("Server1"); + server.start(); + + ConnectionFactory factory = CFUtil.createConnectionFactory("AMQP", "tcp://localhost:" + AMQP_PORT); + + long nmessages = 10; + + try (Connection connection = factory.createConnection()) { + connection.setClientID("myID"); + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageConsumer consumer = session.createDurableConsumer(session.createTopic(getName()), "myTopic"); + MessageProducer producer = session.createProducer(session.createTopic(getName())); + for (int i = 0; i < nmessages; i++) { + producer.send(session.createTextMessage("hello")); + } + session.commit(); + connection.start(); + for (int i = 0; i < nmessages; i++) { + assertNotNull(consumer.receive(5000)); + } + session.rollback(); + assertNull(consumer.receive(100)); + } + + Queue dlq = server.locateQueue("topic.DLQ"); + Wait.assertEquals(nmessages, dlq::getMessageCount, 5000, 100); + + ActiveMQServer server2 = createServer(AMQP_PORT_2, false); + server2.getConfiguration().getAddressSettings().clear(); + server2.getConfiguration().addAddressSetting("#", new AddressSettings().setDeadLetterAddress(SimpleString.of("topic.DLQ")).setRedeliveryDelay(0).setMaxDeliveryAttempts(1)); + server2.getConfiguration().addQueueConfiguration(QueueConfiguration.of("topic.DLQ").setRoutingType(RoutingType.ANYCAST)); + server2.setIdentity("Server2"); + AMQPBrokerConnectConfiguration amqpConnection = new AMQPBrokerConnectConfiguration("test", "tcp://localhost:" + AMQP_PORT); + amqpConnection.addBridge((AMQPBridgeBrokerConnectionElement) new AMQPBridgeBrokerConnectionElement().addBridgeFromAddressPolicy(new AMQPBridgeAddressPolicyElement().setRemoteAddress("topic.DLQ").setName("topic.DLQ")).addBridgeToQueuePolicy(new AMQPBridgeQueuePolicyElement().setRemoteAddress("topic.DLQ").setName("topic.DLQ")).setMatchAddress("topic.DLQ")); Review Comment: This doesn't do what you probably want it to do. It appears to be adding a bridge from the DLQ policy that would be attempting to pull messages from the remote broker if there was demand on the local DLQ. But it is also setting a bridge To policy that would then act to send any messages in the assigned brokers DLQ to the other broker. You've almost created an infinite loop but would need one more policy on the source broker but I'm guessing that isn't what you wanted. Also the setMatchAddress doesn't apply to AMQP bridge policy elements as that's just an unfortunate remnant of the broker connection API not having an initial separation of concerns amongst its features when it was created. I would love to remove those but it'd break the mirror bits configuration along with the Sender, Receivers and Peer configuration elements. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information, visit: https://activemq.apache.org/contact
