IBM MQ - 查询通道状态

时间:2017-03-27 08:30:32

标签: powershell ibm-mq

我尝试查询IBM MQ的通道状态。 PowerShell的下一个片段是我尝试这样做。 但我对如何获得非活动频道的状态表示怀疑。

&{
  $erroractionpreference='stop'
  try{
    $mq="${env:programfiles(x86)}\IBM\WebSphere MQ\bin\amqmdnet.dll"
    [void][reflection.assembly]::loadfrom($mq)
    $mqe=[ibm.wmq.mqenvironment]
    $mqe::hostname='localhost'
    $mqe::port=1414
    $mqe::channel='SYSTEM.DEF.SVRCONN'
    $mqc=[ibm.wmq.mqc]
    $mqe::properties[$mqc::transport_property]=$mqc::transport_mqseries_managed
    $mqe::properties[$mqc::ccsid_property]=$mqc::codeset_utf
    $qm=new-object ibm.wmq.mqqueuemanager EKR_33
    $ag=new-object ibm.wmq.pcf.pcfmessageagent
    $ag.connect($qm)
    $cmqcfc=[ibm.wmq.pcf.cmqcfc]
    $rq=new-object ibm.wmq.pcf.pcfmessage $cmqcfc::mqcmd_inquire_channel_names
    $rq.addparameter($cmqcfc::mqcach_channel_name,'*')
    $chst=@{}
    $ag.send($rq)|%{
      $_.getstringlistparametervalue($cmqcfc::mqcach_channel_names)|%{
        $chst[$_.trim()]='INACTIVE'
      }
    }
    $rq=new-object ibm.wmq.pcf.pcfmessage $cmqcfc::mqcmd_inquire_channel_status
    $rq.addparameter($cmqcfc::mqcach_channel_name,'*')
    $st=@{$cmqcfc::mqchs_binding='BINDING'
          $cmqcfc::mqchs_inactive='INACTIVE'
          $cmqcfc::mqchs_initializing='INITIALIZING'
          $cmqcfc::mqchs_paused='PAUSED'
          $cmqcfc::mqchs_requesting='REQUESTING'
          $cmqcfc::mqchs_retrying='RETRYING'
          $cmqcfc::mqchs_running='RUNNING'
          $cmqcfc::mqchs_starting='STARTING'    
          $cmqcfc::mqchs_stopped='STOPPED'
          $cmqcfc::mqchs_stopping='STOPPING'}
    $ag.send($rq)|%{
      $chst[$_.getstringparametervalue($cmqcfc::mqcach_channel_name).trim()]=
        $st[$_.getintparametervalue($cmqcfc::mqiach_channel_status)]
    }
    $chst|ft -a
  }finally{
    if($ag){$ag.disconnect()}
    if($qm){$qm.disconnect()}
  }
}

一些技术细节:
操作系统:Windows Server 2008 R2标准版 IBM Websphere MQ版本:7.1.0.5

2 JoshMc
实际上,代码段中没有任何错误 首先,我假定频道的非活动状态......

$rq=new-object ibm.wmq.pcf.pcfmessage $cmqcfc::mqcmd_inquire_channel_names
$rq.addparameter($cmqcfc::mqcach_channel_name,'*') $chst=@{} $ag.send($rq)|%{
  $_.getstringlistparametervalue($cmqcfc::mqcach_channel_names)|%{
    $chst[$_.trim()]='INACTIVE' # My guess
  }
} 

......然后才实际查询他们的状态。

$rq=new-object ibm.wmq.pcf.pcfmessage $cmqcfc::mqcmd_inquire_channel_status
$rq.addparameter($cmqcfc::mqcach_channel_name,'*')
$ag.send($rq)|%{ # I have never got channels with inactive status through sending the 'mqcmd_inquire_channel_names' message.
  $chst[$_.getstringparametervalue($cmqcfc::mqcach_channel_name).trim()]=
    $st[$_.getintparametervalue($cmqcfc::mqiach_channel_status)]

我不知道它是否正确。

1 个答案:

答案 0 :(得分:2)

如果频道是非活动的,这意味着它没有状态。也就是说,在“查询频道状态”命令中不会返回与该频道关联的记录。

换句话说。如果您在“查询频道状态”命令中没有为特定频道名称返回任何记录,则表示该频道处于非活动状态。

相关问题