Class WMQ::QueueManager
In: ext/wmq.c
ext/lib/wmq_temp.rb
Parent: Object

Methods

Public Class methods

Connect to the queue manager, then disconnect once the supplied code block completes

Parameters:

  • Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
  • Summary of parameters and their WebSphere MQ equivalents:
 WMQ::QueueManager.connect(                             # WebSphere MQ Equivalents:
  :q_mgr_name         => 'queue_manager name',
  :exception_on_error => true,                          # n/a
  :connect_options    => WMQ::MQCNO_FASTBATH_BINDING    # MQCNO.Options

  :trace_level        => 0,                             # n/a

  # Common client connection parameters
  :channel_name       => 'svrconn channel name',        # MQCD.ChannelName
  :connection_name    => 'localhost(1414)',             # MQCD.ConnectionName
  :transport_type     => WMQ::MQXPT_TCP,                # MQCD.TransportType

  # Advanced client connections parameters
  :max_msg_length     => 65535,                         # MQCD.MaxMsgLength
  :security_exit      => 'Name of security exit',       # MQCD.SecurityExit
  :send_exit          => 'Name of send exit',           # MQCD.SendExit
  :receive_exit       => 'Name of receive exit',        # MQCD.ReceiveExit
  :security_user_data => 'Security exit User data',     # MQCD.SecurityUserData
  :send_user_data     => 'Send exit user data',         # MQCD.SendUserData
  :receive_user_data  => 'Receive exit user data',      # MQCD.ReceiveUserData
  :heartbeat_interval =>  1,                            # MQCD.HeartbeatInterval
  :remote_security_id => 'Remote Security id',          # MQCD.RemoteSecurityId
  :ssl_cipher_spec    => 'SSL Cipher Spec',             # MQCD.SSLCipherSpec
  :keep_alive_interval=> -1,                            # MQCD.KeepAliveInterval
  :mode_name          => 'LU6.2 Mode Name',             # MQCD.ModeName
  :tp_name            => 'LU6.2 Transaction pgm name',  # MQCD.TpName
  :user_identifier    => 'LU 6.2 Userid',               # MQCD.UserIdentifier
  :password           => 'LU6.2 Password',              # MQCD.Password
  :long_remote_user_id=> 'Long remote user identifier', # MQCD.LongRemoteUserId (Ptr, Length)
  :ssl_peer_name      => 'SSL Peer name',               # MQCD.SSLPeerName (Ptr, Length)

  # SSL Options
  :key_repository     => '/var/mqm/qmgrs/.../key',        # MQSCO.KeyRepository
  :crypto_hardware    => 'GSK_ACCELERATOR_NCIPHER_NF_ON', # MQSCO.CryptoHardware
  )

Optional Parameters

  • :q_mgr_name => String
    • Name of the existing WebSphere MQ Queue Manager to connect to
    • Default:
       - Server connections will connect to the default queue manager
       - Client connections will connect to whatever queue
         manager is found at the host and port number as specified
         by the connection_name
      
  • :exception_on_error => true or false
       Determines whether WMQ::WMQExceptions are thrown whenever
       an error occurs during a WebSphere MQ operation (connect, put, get, etc..)
    
       Default: true
    
  • :connect_options => FixNum
    • One or more of the following values:
        WMQ::MQCNO_STANDARD_BINDING
        WMQ::MQCNO_FASTPATH_BINDING
        WMQ::MQCNO_SHARED_BINDING
        WMQ::MQCNO_ISOLATED_BINDING
        WMQ::MQCNO_ACCOUNTING_MQI_ENABLED
        WMQ::MQCNO_ACCOUNTING_MQI_DISABLED
        WMQ::MQCNO_ACCOUNTING_Q_ENABLED
        WMQ::MQCNO_ACCOUNTING_Q_DISABLED
        WMQ::MQCNO_NONE
      
    • Multiple values can be or’d together. E.g.
        :connect_options=>WMQ::MQCNO_FASTPATH_BINDING | WMQ::MQCNO_ACCOUNTING_MQI_ENABLED
      
    • Please see the WebSphere MQ MQCNO data type documentation for more details
       Default: WMQ::MQCNO_NONE
      
  • :trace_level => FixNum
    • Turns on low-level tracing of the WebSphere MQ API calls to stdout.
      • 0: No tracing
      • 1: MQ API tracing only (MQCONNX, MQOPEN, MQPUT, etc..)
      • 2: Include Ruby WMQ tracing
      • 3: Verbose logging (Recommended for when reporting problems in Ruby WMQ)
       Default: 0
      

