4

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.

1 Answers1

3

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();
Petter Nordlander
  • 21,317
  • 5
  • 44
  • 81
  • Awesome, I just had started to review the BrokerService class trying to find something and I discovered the JmsConnector, so I was through all the hierachy until JmsQueue/TopicFactory but I wasn't able to infer how to set the properties to connect to the Queue Manager and all the other properties, thanks a lot. I'll try it and post the result – MarceStarlet Apr 06 '15 at 19:47
  • Great! The code posted is from a working setup so you should get it running. The WMQ can be a bit picky with security, channels etc, but I guess you know all that. – Petter Nordlander Apr 07 '15 at 08:07