ferocia-rubywmq 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +8 -0
- data/LICENSE +13 -0
- data/Manifest.txt +20 -0
- data/README +73 -0
- data/examples/each_a.rb +32 -0
- data/examples/each_b.rb +41 -0
- data/examples/each_header.rb +38 -0
- data/examples/files_to_q.cfg +24 -0
- data/examples/files_to_q.rb +47 -0
- data/examples/get_a.rb +35 -0
- data/examples/get_client.rb +51 -0
- data/examples/put1_a.rb +25 -0
- data/examples/put1_b.rb +33 -0
- data/examples/put1_c.rb +32 -0
- data/examples/put_a.rb +35 -0
- data/examples/put_b.rb +43 -0
- data/examples/put_dlh.rb +41 -0
- data/examples/put_dynamic_q.rb +38 -0
- data/examples/put_group_a.rb +51 -0
- data/examples/put_group_b.rb +53 -0
- data/examples/put_rfh.rb +67 -0
- data/examples/put_rfh2_a.rb +43 -0
- data/examples/put_rfh2_b.rb +43 -0
- data/examples/put_xmit_q.rb +33 -0
- data/examples/q_to_files.cfg +17 -0
- data/examples/q_to_files.rb +48 -0
- data/examples/request.rb +60 -0
- data/examples/server.rb +97 -0
- data/ext/build.bat +3 -0
- data/ext/build.sh +6 -0
- data/ext/decode_rfh.c +348 -0
- data/ext/decode_rfh.h +45 -0
- data/ext/extconf.rb +44 -0
- data/ext/extconf_client.rb +40 -0
- data/ext/generate/generate_const.rb +167 -0
- data/ext/generate/generate_reason.rb +246 -0
- data/ext/generate/generate_structs.rb +97 -0
- data/ext/generate/wmq_structs.erb +371 -0
- data/ext/lib/wmq_temp.rb +197 -0
- data/ext/wmq.c +93 -0
- data/ext/wmq.h +367 -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 +1587 -0
- data/lib/wmq.rb +25 -0
- data/rubywmq.binary.gemspec +32 -0
- data/rubywmq.gemspec +33 -0
- data/tests/test.rb +328 -0
- metadata +124 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : put() : Put multiple Messages to a queue under the same group Id
|
19
|
+
# Open the queue so that multiple puts can be performed
|
20
|
+
# Ensure that all messages have the same group id
|
21
|
+
# Allow MQ to create the unique group id and let it automatically
|
22
|
+
# assign message sequence numbers for each message in the group
|
23
|
+
#
|
24
|
+
require 'rubygems'
|
25
|
+
require 'wmq/wmq'
|
26
|
+
|
27
|
+
# Put 5 messages in a single group onto the queue
|
28
|
+
total = 5
|
29
|
+
|
30
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
31
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
32
|
+
message = WMQ::Message.new
|
33
|
+
total.times do |count|
|
34
|
+
message.data = "Hello:#{count}"
|
35
|
+
|
36
|
+
# Set the message flag to indicate message is in a group
|
37
|
+
# On the last message, set the last message flag
|
38
|
+
message.descriptor[:msg_flags] = (count < total-1) ? WMQ::MQMF_MSG_IN_GROUP : WMQ::MQMF_LAST_MSG_IN_GROUP
|
39
|
+
|
40
|
+
# new_id => true causes subsequent messages to have unique message and
|
41
|
+
# correlation id's. Otherwise all messages will have the same message and
|
42
|
+
# correlation id's since the same message object is being
|
43
|
+
# re-used for all put calls.
|
44
|
+
#
|
45
|
+
# By setting the put :options => WMQ::MQPMO_LOGICAL_ORDER then MQ will supply a unique Group Id
|
46
|
+
# and MQ will automatically set the message sequence number for us.
|
47
|
+
queue.put(:message => message, :new_id => true, :options => WMQ::MQPMO_LOGICAL_ORDER)
|
48
|
+
p message.descriptor
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : put() : Put multiple Messages to a queue under the same group Id
|
19
|
+
# Open the queue so that multiple puts can be performed
|
20
|
+
# Ensure that all messages have the same group id
|
21
|
+
# Supply our own user-defined group Id.
|
22
|
+
# We also have to supply the message sequence number which starts at 1
|
23
|
+
#
|
24
|
+
require 'rubygems'
|
25
|
+
require 'wmq/wmq'
|
26
|
+
|
27
|
+
# Put 5 messages in a single group onto the queue
|
28
|
+
total = 5
|
29
|
+
|
30
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
31
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
32
|
+
message = WMQ::Message.new
|
33
|
+
# Supply a unique Group Id, truncated to the MQ maximum for Group Id.
|
34
|
+
message.descriptor[:group_id] = 'MyUniqueGroupId'
|
35
|
+
total.times do |count|
|
36
|
+
# new_id => true causes subsequent messages to have unique message and
|
37
|
+
# correlation id's. Otherwise all messages will have the same message and
|
38
|
+
# correlation id's since the same message object is being
|
39
|
+
# re-used for all put calls
|
40
|
+
message.data = "Hello:#{count}"
|
41
|
+
|
42
|
+
# Set the message flag to indicate message is in a group
|
43
|
+
# On the last message, set the last message flag
|
44
|
+
message.descriptor[:msg_flags] = (count < total-1) ? WMQ::MQMF_MSG_IN_GROUP : WMQ::MQMF_LAST_MSG_IN_GROUP
|
45
|
+
message.descriptor[:msg_seq_number] = count + 1
|
46
|
+
|
47
|
+
# By setting the put :options => WMQ::MQPMO_LOGICAL_ORDER then MQ will supply a unique Group Id
|
48
|
+
# and MQ will automatically set the message sequence number for us.
|
49
|
+
queue.put(:message => message, :new_id => true)
|
50
|
+
p message.descriptor
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/examples/put_rfh.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : put() : Put a message to a queue with a Refernce header
|
19
|
+
# Open the queue so that multiple puts can be performed
|
20
|
+
#
|
21
|
+
require 'rubygems'
|
22
|
+
require 'wmq/wmq'
|
23
|
+
|
24
|
+
# The Rules Format header (MQRFH) allows a list of name value pairs to be sent along
|
25
|
+
# with a WMQ message. These name value pairs are represented as follows on the "wire":
|
26
|
+
# Name1 Value1 Name2 Value2 Name3 Value3
|
27
|
+
#
|
28
|
+
# Ruby WMQ converts the above string of data into a Ruby hash by
|
29
|
+
# using the name as the key, as follows:
|
30
|
+
# data = {
|
31
|
+
# 'Name1' => 'Value1',
|
32
|
+
# 'Name2' => 'Value2',
|
33
|
+
# 'Name3' => 'Value3'
|
34
|
+
# }
|
35
|
+
#
|
36
|
+
# Since a name can consist of any character except null, it is stored as a String
|
37
|
+
#
|
38
|
+
# Note: It is possible to send or receive the same Name with multiple values using an array.
|
39
|
+
# E.g. Name1 Value1 Name2 Value2 Name1 Value3
|
40
|
+
# Becomes:
|
41
|
+
# data = {
|
42
|
+
# 'Name1' => ['Value1', 'Value3'],
|
43
|
+
# 'Name2' => 'Value2'
|
44
|
+
# }
|
45
|
+
#
|
46
|
+
# Note: Since a Hash does not preserve order, reading a Rules Format Header and then writing
|
47
|
+
# it out immediately again could result in re-ordering of the name value pairs.
|
48
|
+
#
|
49
|
+
|
50
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
51
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
52
|
+
message = WMQ::Message.new
|
53
|
+
message.data = 'Hello World'
|
54
|
+
|
55
|
+
message.headers = [
|
56
|
+
{:header_type =>:rf_header,
|
57
|
+
:name_value => {'name1' => 'value1',
|
58
|
+
'name2' => 'value2',
|
59
|
+
'name3' => ['value 3a', 'value 3b']}
|
60
|
+
}]
|
61
|
+
|
62
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
63
|
+
|
64
|
+
queue.put(:message=>message)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : put() : Put a message to a queue with a Refernce header
|
19
|
+
# Open the queue so that multiple puts can be performed
|
20
|
+
#
|
21
|
+
require 'rubygems'
|
22
|
+
require 'wmq/wmq'
|
23
|
+
|
24
|
+
# The Rules Format header2 (MQRFH2) allows a an XML-like string to be passed as a header
|
25
|
+
# to the data.
|
26
|
+
#
|
27
|
+
|
28
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
29
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
30
|
+
message = WMQ::Message.new
|
31
|
+
message.data = 'Hello World'
|
32
|
+
|
33
|
+
message.headers = [
|
34
|
+
{:header_type =>:rf_header_2,
|
35
|
+
:xml => '<hello>to the world</hello>'
|
36
|
+
}]
|
37
|
+
|
38
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
39
|
+
|
40
|
+
queue.put(:message=>message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : put() : Put a message to a queue with a Refernce header
|
19
|
+
# Open the queue so that multiple puts can be performed
|
20
|
+
#
|
21
|
+
require 'rubygems'
|
22
|
+
require 'wmq/wmq'
|
23
|
+
|
24
|
+
# The Rules Format header2 (MQRFH2) allows a an XML-like string to be passed as a header
|
25
|
+
# to the data.
|
26
|
+
#
|
27
|
+
|
28
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
29
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
30
|
+
message = WMQ::Message.new
|
31
|
+
message.data = 'Hello World'
|
32
|
+
|
33
|
+
message.headers = [
|
34
|
+
{:header_type =>:rf_header_2,
|
35
|
+
:xml => ['<hello>to the world</hello>', '<another>xml like string</another>'],
|
36
|
+
}]
|
37
|
+
|
38
|
+
message.descriptor[:format] = WMQ::MQFMT_STRING
|
39
|
+
|
40
|
+
queue.put(:message=>message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : put() : Put a message to a queue with a Transmission header
|
19
|
+
#
|
20
|
+
require 'rubygems'
|
21
|
+
require 'wmq/wmq'
|
22
|
+
|
23
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
24
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
|
25
|
+
message = WMQ::Message.new
|
26
|
+
message.data = "Test message from 'LOCALQMS1'"
|
27
|
+
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}
|
28
|
+
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}]
|
29
|
+
|
30
|
+
queue.put(:message=>message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -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,48 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Example: q_to_files: Copy all messages in a queue to separate files in a directory
|
19
|
+
#
|
20
|
+
require 'rubygems'
|
21
|
+
require 'find'
|
22
|
+
require 'yaml'
|
23
|
+
require 'wmq/wmq'
|
24
|
+
require 'fileutils'
|
25
|
+
|
26
|
+
# Call program passing environment name as first parameter
|
27
|
+
# The environment corresponds to an entry in the config file
|
28
|
+
env = ARGV[0] || raise("Command line argument 'environment' is required")
|
29
|
+
config = YAML::load_file('q_to_files.cfg')[env]
|
30
|
+
|
31
|
+
# Create supplied path if it does not exist
|
32
|
+
path = config['target_directory']
|
33
|
+
FileUtils.mkdir_p(path)
|
34
|
+
|
35
|
+
message = WMQ::Message.new
|
36
|
+
message.descriptor = config['descriptor'] || {}
|
37
|
+
tstart = Time.now
|
38
|
+
counter = 0
|
39
|
+
WMQ::QueueManager.connect(config['qmgr_options']) do |qmgr|
|
40
|
+
qmgr.open_queue(config['input_queue']) do |queue|
|
41
|
+
queue.each do |message|
|
42
|
+
counter = counter + 1
|
43
|
+
File.open(File.join(path, "message_%03d" % counter), 'w') {|file| file.write(message.data) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
duration = Time.now - tstart
|
48
|
+
printf "Processed #{counter} messages in %.3f seconds. Average: %.3f messages/second\n", duration, counter/duration
|
data/examples/request.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : request.rb
|
19
|
+
#
|
20
|
+
# Sample program that demonstrates how to send a request message
|
21
|
+
# and then block until the response is received from the server.
|
22
|
+
#
|
23
|
+
# A temporary Dynamic Reply To Queue is used with non-persistent messaging
|
24
|
+
#
|
25
|
+
require 'rubygems'
|
26
|
+
require 'wmq'
|
27
|
+
|
28
|
+
wait_seconds = 30
|
29
|
+
|
30
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
31
|
+
qmgr.open_queue(:q_name => 'SYSTEM.DEFAULT.MODEL.QUEUE',
|
32
|
+
:dynamic_q_name=> 'REQUEST.*',
|
33
|
+
:mode => :input
|
34
|
+
) do |reply_queue|
|
35
|
+
|
36
|
+
message = WMQ::Message.new()
|
37
|
+
message.descriptor = { :msg_type => WMQ::MQMT_REQUEST,
|
38
|
+
:reply_to_q => reply_queue.name,
|
39
|
+
:reply_to_q_mgr=> qmgr.name,
|
40
|
+
:format => WMQ::MQFMT_STRING,
|
41
|
+
:expiry => wait_seconds*10} # Measured in tenths of a second
|
42
|
+
message.data = 'Hello World'
|
43
|
+
|
44
|
+
# Send request message
|
45
|
+
qmgr.put(:q_name=>'TEST.QUEUE', :message=>message)
|
46
|
+
|
47
|
+
# Copy outgoing Message id to correlation id
|
48
|
+
message.descriptor[:correl_id]=message.descriptor[:msg_id]
|
49
|
+
|
50
|
+
# Wait for reply
|
51
|
+
# Only get the message that matches the correlation id set above
|
52
|
+
if reply_queue.get(:wait=>wait_seconds*1000, :message=>message, :match=>WMQ::MQMO_MATCH_CORREL_ID)
|
53
|
+
puts "Received:"
|
54
|
+
puts message.data
|
55
|
+
else
|
56
|
+
# get returns false when no message received. Also: message.data = nil
|
57
|
+
puts "Timed Out waiting for a reply from the server"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/examples/server.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# Sample : Sample program to show how to write a server side application
|
19
|
+
#
|
20
|
+
# This server times out after 60 seconds, but could be modified to
|
21
|
+
# run forever. Example:
|
22
|
+
# queue.each(:wait=>-1) do |message|
|
23
|
+
#
|
24
|
+
# Note: - All calls are being performed under synchpoint control to
|
25
|
+
# prevent messages being if the program terminates unexpectedly
|
26
|
+
# or an error occurrs.
|
27
|
+
# Uses: :sync=>true
|
28
|
+
# - Queue#each will backout any message changes if an excecption is raised
|
29
|
+
# but not handled within the each block
|
30
|
+
#
|
31
|
+
# A "well-behaved" WebSphere MQ application should adhere to the following rules:
|
32
|
+
# - Perform puts and gets under synchpoint where applicable
|
33
|
+
# - Only send replies to Request messages. No reply for Datagrams
|
34
|
+
# - Set the message type to Reply when replying to a request message
|
35
|
+
# - Reply with:
|
36
|
+
# - Remaining Expiry (Ideally deduct any processing time since get)
|
37
|
+
# - Same priority as received message
|
38
|
+
# - Same persistence as received message
|
39
|
+
# - Adhere to the Report options supplied for message and correlation id's
|
40
|
+
# in reply message
|
41
|
+
# - All headers must be returned on reply messages
|
42
|
+
# - This allows the calling application to store state information
|
43
|
+
# in these headers
|
44
|
+
# - Unless of course if the relevant header is input only and used
|
45
|
+
# for completing the request
|
46
|
+
# - In this case any remaining headers should be returned
|
47
|
+
# to the caller
|
48
|
+
# - If an error occurs trying to process the message, an error message
|
49
|
+
# must be sent back to the requesting application
|
50
|
+
# - If the reply fails, it must be put to the dead letter queue
|
51
|
+
# with the relevant dead letter header and reason
|
52
|
+
#
|
53
|
+
# Note: - It is not recommended to run server side MQ applications over a client
|
54
|
+
# connection.
|
55
|
+
# - Client connections require substantially more error handling.
|
56
|
+
# - E.g. Connection to queue manager can be lost due to netowk issues
|
57
|
+
# - Need to go into some sort of retry state attempting
|
58
|
+
# to reconnect to the queue manager
|
59
|
+
# - What about any work that was in progress?
|
60
|
+
# - Need to re-open any queues
|
61
|
+
# - Do any changes to other resources need to be undone first?
|
62
|
+
# - E.g. Database, File etc..
|
63
|
+
# - etc....
|
64
|
+
#
|
65
|
+
require 'rubygems'
|
66
|
+
require 'wmq/wmq'
|
67
|
+
|
68
|
+
WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
|
69
|
+
qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
|
70
|
+
queue.each(:wait=>60000, :sync=>true, :convert=>true) do |request|
|
71
|
+
puts "Data Received:"
|
72
|
+
puts request.data
|
73
|
+
|
74
|
+
begin
|
75
|
+
reply = WMQ::Message.new
|
76
|
+
reply.data = 'Echo back:'+request.data
|
77
|
+
|
78
|
+
qmgr.put_to_reply_q(:message=>reply,
|
79
|
+
:request_message=>request, # Only replies if message type is request
|
80
|
+
:sync=>true)
|
81
|
+
|
82
|
+
rescue WMQ::WMQException => exc
|
83
|
+
# Failed to send reply, put message to the Dead Letter Queue and add a dead letter header
|
84
|
+
p exc
|
85
|
+
puts "Failed to reply to sender, Put to dead letter queue"
|
86
|
+
qmgr.put_to_dead_letter_q(:message=>request,
|
87
|
+
:reason=>WMQ::MQRC_UNKNOWN_REMOTE_Q_MGR,
|
88
|
+
:q_name=>queue.name,
|
89
|
+
:sync=>true)
|
90
|
+
# If it fails to put to the dead letter queue, this program will terminate and
|
91
|
+
# the changes will be "backed out". E.g. Queue Full, ...
|
92
|
+
end
|
93
|
+
qmgr.commit
|
94
|
+
end
|
95
|
+
end
|
96
|
+
puts 'No more messages found after 60 second wait interval'
|
97
|
+
end
|
data/ext/build.bat
ADDED
data/ext/build.sh
ADDED