Common Client Connection Parameters (Client connections only)

  • :connection_name => String (Mandatory for client connections)
    • Connection name, made up of the host name (or ip address) and the port number
    • E.g.
        'mymachine.domain.com(1414)'
        '192.168.0.1(1417)'
      
  • :channel_name => String
    • Name of SVRCONN channel defined on the QueueManager for Client Connections
    • Default Value:
        'SYSTEM.DEF.SVRCONN'
      
  • :transport_type => WMQ::MQXPT_TCP, # MQCD.TransportType
    • Valid Values:
        WMQ::MQXPT_LOCAL
        WMQ::MQXPT_LU62
        WMQ::MQXPT_TCP
        WMQ::MQXPT_NETBIOS
        WMQ::MQXPT_SPX
        WMQ::MQXPT_DECNET
        WMQ::MQXPT_UDP
      
    • Default Value:
        WMQ::MQXPT_TCP
      

For the Advanced Client Connection parameters, please see the WebSphere MQ documentation

Note:

  • If an exception is not caught in the code block, the current unit of work is automatically backed out, before disconnecting from the queue manager.

Local Server Connection Example:

  require 'wmq/wmq'

  WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
    qmgr.put(:q_name=>'TEST.QUEUE', :data => 'Hello World')
  end

Client Connection Example:

  require 'wmq/wmq_client'

  WMQ::QueueManager.connect(
              :channel_name    => 'SYSTEM.DEF.SVRCONN',
              :transport_type  => WMQ::MQXPT_TCP,
              :connection_name => 'localhost(1414)' ) do |qmgr|
    qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|

      message = WMQ::Message.new
      if queue.get(:message => message)
        puts "Data Received: #{message.data}"
      else
        puts 'No message available'
      end
    end
  end

Parameters:

  • Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
  • See QueueManager.new for details on all the parameters

Note:

  • It is not recommended to use this method, rather use QueueManager.connect, since it will automatically disconnect from the queue manager. It also deals with backing out the current unit of work in the event of an unhandled exception. E.g. Syntax Error
  • RuntimeError and ArgumentError exceptions are always thrown regardless of the value of :exception_on_error

Todo:

  • Support multiple send and receive exits

Public Instance methods

Open the specified queue, then close it once the supplied code block has completed

Parameters:

  • Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
  • See Queue.open for the complete list of parameters, except that :queue_manager is not required since it is supplied automatically by this method

Example:

  require 'wmq/wmq_client'

  WMQ::QueueManager.connect(:q_mgr_name=>'REID', :connection_name=>'localhost(1414)') do |qmgr|
    qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
      queue.put(:data => 'Hello World')
    end
  end

Backout the current unit of work for this QueueManager instance

Since the last commit or rollback any messages put to a queue under synchpoint will be removed and any messages retrieved under synchpoint from any queues will be returned

Note:

  • backout will have no effect if all put and get operations were performed without specifying :sync => true

Returns:

Throws:

Advanced WebSphere MQ Use:

Begin a unit of work between this QueueManager instance and another resource such as a Database

Starts a new unit of work under which put and get can be called with with the parameter :sync => true

Returns:

Throws:

Commit the current unit of work for this QueueManager instance

Note:

  • commit will have no effect if all put and get operations were performed without specifying :sync => true

Returns:

Throws:

Return the completion code for the last MQ operation

Returns => FixNum

  • WMQ::MQCC_OK 0
  • WMQ::MQCC_WARNING 1
  • WMQ::MQCC_FAILED 2
  • WMQ::MQCC_UNKNOWN -1

Before working with any queues, it is necessary to connect to the queue manager.

Returns:

Throws:

Returns whether this QueueManager instance is currently connected to a WebSphere MQ queue manager

Returns:

  • true : This QueueManager instance is connected to a local or remote queue manager
  • false: This QueueManager instance is not currently connected to a local or remote queue manager

Disconnect from this QueueManager instance

Returns:

Throws:

Returns whether this QueueManager instance is set to throw a WMQ::WMQException whenever an MQ operation fails

Returns:

Note:

  • RuntimeError and ArgumentError exceptions are always thrown regardless of the value of exception_on_error

Execute an Administration command against the local queue manager

Parameters:

  • Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
  • The entire MQ Administration interface has been implemented. Rather than re-documentation the hundreds of options, a standard convention has been used to map the MQ constants to Symbols in Ruby.

For all MQ Admin commands, just drop the MQAI_ off the front and convert the command name to lower case.

  • E.g. MQAI_INQUIRE_Q becomes inquire_q

