尝试使用PHP连接到MQ;差不多了 [英] Trying to connect to MQ using PHP; almost there

查看:196
本文介绍了尝试使用PHP连接到MQ;差不多了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,过去的几天我一直在尝试解决这个似乎已被遗忘的问题,因为两个可用的PECL扩展(SAM和mqseries)都没有更新很长时间.我已经尝试了两者,由于SAM拒绝与我建立连接,因此mqseries在这一点上似乎使我走得最远,即使MQ在命令行中运行正常.我已经成功创建了到QueueManager的连接,但在下一步(MQOPEN)期间,我不幸失败了:

So I've spent the past few days trying to solve this that seems to have been forgotten since none of the two PECL extensions available (SAM and mqseries) have been updated for a long time. I've tried both and mqseries seems to get me the furthest at this point since SAM refuses to get me a connection, even though MQ works perfectly from the command line. I've successfully created a connection to my QueueManager and it's during the next step (MQOPEN) that I fail miserably:

$mqcno = array(
        'Version' => MQSERIES_MQCNO_VERSION_2,
        'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
        'MQCD' => array('ChannelName' => '[channel]',
        'ConnectionName' => '[ipnumber]([port])',
        'TransportType' => MQSERIES_MQXPT_TCP)
    );

mqseries_connx('MQED', $mqcno, $conn, $comp_code,$reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
    printf("Connx CompCode:%d Reason:%d Text:%s<br>\n", $comp_code, $reason, $reason);
    exit;
}

$mqods = array('ObjectName'=>'MYPUTQUEUE', 'ObjectType'=>MQOT_Q, 'ObjectQMgrName'=>'MYQUEUEMANAGER');
mqseries_open($conn, $mqods, 
          MQSERIES_MQOO_FAIL_IF_QUIESCING | MQSERIES_MQOO_OUTPUT,
          $obj, $comp_code,$reason);

这将导致$ reason填充2044,将其转换为MQRC_OD_ERROR或英文:在MQOPEN或MQPUT1调用上,对象描述符MQOD无效".

THis results in $reason being populated with 2044, which translates to MQRC_OD_ERROR, or in English: 'On the MQOPEN or MQPUT1 call, the object descriptor MQOD is not valid'.

问题是,我的MQOD怎么了?

So the question is, what's wrong with my MQOD?

更新#1:目前,此问题尚未解决.我从头开始重新构建了项目,以便在构建时解决所有问题.我仍然停留在返回2044的MQOPEN上.样本仍然可以从CLI完美地运行,因此,这肯定与PECL扩展的安装有关.如果那里有人成功安装并在较新的64位PHP5环境中针对MQ运行PHP,请通知我...

Update #1: At this point this is not resolved. I rebuilt the project from the ground up to resolve any issues at build time. I am still stuck on MQOPEN returning 2044. The samples still run flawlessly from CLI, so this is definitely tied to the installation of the PECL extension. If there's anyone out there who has successfully installed and are running PHP against MQ in a fairly recent 64-bit PHP5 environment please let me know...

更新#2:MQPUT1可以完美地工作,但无法收到响应.在这一点上,只是MQOPEN不起作用.问题是;是什么导致当MQPUT1工作时MQOPEN返回2044,据我所知包括MQOPEN?

Update #2: MQPUT1 works flawlessly with the problem that I can't receive my response. At this point, it's just MQOPEN that doesn't work. Question is; what is causing MQOPEN to return 2044 when MQPUT1 works, which I understand includes MQOPEN?

推荐答案

cmqch文件中的MQOD如下所示:

The MQOD in the cmqch file looks like this:

 /****************************************************************/
 /*  MQOD Structure -- Object Descriptor                         */
 /****************************************************************/


 typedef struct tagMQOD MQOD;
 typedef MQOD  MQPOINTER PMQOD;
 typedef PMQOD MQPOINTER PPMQOD;

 struct tagMQOD {
   MQCHAR4   StrucId;              /* Structure identifier */
   MQLONG    Version;              /* Structure version number */
   MQLONG    ObjectType;           /* Object type */
   MQCHAR48  ObjectName;           /* Object name */
   MQCHAR48  ObjectQMgrName;       /* Object queue manager name */
   MQCHAR48  DynamicQName;         /* Dynamic queue name */
   MQCHAR12  AlternateUserId;      /* Alternate user identifier */
   /* Ver:1 */
   MQLONG    RecsPresent;          /* Number of object records
                                      present */
   MQLONG    KnownDestCount;       /* Number of local queues opened
                                      successfully */
   MQLONG    UnknownDestCount;     /* Number of remote queues opened
                                      successfully */
   MQLONG    InvalidDestCount;     /* Number of queues that failed to
                                      open */
   MQLONG    ObjectRecOffset;      /* Offset of first object record
                                      from start of MQOD */
   MQLONG    ResponseRecOffset;    /* Offset of first response record
                                      from start of MQOD */
   MQPTR     ObjectRecPtr;         /* Address of first object record */
   MQPTR     ResponseRecPtr;       /* Address of first response
                                      record */
   /* Ver:2 */
   MQBYTE40  AlternateSecurityId;  /* Alternate security identifier */
   MQCHAR48  ResolvedQName;        /* Resolved queue name */
   MQCHAR48  ResolvedQMgrName;     /* Resolved queue manager name */
   /* Ver:3 */
   MQCHARV   ObjectString;         /* Object long name */
   MQCHARV   SelectionString;      /* Message Selector */
   MQCHARV   ResObjectString;      /* Resolved long object name*/
   MQLONG    ResolvedType;         /* Alias queue resolved object type */
   /* Ver:4 */
 };

 #define MQOD_DEFAULT {MQOD_STRUC_ID_ARRAY},\
                      MQOD_VERSION_1,\
                      MQOT_Q,\
                      {""},\
                      {""},\
                      {"AMQ.*"},\
                      {""},\
                      0,\
                      0,\
                      0,\
                      0,\
                      0,\
                      0,\
                      NULL,\
                      NULL,\
                      {MQSID_NONE_ARRAY},\
                      {""},\
                      {""},\
                      {MQCHARV_DEFAULT},\
                      {MQCHARV_DEFAULT},\
                      {MQCHARV_DEFAULT},\
                      MQOT_NONE

