温馨提示:本文翻译自stackoverflow.com,查看原文请点击:perl - Sharing queue manager connection among threads
perl ibm-mq

perl - 在线程之间共享队列管理器连接

发布于 2020-03-27 11:30:26

我正在使用MQSeries 9客户端上的Perl MQClient :: MQSeries模块和CentOS 7系统上的服务器安装连接到IBM MQSeries服务器。

我使用两个线程从两个线程连接到队列管理器

sub connectToQueuemanager
{
    my ($host, $queuemanager, $channel) = @_;

    my $coption = {
                  'ChannelName'    => $channel,
                  'TransportType'  => 'TCP',
                  'ConnectionName' => $host
                  };

    my $compcode = 0;
    my $compres  = 0;
    my $hconn    = MQCONNX ($queuemanager, {'ClientConn' => $coption}, $compcode, $compres);
}

这在第一个线程中工作正常,但在第二个线程中工作不正常-结果是我得到代码2002(“应用程序已连接。”)。MQSeries版本6没有出现此问题。

As of https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.5.0/com.ibm.mq.dev.doc/q025940_.htm this could be solved by setting MQCNO_HANDLE_SHARE_NO_BLOCK in the connection options. The Perl module MQSeries.pm lists this as one of the known constants, but I found no way to set this in the MQCONNX connection call.

How can I set this option in the MQCONNX call?

查看更多

查看更多

提问者
André
被浏览
127
Morag Hughson 2019-07-04 06:37

I don't know Perl and I haven't used the Perl MQSeries interface, but reading the help here, it says the following:-

The $ConnectOpts value is a hash reference, with keys corresponding to the fields of the MQCO structure. This is an input value only.

使用$ ConnectOpts,可以提供两个内部数据结构:ClientConn和SSLConfig。这些提供对MQCNO和MQSCO选项的访问。

不幸的是,这不是很有帮助,因为没有MQCO结构之类的东西。我认为这可能意味着MQCNO。然后稍后说ClientConn提供对MQCNO结构的访问,我认为这可能意味着挂在MQCNO结构之外的MQCD结构(因为这肯定是ClientConn的内容)。

您的问题归结为“我将MQCNO_ *选项标志放在哪里?” 我不认为答案是将它们放入MQCD ClientConn结构中,因为在本机MQ API中找不到它们。

鉴于我不知道如何在Perl中进行编程,仅使用我的MQ专业知识,我认为代码应该是这样。如果无法编译,我事先表示歉意,但我希望这会引导您找到解决方案。如果答案很接近,请随时编辑我的答案,但是由于我的Perl的不足,我的答案不太正确。

sub connectToQueuemanager
{
    my ($host, $queuemanager, $channel) = @_;

    my $coption = {
                  'ChannelName'    => $channel,
                  'TransportType'  => 'TCP',
                  'ConnectionName' => $host
                  };

    my $compcode = 0;
    my $compres  = 0;
    my $hconn    = MQCONNX ($queuemanager, {'ClientConn' => $coption,
                                            'Options' => MQCNO_HANDLE_SHARE_NO_BLOCK},
                                            $compcode, $compres);
}