ActiveMQ bridge connector to WebSphereMQ without using XML config

烂漫一生 提交于 2019-12-05 15:13:59

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!