连接 Java 客户端到 IBM MQ 时出现 JMSException。

huangapple go评论110阅读模式
英文:

Getting JMSException connecting to IBM MQ from Java client

问题

我们正在尝试从Java客户端连接到IBM MQ。我们使用JMSAdmin工具为JNDI上下文生成了.bindings文件。在连接到IBM MQ时,我们遇到了以下异常:

ERR fmbaJMS JMSException: JMSWMQ0018: 无法使用连接模式“Client”和主机名“null”连接到队列管理器“<queue manager name>”

发送的主机名参数为空,而.bindings文件中正确地包含以下内容:

mq/RefAddr/30/Content=localhost(51410)
mq/RefAddr/30/Type=CRSHOSTS 

这些条目指向本地主机和端口51410。

英文:

We are trying to connect to IBM MQ from a Java client. We have generated .bindings for JNDI context using the JMSAdmin utility. When connecting to IBM MQ we are getting following exception:

ERR fmbaJMS JMSException: JMSWMQ0018: Failed to connect to queue manager '<queue manager name>' with connection mode 'Client' and host name 'null' 

Host name parameter sent is null while .bindings file correctly have

mq/RefAddr/30/Content=localhost(51410)
mq/RefAddr/30/Type=CRSHOSTS 

Entries pointing to localhost and port 51410.

答案1

得分: 2

你的.bindings文件看起来不正确。您用什么JMSAdmin命令来创建它?

MQ0018: 无法连接到队列管理器'bt.qm.ccxp0'。

这是您的队列管理器名称还是QCF?注意:根据IBM最佳实践,队列管理器名称应为大写。

要定义一个QCF(队列连接工厂),您可以执行以下操作:

DEFINE QCF(myQCF) QMANAGER(MQA1) CHANNEL(TEST.CHL) HOSTNAME(127.0.0.1) PORT(1414) TRANSPORT(CLIENT) FAILIFQUIESCE(YES)

要定义一个JMS队列,您可以执行以下操作:

DEFINE Q(mqs.dev.test.q) QUEUE(TEST.Q1) QMANAGER(MQA1) TARGCLIENT(JMS) FAILIFQUIESCE(YES)

然后在您的代码中,您将执行以下操作从MQ JNDI加载对象:

Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/C:/JNDI-Directory");

Context ctx = new InitialContext(env);

QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup("myQCF");
Queue q = (Queue) ctx.lookup("mqs.dev.test.q");

英文:

Your .bindings file does not look right. What was the JMSAdmin command you used to create it?

> MQ0018: Failed to connect to queue manager 'bt.qm.ccxp0'

Is that your queue manager name or QCF? Note: As per the IBM Best Practises, queue manager names should be in uppercase.

To define a QCF (Queue Connection Factory), you would do:

DEFINE QCF(myQCF) QMANAGER(MQA1) CHANNEL(TEST.CHL) HOSTNAME(127.0.0.1) PORT(1414) TRANSPORT(CLIENT) FAILIFQUIESCE(YES)

To define a JMS queue, you would do:

DEFINE Q(mqs.dev.test.q) QUEUE(TEST.Q1) QMANAGER(MQA1) TARGCLIENT(JMS) FAILIFQUIESCE(YES)

Then in your code, you would do the following to load the objects from the MQ JNDI:

Hashtable&lt;String,String&gt; env = new Hashtable&lt;String,String&gt;();
env.put(Context.INITIAL_CONTEXT_FACTORY, &quot;com.sun.jndi.fscontext.RefFSContextFactory&quot;);
env.put(Context.PROVIDER_URL, &quot;file:/C:/JNDI-Directory&quot;);

Context ctx = new InitialContext(env);

QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup(&quot;myQCF&quot;);
Queue q = (Queue) ctx.lookup(&quot;mqs.dev.test.q&quot;);

huangapple
  • 本文由 发表于 2020年9月15日 17:44:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63899215.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定