Apache Camel MQXAQueueConnectionFactory

时间:2015-03-25 13:39:19

标签: apache-camel ibm-mq

好吧,我试图让MQXAQueueConnectionFactory工作,我已经从JmsComponent创建了一个扩展类,用于在将数据发送到队列时处理用户名和密码。 它确实将消息放入队列,但在我的情况下,我已经创建了一个路由器来测试XA,例如

 from("wmq:queue:incomingQueue")
     .process(new Processor(){
     ... Thread.sleep(20000)
     })
     .to("wmq:queue:outgoingQueue")
在睡觉的时候,我关闭了队列管理员。但是,当尝试从队列中获取未提交的消息时 显示QSTATUS(' qChainQueue')我得到 CURDEPTH(0),而我应该是1,因为我理解XA部分。

  • 我这样做完全错了吗?
  • 如何测试?

HelpClass处理WMQ:

public class WMQComponent extends JmsComponent {
    private final String username;
    private final String password;

    public WMQComponent(String hostname, int port, String username, String password,
                        String queueManager, String channel) throws JMSException {
        super();
        this.username = username;
        this.password = password;

        MQXAQueueConnectionFactory connectionFactory = new MQXAQueueConnectionFactory();
        connectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
        connectionFactory.setFailIfQuiesce(1);

        connectionFactory.setHostName(hostname);
        connectionFactory.setPort(port);
        connectionFactory.setQueueManager(queueManager);
        connectionFactory.setChannel(channel);

        setConnectionFactory(connectionFactory);
    }

    @Override
    public Endpoint createEndpoint(String uri) throws Exception {
        if (uri.contains("username") || uri.contains("password")) {
            throw new IllegalStateException("Username and password is set by the component");
        }
        if (uri.contains("?")) {
            return super.createEndpoint(uri + "&username=" + username + "&password=" + password);
        } else {
            return super.createEndpoint(uri + "?username=" + username + "&password=" + password);
        }
    }

}

出现以下错误:

2015-03-25 14:01:12,077 [ #2 - Multicast] INFO  dest_chain_ldap                - org.springframework.jms.IllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QMBATCHESB' with connection mode 'Client' and host name 'hostname.com'.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QMBATCHESB' with connection mode 'Client' and host name 'hostname.com'. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2059' ('MQRC_Q_MGR_NOT_AVAILABLE').
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:279)
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
    at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:228)
    at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:431)
    at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:385)
    at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:153)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:416)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:416)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
    at org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:732)
    at org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:82)
    at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:303)
    at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:288)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QMBATCHESB' with connection mode 'Client' and host name 'hostname.com'. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
    at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:496)
    at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:236)
    at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:430)
    at com.ibm.msg.client.wmq.internal.WMQXAConnection.<init>(WMQXAConnection.java:70)
    at com.ibm.msg.client.wmq.factories.WMQXAConnectionFactory.createV7ProviderConnection(WMQXAConnectionFactory.java:190)
    at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:6210)
    at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:278)
    at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6155)
    at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:144)
    at com.ibm.mq.jms.MQQueueConnectionFactory.createConnection(MQQueueConnectionFactory.java:223)
    at org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter.doCreateConnection(UserCredentialsConnectionFactoryAdapter.java:175)
    at org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter.createConnection(UserCredentialsConnectionFactoryAdapter.java:150)
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)
    ... 29 more
Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2059' ('MQRC_Q_MGR_NOT_AVAILABLE').
    at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:223)
    ... 41 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2059;AMQ9204: Connection to host 'hostname.com(1514)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2059;AMQ9213: A communications error for  occurred. [1=java.net.ConnectException[Connection refused: connect],3=hostname.com]],3=hostname.com(1514),5=RemoteTCPConnection.connnectUsingLocalAddress]
    at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1831)
    at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:345)
    ... 40 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2059;AMQ9213: A communications error for  occurred. [1=java.net.ConnectException[Connection refused: connect],3=hostname.com]
    at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:612)
    at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.protocolConnect(RemoteTCPConnection.java:940)
    at com.ibm.mq.jmqi.remote.internal.system.RemoteConnection.connect(RemoteConnection.java:1097)
    at com.ibm.mq.jmqi.remote.internal.system.RemoteConnectionPool.getConnection(RemoteConnectionPool.java:348)
    at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1503)
    ... 41 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection$2.run(RemoteTCPConnection.java:597)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:588)
    ... 45 more

2 个答案:

答案 0 :(得分:4)

代码2059的原因以及表明连接被拒绝的各种错误表明机械问题(即监听器未运行)或auths问题。

如果我试图调试这个,我要做的第一件事就是启用授权事件,频道事件以及您通常会启用的任何其他事件。如果您使用MQ Explorer,还要安装MS0P Plugin,这将允许您以人类可读的文本查看事件消息。

接下来,我将使用MQ示例程序进行测试。因为我总是安装完整的客户端而不是抓住jar文件,所以我有amqsputc可用。但是,Java类具有IVT(初始验证测试)程序。这些可确保侦听器正在运行,通道已配置且可用等。从v7.1开始,这还可确保将CHLAUTH规则设置为允许访问。从v8.0开始,或者如果安装了Capitalware出口,这也可以让我们测试用户ID和密码验证。

队列管理器的错误日志和事件消息应该提供良好的诊断,假设连接请求到达MQ。请务必查看特定于QMgr的错误日志和安装全局错误日志。

一旦我确认基本连接到位,我就会调整主机,端口,通道的客户端配置参数,如果指定了[shudder!] QMgr名称。假设这些是正确的并且已经证明基本连接有效,现在可以放心地测试应用程序。

同样的方法适用。首先确保应用程序的连接请求进入QMgr。如果它确实被拒绝,事件消息和错误日志将记录这一点以及原因。如果这些地方没有失败的迹象,那么应用程序就没有进入QMgr。 2059可以指示套接字被拒绝,监听器已启动,但QMgr不是,通道实例已达到最大值,或者在临时启动通道后它被QMgr关闭,通常是由于{{1 }} 规则。在任何情况下,事件消息和错误日志都会详细解释原因。

答案 1 :(得分:3)

所以我这样做有点不对,使用MQXAConnectionFactory还不够,但我必须创建JmsComponent作为事务处理。

尝试在运行应用程序时停止队列管理器并在处理消息时停止应用程序,并且它似乎按预期执行回滚。

结束

public static JmsComponent mqXAComponentTransacted(String hostname, int port, String username, String password,
                           String queueManager, String channel) throws JMSException {
    MQXAQueueConnectionFactory connectionFactory = new MQXAQueueConnectionFactory();
    connectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
    connectionFactory.setFailIfQuiesce(1);
    connectionFactory.setHostName(hostname);
    connectionFactory.setPort(port);
    connectionFactory.setQueueManager(queueManager);
    connectionFactory.setChannel(channel);

    UserCredentialsConnectionFactoryAdapter connectionFactoryAdapter=new UserCredentialsConnectionFactoryAdapter();
    connectionFactoryAdapter.setTargetConnectionFactory(connectionFactory);
    connectionFactoryAdapter.setUsername(username);
    connectionFactoryAdapter.setPassword(password);

    return JmsComponent.jmsComponentTransacted(connectionFactoryAdapter);
}

同样使用UserCredentialsConnectionFactoryAdapter,我不想使用Spring组件,但由于Jms包已经依赖它,因此使用它比我以前的解决方案更容易处理凭证。