mirror of
https://github.com/apache/activemq.git
synced 2025-02-28 05:09:07 +00:00
https://issues.apache.org/jira/browse/AMQ-3685 - sanitize brokerUrl in BrokerInfo as it can break failover url when cluster update is used
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1236707 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3b19c71935
commit
4d3af76ee6
@ -16,14 +16,6 @@
|
||||
*/
|
||||
package org.apache.activemq.broker;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.management.ObjectName;
|
||||
import org.apache.activemq.broker.jmx.ManagedTransportConnector;
|
||||
import org.apache.activemq.broker.jmx.ManagementContext;
|
||||
import org.apache.activemq.broker.region.ConnectorStatistics;
|
||||
@ -43,6 +35,15 @@ import org.apache.activemq.util.ServiceSupport;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @org.apache.xbean.XBean
|
||||
*
|
||||
@ -208,7 +209,7 @@ public class TransportConnector implements Connector, BrokerServiceAware {
|
||||
brokerInfo.setBrokerId(broker.getBrokerId());
|
||||
brokerInfo.setPeerBrokerInfos(broker.getPeerBrokerInfos());
|
||||
brokerInfo.setFaultTolerantConfiguration(broker.isFaultTolerantConfiguration());
|
||||
brokerInfo.setBrokerURL(getServer().getConnectURI().toString());
|
||||
brokerInfo.setBrokerURL(getPublishableConnectString(getServer().getConnectURI()));
|
||||
getServer().setAcceptListener(new TransportAcceptListener() {
|
||||
public void onAccept(final Transport transport) {
|
||||
try {
|
||||
@ -256,10 +257,13 @@ public class TransportConnector implements Connector, BrokerServiceAware {
|
||||
|
||||
LOG.info("Connector " + getName() + " Started");
|
||||
}
|
||||
|
||||
|
||||
public String getPublishableConnectString() throws Exception {
|
||||
return getPublishableConnectString(getConnectUri());
|
||||
}
|
||||
|
||||
public String getPublishableConnectString(URI theConnectURI) throws Exception {
|
||||
String publishableConnectString = null;
|
||||
URI theConnectURI = getConnectUri();
|
||||
if (theConnectURI != null) {
|
||||
publishableConnectString = theConnectURI.toString();
|
||||
// strip off server side query parameters which may not be compatible to
|
||||
|
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 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.usecases;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.JmsMultipleBrokersTestSupport;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
|
||||
public class ClientRebalanceTest extends JmsMultipleBrokersTestSupport {
|
||||
private static final Logger LOG = Logger.getLogger(ClientRebalanceTest.class);
|
||||
private static final String QUEUE_NAME = "Test.ClientRebalanceTest";
|
||||
|
||||
public void testRebalance() throws Exception {
|
||||
createBroker(new ClassPathResource("org/apache/activemq/usecases/rebalance-broker1.xml"));
|
||||
createBroker(new ClassPathResource("org/apache/activemq/usecases/rebalance-broker2.xml"));
|
||||
|
||||
startAllBrokers();
|
||||
|
||||
brokers.get("b1").broker.waitUntilStarted();
|
||||
|
||||
|
||||
LOG.info("Starting connection");
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61617)?randomize=false");
|
||||
Connection conn = factory.createConnection();
|
||||
conn.start();
|
||||
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Queue theQueue = session.createQueue(QUEUE_NAME);
|
||||
MessageProducer producer = session.createProducer(theQueue);
|
||||
MessageConsumer consumer = session.createConsumer(theQueue);
|
||||
Message message = session.createTextMessage("Test message");
|
||||
producer.send(message);
|
||||
Message msg = consumer.receive(2000);
|
||||
assertNotNull(msg);
|
||||
|
||||
|
||||
// introduce third broker
|
||||
createBroker(new ClassPathResource("org/apache/activemq/usecases/rebalance-broker3.xml"));
|
||||
brokers.get("b3").broker.waitUntilStarted();
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
|
||||
LOG.info("Stopping broker 1");
|
||||
|
||||
|
||||
brokers.get("b1").broker.stop();
|
||||
brokers.get("b1").broker.waitUntilStopped();
|
||||
|
||||
Thread.sleep(1000);
|
||||
// should reconnect to some of the remaining brokers
|
||||
producer.send(message);
|
||||
msg = consumer.receive(2000);
|
||||
assertNotNull(msg);
|
||||
|
||||
LOG.info("Stopping broker 2");
|
||||
|
||||
brokers.get("b2").broker.stop();
|
||||
brokers.get("b2").broker.waitUntilStopped();
|
||||
|
||||
// should reconnect to broker3
|
||||
producer.send(message);
|
||||
msg = consumer.receive(2000);
|
||||
assertNotNull(msg);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd" xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<broker brokerName="b1" persistent="false" useJmx="false" xmlns="http://activemq.apache.org/schema/core">
|
||||
<networkConnectors>
|
||||
<networkConnector name="b1_b2" uri="static://tcp://localhost:61617" duplex="false"/>
|
||||
<networkConnector name="b1_b3" uri="static://tcp://localhost:61618"></networkConnector>
|
||||
</networkConnectors>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://localhost:61616?transport.closeAsync=false" rebalanceClusterClients="true" updateClusterClients="true"/>
|
||||
</transportConnectors>
|
||||
</broker>
|
||||
</beans>
|
@ -0,0 +1,14 @@
|
||||
<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd" xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<broker brokerName="b2" persistent="false" useJmx="false" xmlns="http://activemq.apache.org/schema/core">
|
||||
|
||||
<networkConnectors>
|
||||
<networkConnector name="b2_b1" uri="static://tcp://localhost:61616" duplex="false"/>
|
||||
<networkConnector name="b2_b3" uri="static://tcp://localhost:61618"></networkConnector>
|
||||
</networkConnectors>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://localhost:61617?transport.closeAsync=false" rebalanceClusterClients="true" updateClusterClients="true"/>
|
||||
</transportConnectors>
|
||||
</broker>
|
||||
</beans>
|
@ -0,0 +1,13 @@
|
||||
<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd" xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<broker brokerName="b3" persistent="false" useJmx="true" xmlns="http://activemq.apache.org/schema/core">
|
||||
<networkConnectors>
|
||||
<networkConnector name="b3_b1" uri="static://tcp://localhost:61616"></networkConnector>
|
||||
<networkConnector name="b3_b2" uri="static://tcp://localhost:61617"></networkConnector>
|
||||
</networkConnectors>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://localhost:61618?transport.closeAsync=false" rebalanceClusterClients="true" updateClusterClients="true"/>
|
||||
</transportConnectors>
|
||||
</broker>
|
||||
</beans>
|
Loading…
x
Reference in New Issue
Block a user