// Ensure that we are connecting using tcp
if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
config.setBrokerName(localBroker.getBrokerName());
DemandForwardingBridge bridge = new DemandForwardingBridge(config, TransportFactory.connect(localURI), TransportFactory.connect(remoteURI)) {
protected void serviceLocalCommand(Command command) {
if (command.isMessageDispatch()) {
// Keep track of the number of message dispatches
// through the bridge
msgDispatchCount.incrementAndGet();
}
super.serviceLocalCommand(command);
}
};
bridges.add(bridge);
bridge.start();
} else {
throw new Exception("Remote broker or local broker is not using tcp connectors");
}
} else {
throw new Exception("Remote broker or local broker has no registered connectors.");