ekaranto-rubywmq 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +4 -0
- data/LICENSE.txt +201 -0
- data/README.md +408 -0
- data/Rakefile +87 -0
- data/examples/each_a.rb +16 -0
- data/examples/each_b.rb +25 -0
- data/examples/each_header.rb +22 -0
- data/examples/files_to_q.cfg +24 -0
- data/examples/files_to_q.rb +31 -0
- data/examples/get_a.rb +19 -0
- data/examples/get_client.rb +35 -0
- data/examples/put1_a.rb +9 -0
- data/examples/put1_b.rb +17 -0
- data/examples/put1_c.rb +16 -0
- data/examples/put_a.rb +19 -0
- data/examples/put_b.rb +27 -0
- data/examples/put_dlh.rb +25 -0
- data/examples/put_dynamic_q.rb +22 -0
- data/examples/put_group_a.rb +35 -0
- data/examples/put_group_b.rb +37 -0
- data/examples/put_rfh.rb +51 -0
- data/examples/put_rfh2_a.rb +27 -0
- data/examples/put_rfh2_b.rb +27 -0
- data/examples/put_xmit_q.rb +17 -0
- data/examples/q_to_files.cfg +17 -0
- data/examples/q_to_files.rb +32 -0
- data/examples/request.rb +44 -0
- data/examples/server.rb +81 -0
- data/ext/decode_rfh.c +348 -0
- data/ext/decode_rfh.h +45 -0
- data/ext/extconf.rb +30 -0
- data/ext/extconf_client.rb +24 -0
- data/ext/generate/generate_const.rb +140 -0
- data/ext/generate/generate_reason.rb +233 -0
- data/ext/generate/generate_structs.rb +82 -0
- data/ext/generate/wmq_structs.erb +341 -0
- data/ext/wmq.c +90 -0
- data/ext/wmq.h +371 -0
- data/ext/wmq_message.c +671 -0
- data/ext/wmq_mq_load.c +217 -0
- data/ext/wmq_queue.c +1411 -0
- data/ext/wmq_queue_manager.c +1570 -0
- data/lib/rubywmq.rb +1 -0
- data/lib/wmq/message.rb +70 -0
- data/lib/wmq/queue_manager.rb +110 -0
- data/lib/wmq/version.rb +3 -0
- data/lib/wmq.rb +16 -0
- data/nbproject/project.properties +11 -0
- data/nbproject/project.xml +17 -0
- data/tests/test.rb +318 -0
- metadata +115 -0
data/Rakefile
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'rake/testtask'
|
7
|
+
require 'date'
|
8
|
+
require 'wmq/version'
|
9
|
+
|
10
|
+
desc "Build Ruby Source gem"
|
11
|
+
task :gem do |t|
|
12
|
+
excludes = [
|
13
|
+
'lib/wmq/constants.rb',
|
14
|
+
'lib/wmq/constants_admin.rb',
|
15
|
+
'ext/wmq_structs.c',
|
16
|
+
'ext/wmq_reason.c',
|
17
|
+
'ext/Makefile',
|
18
|
+
'ext/*.o',
|
19
|
+
'ext/wmq.so',
|
20
|
+
'*.gem',
|
21
|
+
'nbproject'
|
22
|
+
]
|
23
|
+
|
24
|
+
gemspec = Gem::Specification.new do |spec|
|
25
|
+
spec.name = 'ekaranto-rubywmq'
|
26
|
+
spec.version = WMQ::VERSION
|
27
|
+
spec.platform = Gem::Platform::RUBY
|
28
|
+
spec.authors = ['Reid Morrison', 'Edwin Fine']
|
29
|
+
spec.email = ['reidmo@gmail.com']
|
30
|
+
spec.homepage = 'https://github.com/reidmorrison/rubywmq'
|
31
|
+
spec.date = Date.today.to_s
|
32
|
+
spec.summary = "Native Ruby interface into WebSphere MQ"
|
33
|
+
spec.description = "RubyWMQ is a high performance native Ruby interface into WebSphere MQ."
|
34
|
+
spec.files = FileList["./**/*"].exclude(*excludes).map{|f| f.sub(/^\.\//, '')} +
|
35
|
+
['.document']
|
36
|
+
spec.extensions << 'ext/extconf.rb'
|
37
|
+
spec.rubyforge_project = 'rubywmq'
|
38
|
+
spec.test_file = 'tests/test.rb'
|
39
|
+
spec.has_rdoc = true
|
40
|
+
spec.required_ruby_version = '>= 1.8.4'
|
41
|
+
spec.add_development_dependency 'shoulda'
|
42
|
+
spec.requirements << 'WebSphere MQ v5.3, v6 or v7 Client or Server with Development Kit'
|
43
|
+
end
|
44
|
+
Gem::Builder.new(gemspec).build
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Build a binary gem including pre-compiled binary files for re-distribution"
|
48
|
+
task :binary do |t|
|
49
|
+
# Move compiled files into locations for repackaging as a binary gem
|
50
|
+
FileUtils.mkdir_p('lib/wmq')
|
51
|
+
Dir['ext/lib/*.rb'].each{|file| FileUtils.copy(file, File.join('lib/wmq', File.basename(file)))}
|
52
|
+
FileUtils.copy('ext/wmq.so', 'lib/wmq/wmq.so')
|
53
|
+
|
54
|
+
gemspec = Gem::Specification.new do |spec|
|
55
|
+
spec.name = 'ekaranto-rubywmq'
|
56
|
+
spec.version = WMQ::VERSION
|
57
|
+
spec.platform = Gem::Platform::CURRENT
|
58
|
+
spec.authors = ['Reid Morrison', 'Edwin Fine']
|
59
|
+
spec.email = ['reidmo@gmail.com']
|
60
|
+
spec.homepage = 'https://github.com/reidmorrison/rubywmq'
|
61
|
+
spec.date = Date.today.to_s
|
62
|
+
spec.summary = "Native Ruby interface into WebSphere MQ"
|
63
|
+
spec.description = "RubyWMQ is a high performance native Ruby interface into WebSphere MQ."
|
64
|
+
spec.files = Dir['examples/**/*.rb'] +
|
65
|
+
Dir['examples/**/*.cfg'] +
|
66
|
+
Dir['doc/**/*.*'] +
|
67
|
+
Dir['lib/**/*.rb'] +
|
68
|
+
['lib/wmq/wmq.so', 'tests/test.rb', 'README', 'LICENSE']
|
69
|
+
spec.rubyforge_project = 'rubywmq'
|
70
|
+
spec.test_file = 'tests/test.rb'
|
71
|
+
spec.has_rdoc = false
|
72
|
+
spec.required_ruby_version = '>= 1.8.4'
|
73
|
+
spec.add_development_dependency 'shoulda'
|
74
|
+
spec.requirements << 'WebSphere MQ v5.3, v6 or v7 Client or Server with Development Kit'
|
75
|
+
end
|
76
|
+
Gem::Builder.new(gemspec).build
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "Run Test Suite"
|
80
|
+
task :test do
|
81
|
+
Rake::TestTask.new(:functional) do |t|
|
82
|
+
t.test_files = FileList['test/*_test.rb']
|
83
|
+
t.verbose = true
|
84
|
+
end
|
85
|
+
|
86
|
+
Rake::Task['functional'].invoke
|
87
|
+
end
|
data/examples/each_a.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# Sample : each() : Retrieve all messages from a queue
|
3
|
+
# If no messages are on the queue, the program
|
4
|
+
# completes without waiting
|
5
|
+
#
|
6
|
+
require 'rubygems'
|
7
|
+
require 'wmq'
|
8
|
+
|
9
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
10
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
|
11
|
+
queue.each do |message|
|
12
|
+
puts "Data Received: #{message.data}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts 'Completed.'
|
16
|
+
end
|
data/examples/each_b.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Sample : each() : Retrieve all messages from a queue that
|
3
|
+
# have the same correlation id
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
9
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
|
10
|
+
message = WMQ::Message.new
|
11
|
+
|
12
|
+
# Retrieve First message
|
13
|
+
if queue.get(:message=>message)
|
14
|
+
puts "Data Received: #{message.data}"
|
15
|
+
|
16
|
+
#Retrieve all subsequent messages that have the same correlation id
|
17
|
+
queue.each(:message=>message, :match=>WMQ::MQMO_MATCH_CORREL_ID) do |msg|
|
18
|
+
puts "Matching Data Received: #{msg.data}"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
puts 'No message available'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
puts 'Completed.'
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Sample : each() : Retrieve all messages from a queue
|
3
|
+
# If no messages are on the queue, the program
|
4
|
+
# completes without waiting
|
5
|
+
#
|
6
|
+
require 'rubygems'
|
7
|
+
require 'wmq'
|
8
|
+
|
9
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
10
|
+
qmgr.open_queue(:q_name=>'TEST.DEAD', :mode=>:browse) do |queue|
|
11
|
+
queue.each do |message|
|
12
|
+
puts "Data Received: #{message.data}"
|
13
|
+
|
14
|
+
puts "Message Descriptor:"
|
15
|
+
p message.descriptor
|
16
|
+
|
17
|
+
puts "Headers Received:"
|
18
|
+
message.headers.each {|header| p header}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
puts 'Completed.'
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
dev:
|
2
|
+
qmgr_options:
|
3
|
+
:q_mgr_name: REID
|
4
|
+
output_queue:
|
5
|
+
:q_name: TEST.QUEUE
|
6
|
+
put_options:
|
7
|
+
:new_msg_id: true
|
8
|
+
descriptor:
|
9
|
+
:format: MQSTR
|
10
|
+
source_directory: messages
|
11
|
+
|
12
|
+
test:
|
13
|
+
qmgr_options:
|
14
|
+
:q_mgr_name: TEST.QMGR
|
15
|
+
:channel_name: SYSTEM.DEF.SVRCONN
|
16
|
+
:connection_name: remotehost(1414)
|
17
|
+
output_queue:
|
18
|
+
:q_name: TEST.QUEUE
|
19
|
+
put_options:
|
20
|
+
:new_msg_id: true
|
21
|
+
descriptor:
|
22
|
+
:format: MQSTR
|
23
|
+
source_directory: messages
|
24
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Example : files_to_q : Place all files in a directory to a queue
|
3
|
+
# Each file is written as a separate message
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'find'
|
7
|
+
require 'yaml'
|
8
|
+
require 'wmq'
|
9
|
+
|
10
|
+
# Call program passing environment name as first parameter
|
11
|
+
# The environment corresponds to an entry in the config file
|
12
|
+
env = ARGV[0] || raise("Command line argument 'environment' is required")
|
13
|
+
config = YAML::load_file('files_to_q.cfg')[env]
|
14
|
+
|
15
|
+
message = WMQ::Message.new
|
16
|
+
message.descriptor = config['descriptor'] || {}
|
17
|
+
tstart = Time.now
|
18
|
+
counter = 0
|
19
|
+
WMQ::QueueManager.connect(config['qmgr_options']) do |qmgr|
|
20
|
+
qmgr.open_queue({:mode=>:output}.merge(config['output_queue'])) do |queue|
|
21
|
+
Find.find(config['source_directory']) do |path|
|
22
|
+
unless FileTest.directory?(path)
|
23
|
+
printf("%5d: #{path}\n",counter = counter + 1)
|
24
|
+
message.data = File.read(path)
|
25
|
+
queue.put({:message => message}.merge(config['put_options']))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
duration = Time.now - tstart
|
31
|
+
printf "Processed #{counter} messages in %.3f seconds. Average: %.3f messages/second\n", duration, counter/duration
|
data/examples/get_a.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Sample : get() : Retrieve a single message from a queue
|
3
|
+
# If no messages are on the queue, message.data is nil
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
9
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
|
10
|
+
|
11
|
+
message = WMQ::Message.new
|
12
|
+
if queue.get(:message => message)
|
13
|
+
puts "Data Received: #{message.data}"
|
14
|
+
else
|
15
|
+
puts 'No message available'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Sample : get() : Retrieve a single message from a queue
|
3
|
+
# If no messages are on the queue, message.data is nil
|
4
|
+
#
|
5
|
+
# The Client connection is determined by the :connection_name parameter supplied
|
6
|
+
# to QueueManager::connect or QueueManager::new
|
7
|
+
#
|
8
|
+
# If :connection_name is not present, a WebSphere MQ Server connection will be used
|
9
|
+
# I.e. Local server connection
|
10
|
+
#
|
11
|
+
require 'rubygems'
|
12
|
+
require 'wmq'
|
13
|
+
|
14
|
+
WMQ::QueueManager.connect(
|
15
|
+
:connection_name => 'localhost(1414)', # Use MQ Client Library
|
16
|
+
:channel_name => 'SYSTEM.DEF.SVRCONN', # Optional, since this is the default value
|
17
|
+
:transport_type => WMQ::MQXPT_TCP # Optional, since this is the default value
|
18
|
+
) do |qmgr|
|
19
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
|
20
|
+
|
21
|
+
message = WMQ::Message.new
|
22
|
+
if queue.get(:message => message)
|
23
|
+
puts "Data Received: #{message.data}"
|
24
|
+
|
25
|
+
puts "Message Descriptor:"
|
26
|
+
p message.descriptor
|
27
|
+
|
28
|
+
puts "Headers Received:"
|
29
|
+
message.headers.each {|header| p header}
|
30
|
+
else
|
31
|
+
puts 'No message available'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/examples/put1_a.rb
ADDED
data/examples/put1_b.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put1() : Put a single message to a queue
|
3
|
+
#
|
4
|
+
# Set the correlation id to a text string
|
5
|
+
#
|
6
|
+
require 'rubygems'
|
7
|
+
require 'wmq'
|
8
|
+
|
9
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
10
|
+
|
11
|
+
message = WMQ::Message.new
|
12
|
+
message.data = 'Hello World'
|
13
|
+
message.descriptor[:correl_id] = 'My first message'
|
14
|
+
|
15
|
+
qmgr.put(:q_name=>'TEST.QUEUE', :message=>message)
|
16
|
+
end
|
17
|
+
|
data/examples/put1_c.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a single request message to a queue
|
3
|
+
#
|
4
|
+
require 'rubygems'
|
5
|
+
require 'wmq'
|
6
|
+
|
7
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
8
|
+
message = WMQ::Message.new
|
9
|
+
message.data = 'Hello World'
|
10
|
+
|
11
|
+
message.descriptor = {
|
12
|
+
:msg_type=> WMQ::MQMT_REQUEST,
|
13
|
+
:reply_to_q=>'TEST.REPLY.QUEUE'}
|
14
|
+
|
15
|
+
qmgr.put(:q_name=>'TEST.QUEUE', :message => message)
|
16
|
+
end
|
data/examples/put_a.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a single message to a queue
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
9
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
10
|
+
|
11
|
+
# First message
|
12
|
+
queue.put(:data => 'Hello World')
|
13
|
+
|
14
|
+
# Second message
|
15
|
+
# This message will have new message and correlation id's
|
16
|
+
queue.put(:data => 'Hello Again')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/examples/put_b.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put two Messages to a queue
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
# Ensure that all messages have the same correlation id
|
5
|
+
#
|
6
|
+
require 'rubygems'
|
7
|
+
require 'wmq'
|
8
|
+
|
9
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
10
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
11
|
+
|
12
|
+
message = WMQ::Message.new
|
13
|
+
|
14
|
+
# First message
|
15
|
+
# Results in a WMQ generated msg_id and empty correl_id
|
16
|
+
message.data = 'Hello World'
|
17
|
+
queue.put(:message => message)
|
18
|
+
|
19
|
+
# Second message
|
20
|
+
# new_msg_id will cause the second message to have a new message id
|
21
|
+
# otherwise both messages will have the same message and correlation id's
|
22
|
+
# This message will have the same correlation id as the first message (empty)
|
23
|
+
message.data = 'Hello Again'
|
24
|
+
p message.descriptor
|
25
|
+
queue.put(:message => message, :new_msg_id => true)
|
26
|
+
end
|
27
|
+
end
|
data/examples/put_dlh.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a message to a queue with a dead letter header
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
9
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
10
|
+
message = WMQ::Message.new
|
11
|
+
message.data = 'Hello World'
|
12
|
+
|
13
|
+
message.headers = [
|
14
|
+
{:header_type =>:dead_letter_header,
|
15
|
+
:reason => WMQ::MQRC_UNKNOWN_REMOTE_Q_MGR,
|
16
|
+
:dest_q_name =>'ORIGINAL_QUEUE_NAME',
|
17
|
+
:dest_q_mgr_name =>'BAD_Q_MGR'}
|
18
|
+
]
|
19
|
+
|
20
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
21
|
+
|
22
|
+
queue.put(:message=>message)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a single message to a queue
|
3
|
+
# Create the queue if it does not already exist
|
4
|
+
#
|
5
|
+
# Note : The queue name is that of the model queue
|
6
|
+
# The dynamic_q_name is the actual queue name
|
7
|
+
#
|
8
|
+
# This sample is more usefull if the model queue was a Permanent Dynamic one.
|
9
|
+
# That way the queue would remain after termination of this code.
|
10
|
+
# In this sample the queue will disappear when this program terminates
|
11
|
+
#
|
12
|
+
require 'rubygems'
|
13
|
+
require 'wmq'
|
14
|
+
|
15
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
16
|
+
qmgr.open_queue(:q_name => 'SYSTEM.DEFAULT.MODEL.QUEUE',
|
17
|
+
:dynamic_q_name => 'TEST.QUEUE.SAMPLE',
|
18
|
+
:mode => :output
|
19
|
+
) do |queue|
|
20
|
+
queue.put(:data => 'Hello World')
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put multiple Messages to a queue under the same group Id
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
# Ensure that all messages have the same group id
|
5
|
+
# Allow MQ to create the unique group id and let it automatically
|
6
|
+
# assign message sequence numbers for each message in the group
|
7
|
+
#
|
8
|
+
require 'rubygems'
|
9
|
+
require 'wmq'
|
10
|
+
|
11
|
+
# Put 5 messages in a single group onto the queue
|
12
|
+
total = 5
|
13
|
+
|
14
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
15
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
16
|
+
message = WMQ::Message.new
|
17
|
+
total.times do |count|
|
18
|
+
message.data = "Hello:#{count}"
|
19
|
+
|
20
|
+
# Set the message flag to indicate message is in a group
|
21
|
+
# On the last message, set the last message flag
|
22
|
+
message.descriptor[:msg_flags] = (count < total-1) ? WMQ::MQMF_MSG_IN_GROUP : WMQ::MQMF_LAST_MSG_IN_GROUP
|
23
|
+
|
24
|
+
# new_id => true causes subsequent messages to have unique message and
|
25
|
+
# correlation id's. Otherwise all messages will have the same message and
|
26
|
+
# correlation id's since the same message object is being
|
27
|
+
# re-used for all put calls.
|
28
|
+
#
|
29
|
+
# By setting the put :options => WMQ::MQPMO_LOGICAL_ORDER then MQ will supply a unique Group Id
|
30
|
+
# and MQ will automatically set the message sequence number for us.
|
31
|
+
queue.put(:message => message, :new_id => true, :options => WMQ::MQPMO_LOGICAL_ORDER)
|
32
|
+
p message.descriptor
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put multiple Messages to a queue under the same group Id
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
# Ensure that all messages have the same group id
|
5
|
+
# Supply our own user-defined group Id.
|
6
|
+
# We also have to supply the message sequence number which starts at 1
|
7
|
+
#
|
8
|
+
require 'rubygems'
|
9
|
+
require 'wmq'
|
10
|
+
|
11
|
+
# Put 5 messages in a single group onto the queue
|
12
|
+
total = 5
|
13
|
+
|
14
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
15
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
16
|
+
message = WMQ::Message.new
|
17
|
+
# Supply a unique Group Id, truncated to the MQ maximum for Group Id.
|
18
|
+
message.descriptor[:group_id] = 'MyUniqueGroupId'
|
19
|
+
total.times do |count|
|
20
|
+
# new_id => true causes subsequent messages to have unique message and
|
21
|
+
# correlation id's. Otherwise all messages will have the same message and
|
22
|
+
# correlation id's since the same message object is being
|
23
|
+
# re-used for all put calls
|
24
|
+
message.data = "Hello:#{count}"
|
25
|
+
|
26
|
+
# Set the message flag to indicate message is in a group
|
27
|
+
# On the last message, set the last message flag
|
28
|
+
message.descriptor[:msg_flags] = (count < total-1) ? WMQ::MQMF_MSG_IN_GROUP : WMQ::MQMF_LAST_MSG_IN_GROUP
|
29
|
+
message.descriptor[:msg_seq_number] = count + 1
|
30
|
+
|
31
|
+
# By setting the put :options => WMQ::MQPMO_LOGICAL_ORDER then MQ will supply a unique Group Id
|
32
|
+
# and MQ will automatically set the message sequence number for us.
|
33
|
+
queue.put(:message => message, :new_id => true)
|
34
|
+
p message.descriptor
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/examples/put_rfh.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a message to a queue with a Refernce header
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
# The Rules Format header (MQRFH) allows a list of name value pairs to be sent along
|
9
|
+
# with a WMQ message. These name value pairs are represented as follows on the "wire":
|
10
|
+
# Name1 Value1 Name2 Value2 Name3 Value3
|
11
|
+
#
|
12
|
+
# Ruby WMQ converts the above string of data into a Ruby hash by
|
13
|
+
# using the name as the key, as follows:
|
14
|
+
# data = {
|
15
|
+
# 'Name1' => 'Value1',
|
16
|
+
# 'Name2' => 'Value2',
|
17
|
+
# 'Name3' => 'Value3'
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
# Since a name can consist of any character except null, it is stored as a String
|
21
|
+
#
|
22
|
+
# Note: It is possible to send or receive the same Name with multiple values using an array.
|
23
|
+
# E.g. Name1 Value1 Name2 Value2 Name1 Value3
|
24
|
+
# Becomes:
|
25
|
+
# data = {
|
26
|
+
# 'Name1' => ['Value1', 'Value3'],
|
27
|
+
# 'Name2' => 'Value2'
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
# Note: Since a Hash does not preserve order, reading a Rules Format Header and then writing
|
31
|
+
# it out immediately again could result in re-ordering of the name value pairs.
|
32
|
+
#
|
33
|
+
|
34
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
35
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
36
|
+
message = WMQ::Message.new
|
37
|
+
message.data = 'Hello World'
|
38
|
+
|
39
|
+
message.headers = [
|
40
|
+
{:header_type =>:rf_header,
|
41
|
+
:name_value => {'name1' => 'value1',
|
42
|
+
'name2' => 'value2',
|
43
|
+
'name3' => ['value 3a', 'value 3b']}
|
44
|
+
}]
|
45
|
+
|
46
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
47
|
+
|
48
|
+
queue.put(:message=>message)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a message to a queue with a Refernce header
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
# The Rules Format header2 (MQRFH2) allows a an XML-like string to be passed as a header
|
9
|
+
# to the data.
|
10
|
+
#
|
11
|
+
|
12
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
13
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
14
|
+
message = WMQ::Message.new
|
15
|
+
message.data = 'Hello World'
|
16
|
+
|
17
|
+
message.headers = [
|
18
|
+
{:header_type =>:rf_header_2,
|
19
|
+
:xml => '<hello>to the world</hello>'
|
20
|
+
}]
|
21
|
+
|
22
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
23
|
+
|
24
|
+
queue.put(:message=>message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a message to a queue with a Refernce header
|
3
|
+
# Open the queue so that multiple puts can be performed
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'wmq'
|
7
|
+
|
8
|
+
# The Rules Format header2 (MQRFH2) allows a an XML-like string to be passed as a header
|
9
|
+
# to the data.
|
10
|
+
#
|
11
|
+
|
12
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
13
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
14
|
+
message = WMQ::Message.new
|
15
|
+
message.data = 'Hello World'
|
16
|
+
|
17
|
+
message.headers = [
|
18
|
+
{:header_type =>:rf_header_2,
|
19
|
+
:xml => ['<hello>to the world</hello>', '<another>xml like string</another>'],
|
20
|
+
}]
|
21
|
+
|
22
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
23
|
+
|
24
|
+
queue.put(:message=>message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Sample : put() : Put a message to a queue with a Transmission header
|
3
|
+
#
|
4
|
+
require 'rubygems'
|
5
|
+
require 'wmq'
|
6
|
+
|
7
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
8
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
9
|
+
message = WMQ::Message.new
|
10
|
+
message.data = "Test message from 'LOCALQMS1'"
|
11
|
+
message.descriptor = {:original_length=>-1, :priority=>0, :put_time=>"18510170", :msg_id=>"AMQ LOCALQMS1 E\233\001\237 \000\003\005", :expiry=>-1, :persistence=>0, :reply_to_q=>"MQMON", :correl_id=>"AMQ LOCALQMS1 E\233\001\237 \000\003\004", :feedback=>0, :offset=>0, :report=>0, :msg_flags=>0, :reply_to_q_mgr=>"LOCALQMS1", :appl_identity_data=>"", :put_appl_name=>"LOCALQMS1", :user_identifier=>"mqm", :msg_seq_number=>1, :appl_origin_data=>"", :accounting_token=>"\026\001\005\025\000\000\000\271U\305\002\261\022\362\321\021D\3206\357\003\000\000\000\000\000\000\000\000\000\000\v", :backout_count=>0, :coded_char_set_id=>437, :put_appl_type=>7, :msg_type=>8, :group_id=>"", :put_date=>"20070109", :format=>"MQSTR", :encoding=>546}
|
12
|
+
message.headers = [{:priority=>0, :remote_q_mgr_name=>"OTHER.QMGR", :put_time=>"18510170", :msg_id=>"AMQ LOCALQMS1 E\233\001\237 \000\003\004", :expiry=>-1, :persistence=>0, :remote_q_name=>"OTHER.Q", :header_type=>:xmit_q_header, :reply_to_q=>"MQMON", :correl_id=>"", :feedback=>0, :report=>0, :reply_to_q_mgr=>"LOCALQMS1", :appl_identity_data=>"", :put_appl_name=>"uments\\MQ\\MQMon\\mqmonntp.exe", :user_identifier=>"mqm", :appl_origin_data=>"", :accounting_token=>"\026\001\005\025\000\000\000\271U\305\002\261\022\362\321\021D\3206\357\003\000\000\000\000\000\000\000\000\000\000\v", :backout_count=>0, :coded_char_set_id=>437, :put_appl_type=>11, :msg_type=>8, :put_date=>"20070109", :encoding=>546}]
|
13
|
+
|
14
|
+
queue.put(:message=>message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
dev:
|
2
|
+
qmgr_options:
|
3
|
+
:q_mgr_name: REID
|
4
|
+
input_queue:
|
5
|
+
:mode: :browse
|
6
|
+
:q_name: TEST.QUEUE
|
7
|
+
target_directory: messages
|
8
|
+
|
9
|
+
test:
|
10
|
+
qmgr_options:
|
11
|
+
:q_mgr_name: TEST.QMGR
|
12
|
+
:channel_name: SYSTEM.DEF.SVRCONN
|
13
|
+
:connection_name: remotehost(1414)
|
14
|
+
input_queue:
|
15
|
+
:mode: :browse
|
16
|
+
:q_name: TEST.QUEUE
|
17
|
+
target_directory: messages
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Example: q_to_files: Copy all messages in a queue to separate files in a directory
|
3
|
+
#
|
4
|
+
require 'rubygems'
|
5
|
+
require 'find'
|
6
|
+
require 'yaml'
|
7
|
+
require 'wmq'
|
8
|
+
require 'fileutils'
|
9
|
+
|
10
|
+
# Call program passing environment name as first parameter
|
11
|
+
# The environment corresponds to an entry in the config file
|
12
|
+
env = ARGV[0] || raise("Command line argument 'environment' is required")
|
13
|
+
config = YAML::load_file('q_to_files.cfg')[env]
|
14
|
+
|
15
|
+
# Create supplied path if it does not exist
|
16
|
+
path = config['target_directory']
|
17
|
+
FileUtils.mkdir_p(path)
|
18
|
+
|
19
|
+
message = WMQ::Message.new
|
20
|
+
message.descriptor = config['descriptor'] || {}
|
21
|
+
tstart = Time.now
|
22
|
+
counter = 0
|
23
|
+
WMQ::QueueManager.connect(config['qmgr_options']) do |qmgr|
|
24
|
+
qmgr.open_queue(config['input_queue']) do |queue|
|
25
|
+
queue.each do |message|
|
26
|
+
counter = counter + 1
|
27
|
+
File.open(File.join(path, "message_%03d" % counter), 'w') {|file| file.write(message.data) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
duration = Time.now - tstart
|
32
|
+
printf "Processed #{counter} messages in %.3f seconds. Average: %.3f messages/second\n", duration, counter/duration
|