I want to create a broker to broker connection between ActiveMQ and WebSphere MQ in an embedded broker. I know that exists the network connector in activemq to do that (broker-to-broker), but I don't know how to configure it to connect to WebSphere MQ. Doing a search in the web I found some different ways to do with XML configuration and I noticed that the XML tags used does not refer the network connector, but refers a <jmsBridgeConnectors>
, so I do a research about this bridge connector by using java code but I wasn't able to find something that points me about how to do that.
Is there an explicit way to configure a bridge connector in ActiveMQ to a WebSphere MQ, for an embedded broker by using java code instead to use the XML configuration?
I know that is possible by using XML configuration, but, what if I am implementing an embedded broker (as I've mentioned before), and I want to configure the broker instance with a bridge connector to WebSphere MQ with java code, Does ActiveMQ provide a Class or Interface on the API to do this?
This is what I have done to connect two activemq brokers
try {
getBroker().addConnector("tcp://localhost:61616");
getBroker().addNetworkConnector("static:(tcp://remotBroker:61616)");
} catch (Exception e) {
logger.error("Unexpected ERROR, connection lost.");
e.printStackTrace();
}
One TransportConnector to listen in port 61616 and one Network connector to establish connection from my local broker to the remoteBroker, both brokers are instances of activemq. Now I want a connection from my ActiveMQ local broker to WebSphere MQ broker using java code, no XML.
It's pretty simple. The following example will send all messages on the ActiveMQ queue QUEUE42 to a remote WebSphere MQ broker. Change connection settings.
This requires you to have some WMQ libs on your classpath: com.ibm.mq.jar and com.ibm.mqjms.jar (at least). The trick is to simply create a JmsQueueConnector with a QueueConnectionFactory (to WMQ) and whatever inbound/outbound bridges you want. The bridges are simply queue names that will be copied.
BrokerService broker = new BrokerService();
broker.setBrokerName("amqbroker");
broker.setPersistent(false);
broker.setTransportConnectorURIs(new String[] {"tcp://localhost:61616"});
// setup bridge
JmsQueueConnector qCon = new JmsQueueConnector();
JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
JmsQueueConnectionFactory cf = ff.createQueueConnectionFactory();
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "192.168.13.151");
cf.setIntProperty(WMQConstants.WMQ_PORT, 1414);
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "SYSTEM.DEF.SVRCONN");
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "SUPERHERO");
qCon.setOutboundQueueConnectionFactory(cf);
OutboundQueueBridge outBridge1 = new OutboundQueueBridge("QUEUE42");
qCon.setOutboundQueueBridges(new OutboundQueueBridge[] {outBridge1});
broker.setJmsBridgeConnectors(new JmsConnector[] {qCon});
broker.start();
来源:https://stackoverflow.com/questions/29476063/activemq-bridge-connector-to-webspheremq-without-using-xml-config