rubywmq 0.3.0-sparc-solaris2.8-mq5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
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 'wmq/wmq'
22
+
23
+ # The Rules Format header2 (MQRFH2) allows a an XML-like string to be passed as a header
24
+ # to the data.
25
+ #
26
+
27
+ WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
28
+ qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
29
+ message = WMQ::Message.new
30
+ message.data = 'Hello World'
31
+
32
+ message.headers = [
33
+ {:header_type =>:rf_header_2,
34
+ :xml => '<hello>to the world</hello>'
35
+ }]
36
+
37
+ message.descriptor[:format] = WMQ::MQFMT_STRING
38
+
39
+ queue.put(:message=>message)
40
+ end
41
+ end
42
+
@@ -0,0 +1,42 @@
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 'wmq/wmq'
22
+
23
+ # The Rules Format header2 (MQRFH2) allows a an XML-like string to be passed as a header
24
+ # to the data.
25
+ #
26
+
27
+ WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
28
+ qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
29
+ message = WMQ::Message.new
30
+ message.data = 'Hello World'
31
+
32
+ message.headers = [
33
+ {:header_type =>:rf_header_2,
34
+ :xml => ['<hello>to the world</hello>', '<another>xml like string</another>'],
35
+ }]
36
+
37
+ message.descriptor[:format] = WMQ::MQFMT_STRING
38
+
39
+ queue.put(:message=>message)
40
+ end
41
+ end
42
+
@@ -0,0 +1,32 @@
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 'wmq/wmq'
21
+
22
+ WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
23
+ qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:output) do |queue|
24
+ message = WMQ::Message.new
25
+ message.data = "Test message from 'LOCALQMS1'"
26
+ 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}
27
+ 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}]
28
+
29
+ queue.put(:message=>message)
30
+ end
31
+ end
32
+
@@ -0,0 +1,59 @@
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 'wmq'
26
+
27
+ wait_seconds = 30
28
+
29
+ WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
30
+ qmgr.open_queue(:q_name => 'SYSTEM.DEFAULT.MODEL.QUEUE',
31
+ :dynamic_q_name=> 'REQUEST.*',
32
+ :mode => :input
33
+ ) do |reply_queue|
34
+
35
+ message = WMQ::Message.new()
36
+ message.descriptor = { :msg_type => WMQ::MQMT_REQUEST,
37
+ :reply_to_q => reply_queue.name,
38
+ :reply_to_q_mgr=> qmgr.name,
39
+ :format => WMQ::MQFMT_STRING,
40
+ :expiry => wait_seconds*10} # Measured in tenths of a second
41
+ message.data = 'Hello World'
42
+
43
+ # Send request message
44
+ qmgr.put(:q_name=>'TEST.QUEUE', :message=>message)
45
+
46
+ # Copy outgoing Message id to correlation id
47
+ message.descriptor[:correl_id]=message.descriptor[:msg_id]
48
+
49
+ # Wait for reply
50
+ # Only get the message that matches the correlation id set above
51
+ if reply_queue.get(:wait=>wait_seconds*1000, :message=>message, :match=>WMQ::MQMO_MATCH_CORREL_ID)
52
+ puts "Received:"
53
+ puts message.data
54
+ else
55
+ # get returns false when no message received. Also: message.data = nil
56
+ puts "Timed Out waiting for a reply from the server"
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,96 @@
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 'wmq/wmq'
66
+
67
+ WMQ::QueueManager.connect(:q_mgr_name=>'REID') do |qmgr|
68
+ qmgr.open_queue(:q_name=>'TEST.QUEUE', :mode=>:input) do |queue|
69
+ queue.each(:wait=>60000, :sync=>true, :convert=>true) do |request|
70
+ puts "Data Received:"
71
+ puts request.data
72
+
73
+ begin
74
+ reply = WMQ::Message.new
75
+ reply.data = 'Echo back:'+request.data
76
+
77
+ qmgr.put_to_reply_q(:message=>reply,
78
+ :request_message=>request, # Only replies if message type is request
79
+ :sync=>true)
80
+
81
+ rescue WMQ::WMQException => exc
82
+ # Failed to send reply, put message to the Dead Letter Queue and add a dead letter header
83
+ p exc
84
+ puts "Failed to reply to sender, Put to dead letter queue"
85
+ qmgr.put_to_dead_letter_q(:message=>request,
86
+ :reason=>WMQ::MQRC_UNKNOWN_REMOTE_Q_MGR,
87
+ :q_name=>queue.name,
88
+ :sync=>true)
89
+ # If it fails to put to the dead letter queue, this program will terminate and
90
+ # the changes will be "backed out". E.g. Queue Full, ...
91
+ end
92
+ qmgr.commit
93
+ end
94
+ end
95
+ puts 'No more messages found after 60 second wait interval'
96
+ end
data/lib/wmq/wmq.so ADDED
Binary file