For the hundreds of parameters, a similiar technique is followed. Remove the prefixes: MQCA_, MQIA_, etc.. and convert to lowercase

  • E.g. MQCA_Q_NAME becomes :q_name

Example

  WMQ::QueueManager.connect do |qmgr|
    result = qmgr.execute(
               :command         => :inquire_q,
               :q_name          => 'MY.LOCAL.QUEUE',
               :q_type          => WMQ::MQQT_LOCAL,
               :current_q_depth => nil
               )
    # OR, we can replace the method name execute with the MQAI command:
    result = qmgr.inquire_q(
               :q_name          => 'MY.LOCAL.QUEUE',
               :q_type          => WMQ::MQQT_LOCAL,
               :current_q_depth => nil
               )

Complete Example:

  require 'wmq/wmq'
  require 'wmq/wmq_const_admin'
  WMQ::QueueManager.connect(:q_mgr_name=>'REID', :connection_name=>'localhost(1414)') do |qmgr|
    qmgr.reset_q_stats(:q_name=>'*').each {|item| p item }
  end

Some one line examples

  qmgr.inquire_q(:q_name=>'TEST*').each {|item| p item }

  qmgr.inquire_q(:q_name=>'TEST*', :q_type=>WMQ::MQQT_LOCAL, :current_q_depth=>nil).each {|item| p item }

  qmgr.inquire_process(:process_name=>'*').each {|item| p item }

  qmgr.ping_q_mgr.each {|item| p item }

  qmgr.refresh_security.each {|item| p item }

  qmgr.inquire_q_status(:q_name=>'TEST*', :q_status_type=>:q_status, :q_status_attrs=>:process_id).each {|item| p item }

  qmgr.start_channel_listener.each {|item| p item }

  qmgr.inquire_channel_status(:channel_name=>'*').each {|item| p item }

Execute any MQSC command against the queue manager

Example

  require 'wmq/wmq'
  require 'wmq/wmq_const_admin'
  WMQ::QueueManager.connect(:q_mgr_name=>'REID', :connection_name=>'localhost(1414)') do |qmgr|
    qmgr.mqsc('dis ql(*)').each {|item| p item }
  end

Returns the QueueManager name => String

Open the specified queue, then close it once the supplied code block has completed

Parameters:

  • Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
  • See Queue.open for the complete list of parameters, except that :queue_manager is not required since it is supplied automatically by this method

Example:

  require 'wmq/wmq_client'

  WMQ::QueueManager.connect(:q_mgr_name=>'REID', :connection_name=>'localhost(1414)') do |qmgr|
    qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
      queue.put(:data => 'Hello World')
    end
  end

Put a message to the queue without having to first open the queue Recommended for reply queues that change frequently

  • parameters: a Hash consisting of one or more of the following parameters

Summary of parameters and their WebSphere MQ equivalents

 queue.get(                                             # WebSphere MQ Equivalents:
  :q_name             => 'Queue Name',                  # MQOD.ObjectName
  :q_name             => { queue_manager=>'QMGR_name',  # MQOD.ObjectQMgrName
                           q_name       =>'q_name'}
  :message            => my_message,                    # n/a : Instance of Message
  :data               => "Hello World",                 # n/a : Data to send
  :sync               => false,                         # MQGMO_SYNCPOINT
  :new_id             => true,                          # MQPMO_NEW_MSG_ID & MQPMO_NEW_CORREL_ID
  :new_msg_id         => true,                          # MQPMO_NEW_MSG_ID
  :new_correl_id      => true,                          # MQPMO_NEW_CORREL_ID
  :fail_if_quiescing  => true,                          # MQOO_FAIL_IF_QUIESCING
  :options            => WMQ::MQPMO_FAIL_IF_QUIESCING   # MQPMO_*
  )

Mandatory Parameters

  • :q_name => String
    • Name of the existing WebSphere MQ local queue, model queue or remote queue to open
    • To open remote queues for which a local remote queue definition is not available pass a Hash as q_name (see q_name => Hash)
        OR
      
  • :q_name => Hash
    • q_name => String
      • Name of the existing WebSphere MQ local queue, model queue or remote queue to open
    • :q_mgr_name => String
      • Name of the remote WebSphere MQ queue manager to send the message to.
      • This allows a message to be written to a queue on a remote queue manager where a remote queue definition is not defined locally
      • Commonly used to reply to messages from remote systems
      • If q_mgr_name is the same as the local queue manager name then the message is merely written to the local queue.
      • Note: q_mgr_name should only be supplied when putting messages to the queue.
          It is not possible to get messages from a queue on a queue manager other
          than the currently connected queue manager
        
  • Either :message or :data must be supplied
    • If both are supplied, then :data will be written to the queue. The data in :message will be ignored

