| Class | WMQ::Queue |
| In: |
ext/wmq.c
|
| Parent: | Object |
Note:
Parameters:
Open a queue, then close the queue once the supplied code block completes
Parameters:
queue = Queue.new( # WebSphere MQ Equivalents:
:queue_manager => queue_manager, # n/a : Instance of QueueManager
:q_name => 'Queue Name', # MQOD.ObjectName
:q_name => { queue_manager=>'QMGR_name', # MQOD.ObjectQMgrName
q_name =>'q_name'}
:mode => :input or :input_shared or :input_exclusive or :output,
:fail_if_quiescing => true # MQOO_FAIL_IF_QUIESCING
:fail_if_exists => true, # For dynamic queues, fail if it already exists
:open_options => WMQ::MQOO_BIND_ON_OPEN | ... # MQOO_*
:close_options => WMQ::MQCO_DELETE_PURGE # MQCO_*
:dynamic_q_name => 'Name of Dynamic Queue' # MQOD.DynamicQName
:alternate_user_id => 'userid', # MQOD.AlternateUserId
:alternate_security_id => '' # MQOD.AlternateSecurityId
)
Mandatory Parameters
OR
It is not possible to get messages from a queue on a queue manager other than the currently connected queue manager
Equivalent to: MQOO_OUTPUT
Equivalent to: MQOO_INPUT_AS_Q_DEF
Equivalent to: MQOO_INPUT_SHARED
Equivalent to: MQOO_INPUT_EXCLUSIVE
Equivalent to: MQOO_BROWSE
Optional Parameters
Default: true Equivalent to: MQOO_FAIL_IF_QUIESCING
WMQ::MQOO_INQUIRE WMQ::MQOO_SET WMQ::MQOO_BIND_ON_OPEN WMQ::MQOO_BIND_NOT_FIXED WMQ::MQOO_BIND_AS_Q_DEF WMQ::MQOO_SAVE_ALL_CONTEXT WMQ::MQOO_PASS_IDENTITY_CONTEXT WMQ::MQOO_PASS_ALL_CONTEXT WMQ::MQOO_SET_IDENTITY_CONTEXT WMQ::MQOO_SET_ALL_CONTEXT
:open_options=>WMQ::MQOO_BIND_ON_OPEN | WMQ::MQOO_SAVE_ALL_CONTEXT
WMQ::MQCO_DELETE WMQ::MQCO_DELETE_PURGE
Default: true
Note:
Example:
# Put 10 Hello World messages onto a queue
require 'wmq/wmq_client'
WMQ::QueueManager.connect(:q_mgr_name=>'REID', :connection_name=>'localhost(1414)') do |qmgr|
WMQ::Queue.open(:queue_manager=>qmgr,
:q_name =>'TEST.QUEUE',
:mode =>:output) do |queue|
10.times { |counter| queue.put(:data => "Hello World #{counter}") }
end
end
Close the queue
Returns:
comp_code and reason_code are also updated. reason will return a text description of the reason_code
Throws:
Return the completion code for the last MQ operation on this queue instance
Returns => FixNum
For each message found on the queue, the supplied block is executed
Note:
Returns:
Example:
require 'wmq/wmq'
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
queue.each do |message|
puts "Data Received: #{message.data}"
end
end
puts 'Completed.'
end
Get a message from the opened queue
Parameters:
queue.get( # WebSphere MQ Equivalents: :message => my_message, # n/a : Instance of Message :sync => false, # MQGMO_SYNCPOINT :wait => 0, # MQGMO_WAIT, duration in ms :match => WMQ::MQMO_NONE, # MQMO_* :convert => false, # MQGMO_CONVERT :fail_if_quiescing => true # MQOO_FAIL_IF_QUIESCING :options => WMQ::MQGMO_FAIL_IF_QUIESCING # MQGMO_* )
Mandatory Parameters
Optional Parameters
Default: false
Default: Wait forever
WMQ::MQMO_MATCH_MSG_ID WMQ::MQMO_MATCH_CORREL_ID WMQ::MQMO_MATCH_GROUP_ID WMQ::MQMO_MATCH_MSG_SEQ_NUMBER WMQ::MQMO_MATCH_OFFSET WMQ::MQMO_MATCH_MSG_TOKEN WMQ::MQMO_NONE
:match=>WMQ::MQMO_MATCH_MSG_ID | WMQ::MQMO_MATCH_CORREL_ID
Default: WMQ::MQMO_MATCH_MSG_ID | WMQ::MQMO_MATCH_CORREL_ID
Default: false
Default: true
WMQ::MQGMO_SYNCPOINT_IF_PERSISTENT WMQ::MQGMO_NO_SYNCPOINT WMQ::MQGMO_MARK_SKIP_BACKOUT WMQ::MQGMO_BROWSE_FIRST WMQ::MQGMO_BROWSE_NEXT WMQ::MQGMO_BROWSE_MSG_UNDER_CURSOR WMQ::MQGMO_MSG_UNDER_CURSOR WMQ::MQGMO_LOCK WMQ::MQGMO_UNLOCK WMQ::MQGMO_LOGICAL_ORDER WMQ::MQGMO_COMPLETE_MSG WMQ::MQGMO_ALL_MSGS_AVAILABLE WMQ::MQGMO_ALL_SEGMENTS_AVAILABLE WMQ::MQGMO_DELETE_MSG WMQ::MQGMO_NONE
Default: WMQ::MQGMO_NONE
Returns:
comp_code and reason_code are also updated. reason will return a text description of the reason_code
Throws:
Example:
require 'wmq/wmq'
WMQ::QueueManager.connect(:q_mgr_name=>'REID') 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
Open the queue
Note:
When :dynamic_q_name is supplied and MQ fails to
open the queue with MQRC_OBJECT_ALREADY_EXISTS,
this method will automatically open the existing
queue by replacing the queue name with :dynamic_q_name
This technique allows programs to dynamically create
queues, without being concerned with first checking if
the queue is already defined.
I.e. Removes the need to have to explicitly create
required queues in advance
However, in order for this approach to work a
Permanent model queue must be used. A Temporary
model queue is automatically erased by WMQ when the
queue is closed.
Persistent messages cannot be put to a
temporary dynamic queue!
Returns:
comp_code and reason_code are also updated. reason will return a text description of the reason_code
Throws:
Example:
require 'wmq/wmq_client'
queue_manager = WMQ::QueueManager.new(:q_mgr_name =>'REID',
:connection_name=>'localhost(1414)')
begin
queue_manager.connect
# Create Queue and clear any messages from the queue
in_queue = WMQ::Queue.new(:queue_manager =>queue_manager,
:mode =>:input,
:dynamic_q_name=>'UNIT.TEST',
:q_name =>'SYSTEM.DEFAULT.MODEL.QUEUE',
:fail_if_exists=>false)
begin
in_queue.open
in_queue.each { |message| p message.data }
ensure
# Note: Very important: Must close the queue explicitly
in_queue.close
end
rescue => exc
queue_manager.backout
raise exc
ensure
# Note: Very important: Must disconnect from the queue manager explicitly
queue_manager.disconnect
end
Returns whether this queue is currently open
Returns:
Put a message to the WebSphere MQ queue
Parameters:
queue.put( # WebSphere MQ Equivalents: :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:
Optional Parameters:
Default: false
Default: false
Default: false
Default: false
Default: true Equivalent to: MQGMO_FAIL_IF_QUIESCING
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
Default: WMQ::MQPMO_NONE
Returns:
comp_code and reason_code are also updated. reason will return a text description of the reason_code
Throws:
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|
# First message
queue.put(:data => 'Hello World')
# Set Format of message to string
message = WMQ::Message.new
message.descriptor[:format] = WMQ::MQFMT_STRING
queue.put(:message=>message, :data => 'Hello Again')
# Or, pass the data in the message
message = WMQ::Message.new
message.descriptor[:format] = WMQ::MQFMT_STRING
message.data = 'Hello Again'
queue.put(:message=>message)
end
end
Returns a textual representation of the reason_code for the last MQ operation on this queue instance
Returns => String
Note
Return the reason code for the last MQ operation on this queue instance
Returns => FixNum
Note