1 18 package org.apache.activemq.usecases; 19 20 import org.apache.activemq.broker.BrokerService; 21 import org.apache.activemq.broker.TransportConnector; 22 import org.apache.activemq.network.DemandForwardingBridge; 23 import org.apache.activemq.network.NetworkBridgeConfiguration; 24 import org.apache.activemq.transport.TransportFactory; 25 26 import java.util.List ; 27 import java.util.Iterator ; 28 import java.util.ArrayList ; 29 import java.net.URI ; 30 31 34 public class MultiBrokersMultiClientsUsingTcpTest extends MultiBrokersMultiClientsTest { 35 protected List bridges; 36 37 protected void bridgeAllBrokers(String groupName) throws Exception { 38 for (int i=1; i<=BROKER_COUNT; i++) { 39 for (int j=1; j<=BROKER_COUNT; j++) { 40 if (i != j) { 41 bridgeBrokers("Broker" + i, "Broker" + j); 42 } 43 } 44 } 45 46 MAX_SETUP_TIME = 5000; 47 } 48 49 protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception { 50 List remoteTransports = remoteBroker.getTransportConnectors(); 51 List localTransports = localBroker.getTransportConnectors(); 52 53 URI remoteURI, localURI; 54 if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) { 55 remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri(); 56 localURI = ((TransportConnector)localTransports.get(0)).getConnectUri(); 57 58 if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) { 60 NetworkBridgeConfiguration config = new NetworkBridgeConfiguration(); 61 config.setBrokerName(localBroker.getBrokerName()); 62 DemandForwardingBridge bridge = new DemandForwardingBridge(config,TransportFactory.connect(localURI), 63 TransportFactory.connect(remoteURI)); 64 bridges.add(bridge); 65 66 bridge.start(); 67 } else { 68 throw new Exception ("Remote broker or local broker is not using tcp connectors"); 69 } 70 } else { 71 throw new Exception ("Remote broker or local broker has no registered connectors."); 72 } 73 } 74 75 public void setUp() throws Exception { 76 super.setUp(); 77 78 int j=0; 80 for (Iterator i=brokers.values().iterator(); i.hasNext();) { 81 ((BrokerItem)i.next()).broker.addConnector("tcp://localhost:" + (61616 + j++)); 82 } 83 84 bridges = new ArrayList (); 85 } 86 } 87 | Popular Tags |