Optional Parameters

  • :data => String
    • Data to be written to the queue. Can be binary or text data
  • :message => Message
    • An instance of the WMQ::Message
    • The Message descriptor, headers and data is retrieved from :message
      • message.data is ignored if :data is supplied
  • :sync => true or false
    • Determines whether the get is performed under synchpoint. I.e. Under the current unit of work
       Default: false
      
  • :new_id => true or false
    • Generate a new message id and correlation id for this message. :new_msg_id and :new_correl_id will be ignored if this parameter is true
       Default: false
      
  • :new_msg_id => true or false
    • Generate a new message id for this message
    • Note: A blank message id will result in a new message id anyway. However, for subsequent puts using the same message descriptor, the same message id will be used.
       Default: false
      
  • :new_correl_id => true or false
    • Generate a new correlation id for this message
       Default: false
      
  • :fail_if_quiescing => true or false
    • Determines whether the WMQ::Queue#put call will fail if the queue manager is in the process of being quiesced.
    • Note: This interface differs from other WebSphere MQ interfaces, they do not default to true.
       Default: true
       Equivalent to: MQGMO_FAIL_IF_QUIESCING
      
    • Note: As part of the application design, carefull consideration should be given as to when to allow a transaction or unit of work to complete or fail under this condition. As such it is important to include this option where appropriate so that MQ Administrators can shutdown the queue managers without having to resort to the ‘immediate’ shutdown option.
  • :options => Fixnum (Advanced MQ Use only)
    • Numeric field containing any of the MQ Put message options or’d together
      • E.g. :options => WMQ::MQPMO_PASS_IDENTITY_CONTEXT | WMQ::MQPMO_ALTERNATE_USER_AUTHORITY
    • Note: If :options is supplied, it is applied first, then the above parameters are applied afterwards.
    • One or more of the following values:
        WMQ::MQPMO_NO_SYNCPOINT
        WMQ::MQPMO_LOGICAL_ORDER
        WMQ::MQPMO_NO_CONTEXT
        WMQ::MQPMO_DEFAULT_CONTEXT
        WMQ::MQPMO_PASS_IDENTITY_CONTEXT
        WMQ::MQPMO_PASS_ALL_CONTEXT
        WMQ::MQPMO_SET_IDENTITY_CONTEXT
        WMQ::MQPMO_SET_ALL_CONTEXT
        WMQ::MQPMO_ALTERNATE_USER_AUTHORITY
        WMQ::MQPMO_RESOLVE_LOCAL_Q
        WMQ::MQPMO_NONE
      
    • Please see the WebSphere MQ documentation for more details on the above options
       Default: WMQ::MQPMO_NONE
      

Returns:

Throws:

Put a message to the Dead Letter Queue

  If an error occurs when processing a datagram message
  it is necessary to move the message to the dead letter queue.
  I.e. An error message cannot be sent back to the sender because
       the original message was not a request message.
         I.e. msg_type != WMQ::MQMT_REQUEST

  All existing message data, message descriptor and message headers
  are retained.

Put a reply message back to the sender

  The :message is sent to the queue and queue manager specified in the
  :reply_to_q and :reply_to_q_mgr propoerties of the :request_message.

  The following rules are followed before sending the reply:
  - Only send replies to Request messages. No reply for Datagrams
  - Set the message type to Reply when replying to a request message
  - Reply with:
    - Remaining Expiry (Ideally deduct any processing time since get)
    - Same priority as received message
    - Same persistence as received message
  - Adhere to the Report options supplied for message and correlation id's
      in reply message
  - All headers must be returned on reply messages
    - This allows the calling application to store state information
      in these headers
    - Unless of course if the relevant header is input only and used
      for completing the request
      - In this case any remaining headers should be returned
        to the caller

Parameters:

  * :request_message The message originally received
  * All the other parameters are the same as QueueManager#put

Returns a textual representation of the reason_code for the last MQ operation

Returns => String

  • For a complete list of reasons, please see WMQ Constants or the WebSphere MQ documentation for Reason Codes

Note

  • The list of Reason Codes varies depending on the version of WebSphere MQ and the operating system on which Ruby WMQ was compiled

Return the reason code for the last MQ operation

Returns => FixNum

  • For a complete list of reason codes, please see WMQ Constants or the WebSphere MQ documentation for Reason Codes

Note

  • The list of Reason Codes varies depending on the version of WebSphere MQ and the operating system on which Ruby WMQ was compiled

[Validate]