rmq 0.0.1
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/lib/rmq.rb +12 -0
- data/lib/rmq/constants.rb +1494 -0
- data/lib/rmq/exceptions.rb +17 -0
- data/lib/rmq/get_message_options.rb +55 -0
- data/lib/rmq/message_descriptor.rb +43 -0
- data/lib/rmq/mqclient.rb +282 -0
- data/lib/rmq/object_descriptor.rb +41 -0
- data/lib/rmq/put_message_options.rb +31 -0
- data/lib/rmq/queue.rb +36 -0
- data/lib/rmq/queue_manager.rb +105 -0
- data/lib/rmq/version.rb +3 -0
- data/spec/rmq/queue_manager_spec.rb +51 -0
- data/spec/rmq/queue_spec.rb +27 -0
- data/spec/spec_helper.rb +15 -0
- metadata +72 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module RMQ
|
2
|
+
class RMQException < RuntimeError
|
3
|
+
include Constants
|
4
|
+
|
5
|
+
attr_reader :reason_code
|
6
|
+
attr_reader :completion_code
|
7
|
+
|
8
|
+
def initialize(completion_code, reason_code)
|
9
|
+
@reason_code = reason_code
|
10
|
+
@completion_code = completion_code
|
11
|
+
end
|
12
|
+
|
13
|
+
def message
|
14
|
+
"#{to_s}. Reason code = #{decode_reason_code(reason_code)} (#{reason_code}), completion code = #{decode_completion_code(completion_code)}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module RMQ
|
2
|
+
module MQClient
|
3
|
+
|
4
|
+
class GetMessageOptions < FFI::Struct
|
5
|
+
MQGMO_STRUC_ID = "GMO "
|
6
|
+
MQGMO_VERSION_1 = 1
|
7
|
+
|
8
|
+
# Get Message Options
|
9
|
+
MQGMO_WAIT = 0x00000001
|
10
|
+
MQGMO_NO_WAIT = 0x00000000
|
11
|
+
MQGMO_SET_SIGNAL = 0x00000008
|
12
|
+
MQGMO_FAIL_IF_QUIESCING = 0x00002000
|
13
|
+
MQGMO_SYNCPOINT = 0x00000002
|
14
|
+
MQGMO_SYNCPOINT_IF_PERSISTENT = 0x00001000
|
15
|
+
MQGMO_NO_SYNCPOINT = 0x00000004
|
16
|
+
MQGMO_MARK_SKIP_BACKOUT = 0x00000080
|
17
|
+
MQGMO_BROWSE_FIRST = 0x00000010
|
18
|
+
MQGMO_BROWSE_NEXT = 0x00000020
|
19
|
+
MQGMO_BROWSE_MSG_UNDER_CURSOR = 0x00000800
|
20
|
+
MQGMO_MSG_UNDER_CURSOR = 0x00000100
|
21
|
+
MQGMO_LOCK = 0x00000200
|
22
|
+
MQGMO_UNLOCK = 0x00000400
|
23
|
+
MQGMO_ACCEPT_TRUNCATED_MSG = 0x00000040
|
24
|
+
MQGMO_CONVERT = 0x00004000
|
25
|
+
MQGMO_LOGICAL_ORDER = 0x00008000
|
26
|
+
MQGMO_COMPLETE_MSG = 0x00010000
|
27
|
+
MQGMO_ALL_MSGS_AVAILABLE = 0x00020000
|
28
|
+
MQGMO_ALL_SEGMENTS_AVAILABLE = 0x00040000
|
29
|
+
MQGMO_MARK_BROWSE_HANDLE = 0x00100000
|
30
|
+
MQGMO_MARK_BROWSE_CO_OP = 0x00200000
|
31
|
+
MQGMO_UNMARK_BROWSE_CO_OP = 0x00400000
|
32
|
+
MQGMO_UNMARK_BROWSE_HANDLE = 0x00800000
|
33
|
+
MQGMO_UNMARKED_BROWSE_MSG = 0x01000000
|
34
|
+
MQGMO_PROPERTIES_FORCE_MQRFH2 = 0x02000000
|
35
|
+
MQGMO_NO_PROPERTIES = 0x04000000
|
36
|
+
MQGMO_PROPERTIES_IN_HANDLE = 0x08000000
|
37
|
+
MQGMO_PROPERTIES_COMPATIBILITY = 0x10000000
|
38
|
+
MQGMO_PROPERTIES_AS_Q_DEF = 0x00000000
|
39
|
+
MQGMO_NONE = 0x00000000
|
40
|
+
|
41
|
+
layout :StrucId, [:char, 4],
|
42
|
+
:Version, :long,
|
43
|
+
:Options, :long,
|
44
|
+
:WaitInterval, :long,
|
45
|
+
:Signal1, :long,
|
46
|
+
:Signal2, :long,
|
47
|
+
:ResolvedQName, [:char, 48],
|
48
|
+
:MatchOptions, :long,
|
49
|
+
:GroupStatus, :char,
|
50
|
+
:SegmentStatus, :char,
|
51
|
+
:Segmentation, :char,
|
52
|
+
:Reserved1, :char
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module RMQ
|
2
|
+
module MQClient
|
3
|
+
|
4
|
+
class MessageDescriptor < FFI::Struct
|
5
|
+
MQMD_STRUC_ID = "MD "
|
6
|
+
MQMD_VERSION_1 = 1
|
7
|
+
MQEI_UNLIMITED = -1
|
8
|
+
MQRO_NONE = 0x00000000
|
9
|
+
MQMT_DATAGRAM = 8
|
10
|
+
MQPER_PERSISTENT = 1
|
11
|
+
|
12
|
+
layout :StrucId, [:char, 4],
|
13
|
+
:Version, :long,
|
14
|
+
:Report, :long,
|
15
|
+
:MsgType, :long,
|
16
|
+
:Expiry, :long,
|
17
|
+
:Feedback, :long,
|
18
|
+
:Encoding, :long,
|
19
|
+
:CodedCharSetId, :long,
|
20
|
+
:Format, [:char, 8],
|
21
|
+
:Priority, :long,
|
22
|
+
:Persistence, :long,
|
23
|
+
:MsgId, [:char, 24],
|
24
|
+
:CorrelId, [:char, 24],
|
25
|
+
:ReplyToQ, [:char, 48],
|
26
|
+
:ReplyToQMgr, [:char, 48],
|
27
|
+
:UserIdentifier, [:char, 12],
|
28
|
+
:AccountingToken, [:char, 32],
|
29
|
+
:ApplIdentityData, [:char, 32],
|
30
|
+
:PutApplType, :long,
|
31
|
+
:PutApplName, [:char, 28],
|
32
|
+
:PutDate, [:char, 8],
|
33
|
+
:PutTime, [:char, 8],
|
34
|
+
:ApplOriginData, [:char, 4],
|
35
|
+
:GroupId, [:char, 24],
|
36
|
+
:MsgSeqNumber, :long,
|
37
|
+
:Offset, :long,
|
38
|
+
:MsgFlags, :long,
|
39
|
+
:OriginalLength, :long
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/rmq/mqclient.rb
ADDED
@@ -0,0 +1,282 @@
|
|
1
|
+
module RMQ
|
2
|
+
module MQClient
|
3
|
+
include Constants
|
4
|
+
extend FFI::Library
|
5
|
+
|
6
|
+
ffi_lib "C:\\Program Files (x86)\\IBM\\WebSphere MQ\\bin\\mqic32.dll"
|
7
|
+
ffi_convention :stdcall
|
8
|
+
|
9
|
+
attach_function :mqconn, :MQCONN,
|
10
|
+
[:string, :pointer, :pointer, :pointer], :void
|
11
|
+
attach_function :mqdisc, :MQDISC,
|
12
|
+
[:pointer, :pointer, :pointer], :void
|
13
|
+
|
14
|
+
# MQPUT (Hconn, Hobj, &MsgDesc, &PutMsgOpts, BufferLength, &Buffer, &CompCode, &Reason)
|
15
|
+
attach_function :mqput, :MQPUT,
|
16
|
+
[:long, :long, :pointer, :pointer, :long, :string, :pointer, :pointer], :void
|
17
|
+
|
18
|
+
# MQGET (Hconn, Hobj, &MsgDesc, &GetMsgOpts, BufferLength, Buffer, &DataLength, &CompCode, &Reason)
|
19
|
+
attach_function :mqget, :MQGET,
|
20
|
+
[:long, :long, :pointer, :pointer, :long, :pointer, :pointer, :pointer, :pointer], :void
|
21
|
+
|
22
|
+
# MQOPEN (Hconn, &ObjDesc, Options, &Hobj, &CompCode, &Reason)
|
23
|
+
attach_function :mqopen, :MQOPEN,
|
24
|
+
[:long, :pointer, :long, :pointer, :pointer, :pointer], :void
|
25
|
+
|
26
|
+
# MQCLOSE (Hconn, &Hobj, Options, &CompCode, &Reason)
|
27
|
+
attach_function :mqclose, :MQCLOSE,
|
28
|
+
[:long, :pointer, :long, :pointer, :pointer], :void
|
29
|
+
|
30
|
+
# mqCreateBag (Options, &Bag, &CompCode, &Reason)
|
31
|
+
attach_function :mqai_create_bag, :mqCreateBag,
|
32
|
+
[:long, :pointer, :pointer, :pointer], :void
|
33
|
+
|
34
|
+
# mqAddString (hBag, Selector, BufferLength, Buffer, &CompCode, &Reason)
|
35
|
+
attach_function :mqai_add_string, :mqAddString,
|
36
|
+
[:long, :long, :long, :string, :pointer, :pointer], :void
|
37
|
+
|
38
|
+
# mqAddInteger (Bag, Selector, ItemValue, &CompCode, &Reason)
|
39
|
+
attach_function :mqai_add_integer, :mqAddInteger,
|
40
|
+
[:long, :long, :long, :pointer, :pointer], :void
|
41
|
+
|
42
|
+
# mqInquireString (Bag, Selector, ItemIndex, BufferLength, Buffer, &StringLength, &CodedCharSetId, &CompCode, &Reason)
|
43
|
+
attach_function :mqai_inquire_string, :mqInquireString,
|
44
|
+
[:long, :long, :long, :long, :pointer, :pointer, :pointer, :pointer, :pointer], :void
|
45
|
+
|
46
|
+
# mqInquireInteger (Bag, Selector, ItemIndex, &ItemValue, &CompCode, &Reason);
|
47
|
+
attach_function :mqai_inquire_integer, :mqInquireInteger,
|
48
|
+
[:long, :long, :long, :pointer, :pointer, :pointer], :void
|
49
|
+
|
50
|
+
# mqAddInquiry (Bag, Selector, &CompCode, &Reason)
|
51
|
+
attach_function :mqai_add_inquiry, :mqAddInquiry,
|
52
|
+
[:long, :long, :pointer, :pointer], :void
|
53
|
+
|
54
|
+
# mqExecute (Hconn, Command, OptionsBag, AdminBag, ResponseBag, AdminQ, ResponseQ, CompCode, Reason)
|
55
|
+
attach_function :mqai_execute, :mqExecute,
|
56
|
+
[:long, :long, :long, :long, :long, :long, :long, :pointer, :pointer], :void
|
57
|
+
|
58
|
+
# mqCountItems (Bag, Selector, &ItemCount, &CompCode, &Reason)
|
59
|
+
attach_function :mqai_count_items, :mqCountItems,
|
60
|
+
[:long, :long, :pointer, :pointer, :pointer], :void
|
61
|
+
|
62
|
+
# mqInquireBag (Bag, Selector, ItemIndex, &ItemValue, &CompCode, &Reason)
|
63
|
+
attach_function :mqai_inquire_bag, :mqInquireBag,
|
64
|
+
[:long, :long, :long, :pointer, :pointer, :pointer], :void
|
65
|
+
|
66
|
+
# mqDeleteBag (&Bag, CompCode, Reason)
|
67
|
+
attach_function :mqai_delete_bag, :mqDeleteBag,
|
68
|
+
[:pointer, :pointer, :pointer], :void
|
69
|
+
|
70
|
+
|
71
|
+
def create_admin_bag
|
72
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
73
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
74
|
+
|
75
|
+
adminbag_handle_ptr = FFI::MemoryPointer.new :long
|
76
|
+
mqai_create_bag(MQCBO_ADMIN_BAG, adminbag_handle_ptr, completion_code_ptr, reason_code_ptr)
|
77
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot create admin bag" if completion_code_ptr.read_long != MQCC_OK
|
78
|
+
|
79
|
+
adminbag_handle_ptr.read_long
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_response_bag
|
83
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
84
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
85
|
+
|
86
|
+
responsebag_handle_ptr = FFI::MemoryPointer.new :long
|
87
|
+
mqai_create_bag(MQCBO_ADMIN_BAG, responsebag_handle_ptr, completion_code_ptr, reason_code_ptr)
|
88
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot create response bag" if completion_code_ptr.read_long != MQCC_OK
|
89
|
+
|
90
|
+
responsebag_handle_ptr.read_long
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_string_to_bag(bag_handle, selector, value)
|
94
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
95
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
96
|
+
|
97
|
+
mqai_add_string(bag_handle, selector, MQBL_NULL_TERMINATED, value, completion_code_ptr, reason_code_ptr)
|
98
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot add string to admin bag" if completion_code_ptr.read_long != MQCC_OK
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_integer_to_bag(bag_handle, selector, value)
|
102
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
103
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
104
|
+
|
105
|
+
mqai_add_integer(bag_handle, selector, value, completion_code_ptr, reason_code_ptr)
|
106
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot add integer to admin bag" if completion_code_ptr.read_long != MQCC_OK
|
107
|
+
end
|
108
|
+
|
109
|
+
def add_inquiry(bag_handle, selector)
|
110
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
111
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
112
|
+
|
113
|
+
mqai_add_inquiry(bag_handle, selector, completion_code_ptr, reason_code_ptr)
|
114
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot add inquiry to admin bag" if completion_code_ptr.read_long != MQCC_OK
|
115
|
+
end
|
116
|
+
|
117
|
+
def execute(connection_handle, command, options_bag, admin_bag, response_bag,
|
118
|
+
admin_queue, response_queue)
|
119
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
120
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
121
|
+
|
122
|
+
mqai_execute(connection_handle, command, options_bag, admin_bag,
|
123
|
+
response_bag, admin_queue, response_queue, completion_code_ptr, reason_code_ptr)
|
124
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot execute admin bag" if completion_code_ptr.read_long != MQCC_OK
|
125
|
+
end
|
126
|
+
|
127
|
+
def count_items(bag_handle, selector)
|
128
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
129
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
130
|
+
|
131
|
+
number_of_bags_ptr = FFI::MemoryPointer.new :long
|
132
|
+
mqai_count_items(bag_handle, selector, number_of_bags_ptr, completion_code_ptr, reason_code_ptr)
|
133
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot count items in response bag" if completion_code_ptr.read_long != MQCC_OK
|
134
|
+
|
135
|
+
number_of_bags_ptr.read_long
|
136
|
+
end
|
137
|
+
|
138
|
+
def inquire_bag(bag_handle, selector, item_index)
|
139
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
140
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
141
|
+
|
142
|
+
item_value_ptr = FFI::MemoryPointer.new :long
|
143
|
+
mqai_inquire_bag(bag_handle, selector, item_index, item_value_ptr, completion_code_ptr, reason_code_ptr)
|
144
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot inquire attributes bag handle from response bag" if completion_code_ptr.read_long != MQCC_OK
|
145
|
+
|
146
|
+
item_value_ptr.read_long
|
147
|
+
end
|
148
|
+
|
149
|
+
def inquire_string(bag_handle, selector, item_index)
|
150
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
151
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
152
|
+
|
153
|
+
string_ptr = FFI::MemoryPointer.new :char, 255
|
154
|
+
length_ptr = FFI::MemoryPointer.new :long
|
155
|
+
mqai_inquire_string(bag_handle, selector, item_index, 255, string_ptr, length_ptr, nil, completion_code_ptr, reason_code_ptr)
|
156
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot inquire string from attributes bag" if completion_code_ptr.read_long != MQCC_OK
|
157
|
+
|
158
|
+
string_ptr.read_string.strip
|
159
|
+
end
|
160
|
+
|
161
|
+
def inquire_integer(bag_handle, selector, item_index)
|
162
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
163
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
164
|
+
item_value_ptr = FFI::MemoryPointer.new :long
|
165
|
+
|
166
|
+
mqai_inquire_integer(bag_handle, selector, item_index, item_value_ptr, completion_code_ptr, reason_code_ptr)
|
167
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot inquire integer from attributes bag" if completion_code_ptr.read_long != MQCC_OK
|
168
|
+
|
169
|
+
item_value_ptr.read_long
|
170
|
+
end
|
171
|
+
|
172
|
+
def delete_bag(bag_handle)
|
173
|
+
unless bag_handle == MQHB_UNUSABLE_HBAG
|
174
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
175
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
176
|
+
bag_handle_ptr = FFI::MemoryPointer.new :long
|
177
|
+
bag_handle_ptr.write_long(bag_handle)
|
178
|
+
|
179
|
+
mqai_delete_bag(bag_handle_ptr, completion_code_ptr, reason_code_ptr)
|
180
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot delete bag" if completion_code_ptr.read_long != MQCC_OK
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def open_queue(connection_handle, queue_name, options)
|
185
|
+
object_descriptor = MQClient::ObjectDescriptor.new
|
186
|
+
object_descriptor[:StrucId] = MQClient::ObjectDescriptor::MQOD_STRUC_ID
|
187
|
+
object_descriptor[:Version] = MQClient::ObjectDescriptor::MQOD_VERSION_1
|
188
|
+
object_descriptor[:ObjectType] = MQClient::ObjectDescriptor::MQOT_Q
|
189
|
+
object_descriptor[:ObjectName] = queue_name
|
190
|
+
|
191
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
192
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
193
|
+
queue_handle_ptr = FFI::MemoryPointer.new :long
|
194
|
+
|
195
|
+
mqopen(connection_handle, object_descriptor, options, queue_handle_ptr,
|
196
|
+
completion_code_ptr, reason_code_ptr)
|
197
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot open queue" if completion_code_ptr.read_long != MQCC_OK
|
198
|
+
|
199
|
+
queue_handle_ptr.read_long
|
200
|
+
end
|
201
|
+
|
202
|
+
def close_queue(connection_handle, queue_handle, options)
|
203
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
204
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
205
|
+
|
206
|
+
queue_handle_ptr = FFI::MemoryPointer.new :long
|
207
|
+
queue_handle_ptr.write_long(queue_handle)
|
208
|
+
|
209
|
+
mqclose(connection_handle, queue_handle_ptr, options, completion_code_ptr, reason_code_ptr)
|
210
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot close queue" if completion_code_ptr.read_long != MQCC_OK
|
211
|
+
end
|
212
|
+
|
213
|
+
def put_message_on_queue(connection_handle, queue_handle, payload)
|
214
|
+
message_options = MQClient::PutMessageOptions.new
|
215
|
+
message_options[:StrucId] = MQClient::PutMessageOptions::MQPMO_STRUC_ID
|
216
|
+
message_options[:Version] = MQClient::PutMessageOptions::MQPMO_VERSION_1
|
217
|
+
|
218
|
+
message_descriptor = MQClient::MessageDescriptor.new
|
219
|
+
message_descriptor[:StrucId] = MQClient::MessageDescriptor::MQMD_STRUC_ID
|
220
|
+
message_descriptor[:Version] = MQClient::MessageDescriptor::MQMD_VERSION_1
|
221
|
+
message_descriptor[:Expiry] = MQClient::MessageDescriptor::MQEI_UNLIMITED
|
222
|
+
message_descriptor[:Report] = MQClient::MessageDescriptor::MQRO_NONE
|
223
|
+
message_descriptor[:MsgType] = MQClient::MessageDescriptor::MQMT_DATAGRAM
|
224
|
+
message_descriptor[:Priority] = 1
|
225
|
+
message_descriptor[:Persistence] = MQClient::MessageDescriptor::MQPER_PERSISTENT
|
226
|
+
message_descriptor[:ReplyToQ] = ""
|
227
|
+
|
228
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
229
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
230
|
+
|
231
|
+
mqput(connection_handle, queue_handle, message_descriptor, message_options, payload.length, payload, completion_code_ptr, reason_code_ptr)
|
232
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot send message" if completion_code_ptr.read_long != MQCC_OK
|
233
|
+
end
|
234
|
+
|
235
|
+
def queue_depth(connection_handle, queue_name)
|
236
|
+
adminbag_handle = create_admin_bag
|
237
|
+
responsebag_handle = create_response_bag
|
238
|
+
|
239
|
+
add_string_to_bag(adminbag_handle, MQCA_Q_NAME, queue_name)
|
240
|
+
add_integer_to_bag(adminbag_handle, MQIA_Q_TYPE, MQQT_LOCAL)
|
241
|
+
add_inquiry(adminbag_handle, MQIA_CURRENT_Q_DEPTH)
|
242
|
+
|
243
|
+
execute(connection_handle, MQCMD_INQUIRE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
|
244
|
+
|
245
|
+
attributes_bag_handle = inquire_bag(responsebag_handle, MQHA_BAG_HANDLE, 0)
|
246
|
+
queue_depth = inquire_integer(attributes_bag_handle, MQIA_CURRENT_Q_DEPTH, 0)
|
247
|
+
|
248
|
+
delete_bag(adminbag_handle)
|
249
|
+
delete_bag(responsebag_handle)
|
250
|
+
|
251
|
+
queue_depth
|
252
|
+
end
|
253
|
+
|
254
|
+
def get_message_from_queue(connection_handle, queue_handle)
|
255
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
256
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
257
|
+
data_length_ptr = FFI::MemoryPointer.new :long
|
258
|
+
|
259
|
+
message_options = GetMessageOptions.new
|
260
|
+
message_options[:StrucId] = GetMessageOptions::MQGMO_STRUC_ID
|
261
|
+
message_options[:Version] = GetMessageOptions::MQGMO_VERSION_1
|
262
|
+
message_options[:Options] = GetMessageOptions::MQGMO_ACCEPT_TRUNCATED_MSG
|
263
|
+
|
264
|
+
message_descriptor = MQClient::MessageDescriptor.new
|
265
|
+
message_descriptor[:StrucId] = MQClient::MessageDescriptor::MQMD_STRUC_ID
|
266
|
+
message_descriptor[:Version] = MQClient::MessageDescriptor::MQMD_VERSION_1
|
267
|
+
|
268
|
+
# TODO determine message length and then reissue call
|
269
|
+
# mqget(connection_handle, queue_handle, message_descriptor, message_options, 0, nil, data_length_ptr, completion_code_ptr, reason_code_ptr)
|
270
|
+
# raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot learn message length" if completion_code_ptr.read_long == MQCC_FAILED
|
271
|
+
|
272
|
+
# data_length = data_length_ptr.read_long
|
273
|
+
data_length = 8192
|
274
|
+
buffer_ptr = FFI::MemoryPointer.new :char, data_length
|
275
|
+
mqget(connection_handle, queue_handle, message_descriptor, message_options, data_length, buffer_ptr, data_length_ptr, completion_code_ptr, reason_code_ptr)
|
276
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot learn message length" if completion_code_ptr.read_long == MQCC_FAILED
|
277
|
+
|
278
|
+
buffer_ptr.read_string
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RMQ
|
2
|
+
module MQClient
|
3
|
+
|
4
|
+
class ObjectDescriptor < FFI::Struct
|
5
|
+
MQOD_STRUC_ID = "OD "
|
6
|
+
MQOD_VERSION_1 = 1
|
7
|
+
|
8
|
+
# Object Types
|
9
|
+
MQOT_NONE = 0
|
10
|
+
MQOT_Q = 1
|
11
|
+
MQOT_NAMELIST = 2
|
12
|
+
MQOT_PROCESS = 3
|
13
|
+
MQOT_STORAGE_CLASS = 4
|
14
|
+
MQOT_Q_MGR = 5
|
15
|
+
MQOT_CHANNEL = 6
|
16
|
+
MQOT_AUTH_INFO = 7
|
17
|
+
MQOT_TOPIC = 8
|
18
|
+
MQOT_CF_STRUC = 10
|
19
|
+
MQOT_LISTENER = 11
|
20
|
+
MQOT_SERVICE = 12
|
21
|
+
MQOT_RESERVED_1 = 999
|
22
|
+
|
23
|
+
|
24
|
+
layout :StrucId, [:char, 4],
|
25
|
+
:Version, :long,
|
26
|
+
:ObjectType, :long,
|
27
|
+
:ObjectName, [:char, 48],
|
28
|
+
:ObjectQMgrName, [:char, 48],
|
29
|
+
:DynamicQName, [:char, 48],
|
30
|
+
:AlternateUserId, [:char, 12],
|
31
|
+
:RecsPresent, :long,
|
32
|
+
:KnownDestCount, :long,
|
33
|
+
:UnknownDestCount, :long,
|
34
|
+
:InvalidDestCount, :long,
|
35
|
+
:ObjectRecOffset, :long,
|
36
|
+
:ResponseRecOffset, :long,
|
37
|
+
:ObjectRecPtr, :pointer,
|
38
|
+
:ResponseRecPtr, :pointer
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RMQ
|
2
|
+
module MQClient
|
3
|
+
|
4
|
+
class PutMessageOptions < FFI::Struct
|
5
|
+
MQPMO_STRUC_ID = "PMO "
|
6
|
+
MQPMO_VERSION_1 = 1
|
7
|
+
MQPMO_SYNCPOINT = 0x00000002
|
8
|
+
|
9
|
+
layout :StrucId, [:char, 4],
|
10
|
+
:Version, :long,
|
11
|
+
:Options, :long,
|
12
|
+
:Timeout, :long,
|
13
|
+
:Context, :long,
|
14
|
+
:KnownDestCount, :long,
|
15
|
+
:UnknownDestCount, :long,
|
16
|
+
:InvalidDestCount, :long,
|
17
|
+
:ResolvedQName, [:char, 48],
|
18
|
+
:ResolvedQMgrName, [:char, 48],
|
19
|
+
:RecsPresent, :long,
|
20
|
+
:PutMsgRecFields, :long,
|
21
|
+
:PutMsgRecOffset, :long,
|
22
|
+
:ResponseRecOffset, :long,
|
23
|
+
:PutMsgRecPtr, :pointer,
|
24
|
+
:ResponseRecPtr, :pointer,
|
25
|
+
:OriginalMsgHandle, :int64,
|
26
|
+
:NewMsgHandle, :int64,
|
27
|
+
:Action, :long,
|
28
|
+
:PubLevel, :long
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|