我想知道模块是否填写了默认值,并允许您使用哈希值进行覆盖.如果是这样,"DeviceName"真的是正确的键吗?我认为它将与WMQ字段名称或常量匹配.

I'm wondering if the module fills in the defaults and is letting you override then with the hash. If so, is 'DeviceName' really the right key? I would think it would match the WMQ field name or constant.

更新:根据提供的链接上的示例键确实与cmqc.h中的字段名称匹配.

Update: Per the example at the link provided, the hash key does indeed match the field name from the cmqc.h.

更新#2回应评论:cmqc.h中定义的对象类型为:

Update #2 respond to comment: Object types as defined in cmqc.h are:

 /* Object Types */
 #define MQOT_NONE       0
 #define MQOT_Q          1
 #define MQOT_NAMELIST   2
 #define MQOT_PROCESS    3
 #define MQOT_STORAGE_CLASS 4
 #define MQOT_Q_MGR      5
 #define MQOT_CHANNEL    6
 #define MQOT_AUTH_INFO  7
 #define MQOT_TOPIC      8
 #define MQOT_CF_STRUC   10
 #define MQOT_LISTENER   11
 #define MQOT_SERVICE    12
 #define MQOT_RESERVED_1 999

我对PHP,Perl和大多数其他类似工作的理解是,它们是对C API的非常薄的包装. Perl只是直接从cmqc.h和其他C包含文件生成大多数代码,因此所有字段名称和默认值都与那些包含文件完全匹配.该模块似乎采取了类似的方法,我希望在需要的地方使用定义的名称和字段默认值.

My understanding of the PHP, Perl and most other similar efforts is that they are a very thin wrapper over the C API. The Perl one simply generates most of the code directly from the cmqc.h and other C include files and therefore all the field names and defaults exactly match those include files. This module appears to have taken a similar approach and I would expect to use the defined names and field defaults where needed.

我在想类似的东西:

$mqods = array(
                 'StrucID'=>'OD  ',
                 'Version'=>1.
                 'ObjectType'=>1,
                 'ObjectName'=>'MYPUTQUEUE', 
                 'ObjectQMgrName'=>'MYQUEUEMANAGER'
                 'DynamicQName'='',
                 'AlternateUserId'='',
                 'RecsPresent'=>0,
                 'KnownDestCount'=>0,
                 'UnknownDestCount'=>0,
                 'InvalidDestCount'=>0,
                 'ObjectRecOffset'=>0,
                 'ResponseRecOffset'=>0,
                 'ObjectRecPtr'=>NULL,
                 'ResponseRecPtr'=>NULL
);

更新#3回应其他评论:

Update #3 respond to additional comments:

Q Mgr将接受任何版本的MQOD,但将退回到该功能级别.如果您使用v1,则可以测试它是否有效.如果要使用更高版本的MQOD,则需要将其他字段添加到哈希中.

The Q Mgr will accept any version of the MQOD but will fall back to that level of functionality. If you use v1 you can test out that it works. If you want to use later versions of the MQOD then you will need to add the additional fields to the hash.

2009年是连接中断".本质上,QMgr不喜欢某些东西,因此终止了您的连接.通常,该返回代码的有意义的错误消息在/var/mqm/qmgrs/<qmgrname>/errors/AMQEER01.LOG中.

The 2009 is "Connection Broken." Essentially the QMgr didn't like something and terminated your connection. Usually the meaningful error messages for that return code are in /var/mqm/qmgrs/<qmgrname>/errors/AMQEER01.LOG.

这篇关于尝试使用PHP连接到MQ;差不多了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