rmq 0.0.6 → 0.0.7
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 +13 -13
- data/lib/rmq/constants.rb +1497 -1497
- data/lib/rmq/exceptions.rb +21 -21
- data/lib/rmq/get_message_options.rb +55 -55
- data/lib/rmq/message.rb +13 -13
- data/lib/rmq/message_descriptor.rb +46 -46
- data/lib/rmq/mqclient.rb +333 -324
- data/lib/rmq/object_descriptor.rb +41 -41
- data/lib/rmq/put_message_options.rb +31 -31
- data/lib/rmq/queue.rb +54 -54
- data/lib/rmq/queue_manager.rb +107 -107
- data/lib/rmq/version.rb +2 -2
- data/spec/rmq/queue_manager_spec.rb +59 -63
- data/spec/rmq/queue_spec.rb +47 -47
- data/spec/spec_helper.rb +20 -20
- metadata +15 -15
data/lib/rmq/exceptions.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
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
|
-
|
18
|
-
class RMQTimeOutError < RuntimeError
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
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
|
+
|
18
|
+
class RMQTimeOutError < RuntimeError
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -1,55 +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
|
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
|
data/lib/rmq/message.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
module RMQ
|
2
|
-
class Message
|
3
|
-
attr_reader :payload
|
4
|
-
|
5
|
-
def initialize(payload, message_descriptor)
|
6
|
-
@payload = payload
|
7
|
-
@message_descriptor = message_descriptor
|
8
|
-
end
|
9
|
-
|
10
|
-
def reply_queue_name
|
11
|
-
@message_descriptor[:ReplyToQ].to_s.strip
|
12
|
-
end
|
13
|
-
end
|
1
|
+
module RMQ
|
2
|
+
class Message
|
3
|
+
attr_reader :payload
|
4
|
+
|
5
|
+
def initialize(payload, message_descriptor)
|
6
|
+
@payload = payload
|
7
|
+
@message_descriptor = message_descriptor
|
8
|
+
end
|
9
|
+
|
10
|
+
def reply_queue_name
|
11
|
+
@message_descriptor[:ReplyToQ].to_s.strip
|
12
|
+
end
|
13
|
+
end
|
14
14
|
end
|
@@ -1,46 +1,46 @@
|
|
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
|
-
MSG_ID_LENGTH = 24
|
13
|
-
|
14
|
-
layout :StrucId, [:char, 4],
|
15
|
-
:Version, :long,
|
16
|
-
:Report, :long,
|
17
|
-
:MsgType, :long,
|
18
|
-
:Expiry, :long,
|
19
|
-
:Feedback, :long,
|
20
|
-
:Encoding, :long,
|
21
|
-
:CodedCharSetId, :long,
|
22
|
-
:Format, [:char, 8],
|
23
|
-
:Priority, :long,
|
24
|
-
:Persistence, :long,
|
25
|
-
:MsgId, [:char, MSG_ID_LENGTH],
|
26
|
-
:CorrelId, [:char, 24],
|
27
|
-
:BackoutCount, :long,
|
28
|
-
:ReplyToQ, [:char, 48],
|
29
|
-
:ReplyToQMgr, [:char, 48],
|
30
|
-
:UserIdentifier, [:char, 12],
|
31
|
-
:AccountingToken, [:char, 32],
|
32
|
-
:ApplIdentityData, [:char, 32],
|
33
|
-
:PutApplType, :long,
|
34
|
-
:PutApplName, [:char, 28],
|
35
|
-
:PutDate, [:char, 8],
|
36
|
-
:PutTime, [:char, 8],
|
37
|
-
:ApplOriginData, [:char, 4],
|
38
|
-
:GroupId, [:char, 24],
|
39
|
-
:MsgSeqNumber, :long,
|
40
|
-
:Offset, :long,
|
41
|
-
:MsgFlags, :long,
|
42
|
-
:OriginalLength, :long
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
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
|
+
MSG_ID_LENGTH = 24
|
13
|
+
|
14
|
+
layout :StrucId, [:char, 4],
|
15
|
+
:Version, :long,
|
16
|
+
:Report, :long,
|
17
|
+
:MsgType, :long,
|
18
|
+
:Expiry, :long,
|
19
|
+
:Feedback, :long,
|
20
|
+
:Encoding, :long,
|
21
|
+
:CodedCharSetId, :long,
|
22
|
+
:Format, [:char, 8],
|
23
|
+
:Priority, :long,
|
24
|
+
:Persistence, :long,
|
25
|
+
:MsgId, [:char, MSG_ID_LENGTH],
|
26
|
+
:CorrelId, [:char, 24],
|
27
|
+
:BackoutCount, :long,
|
28
|
+
:ReplyToQ, [:char, 48],
|
29
|
+
:ReplyToQMgr, [:char, 48],
|
30
|
+
:UserIdentifier, [:char, 12],
|
31
|
+
:AccountingToken, [:char, 32],
|
32
|
+
:ApplIdentityData, [:char, 32],
|
33
|
+
:PutApplType, :long,
|
34
|
+
:PutApplName, [:char, 28],
|
35
|
+
:PutDate, [:char, 8],
|
36
|
+
:PutTime, [:char, 8],
|
37
|
+
:ApplOriginData, [:char, 4],
|
38
|
+
:GroupId, [:char, 24],
|
39
|
+
:MsgSeqNumber, :long,
|
40
|
+
:Offset, :long,
|
41
|
+
:MsgFlags, :long,
|
42
|
+
:OriginalLength, :long
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/rmq/mqclient.rb
CHANGED
@@ -1,324 +1,333 @@
|
|
1
|
-
module RMQ
|
2
|
-
module MQClient
|
3
|
-
include Constants
|
4
|
-
extend FFI::Library
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
completion_code_ptr = FFI::MemoryPointer.new :long
|
120
|
-
reason_code_ptr = FFI::MemoryPointer.new :long
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
completion_code_ptr = FFI::MemoryPointer.new :long
|
129
|
-
reason_code_ptr = FFI::MemoryPointer.new :long
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
end
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
message_descriptor
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
1
|
+
module RMQ
|
2
|
+
module MQClient
|
3
|
+
include Constants
|
4
|
+
extend FFI::Library
|
5
|
+
|
6
|
+
def MQClient.running_on_windows?
|
7
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def MQClient.running_on_linux?
|
11
|
+
RUBY_PLATFORM.include?("linux")
|
12
|
+
end
|
13
|
+
|
14
|
+
ffi_lib "mqic32.dll" if running_on_windows?
|
15
|
+
ffi_lib "libmqic" if running_on_linux?
|
16
|
+
ffi_convention :stdcall
|
17
|
+
|
18
|
+
attach_function :mqconn, :MQCONN,
|
19
|
+
[:string, :pointer, :pointer, :pointer], :void
|
20
|
+
attach_function :mqdisc, :MQDISC,
|
21
|
+
[:pointer, :pointer, :pointer], :void
|
22
|
+
|
23
|
+
# MQPUT (Hconn, Hobj, &MsgDesc, &PutMsgOpts, BufferLength, &Buffer, &CompCode, &Reason)
|
24
|
+
attach_function :mqput, :MQPUT,
|
25
|
+
[:long, :long, :pointer, :pointer, :long, :string, :pointer, :pointer], :void
|
26
|
+
|
27
|
+
# MQGET (Hconn, Hobj, &MsgDesc, &GetMsgOpts, BufferLength, Buffer, &DataLength, &CompCode, &Reason)
|
28
|
+
attach_function :mqget, :MQGET,
|
29
|
+
[:long, :long, :pointer, :pointer, :long, :pointer, :pointer, :pointer, :pointer], :void
|
30
|
+
|
31
|
+
# MQOPEN (Hconn, &ObjDesc, Options, &Hobj, &CompCode, &Reason)
|
32
|
+
attach_function :mqopen, :MQOPEN,
|
33
|
+
[:long, :pointer, :long, :pointer, :pointer, :pointer], :void
|
34
|
+
|
35
|
+
# MQCLOSE (Hconn, &Hobj, Options, &CompCode, &Reason)
|
36
|
+
attach_function :mqclose, :MQCLOSE,
|
37
|
+
[:long, :pointer, :long, :pointer, :pointer], :void
|
38
|
+
|
39
|
+
# mqCreateBag (Options, &Bag, &CompCode, &Reason)
|
40
|
+
attach_function :mqai_create_bag, :mqCreateBag,
|
41
|
+
[:long, :pointer, :pointer, :pointer], :void
|
42
|
+
|
43
|
+
# mqAddString (hBag, Selector, BufferLength, Buffer, &CompCode, &Reason)
|
44
|
+
attach_function :mqai_add_string, :mqAddString,
|
45
|
+
[:long, :long, :long, :string, :pointer, :pointer], :void
|
46
|
+
|
47
|
+
# mqAddInteger (Bag, Selector, ItemValue, &CompCode, &Reason)
|
48
|
+
attach_function :mqai_add_integer, :mqAddInteger,
|
49
|
+
[:long, :long, :long, :pointer, :pointer], :void
|
50
|
+
|
51
|
+
# mqInquireString (Bag, Selector, ItemIndex, BufferLength, Buffer, &StringLength, &CodedCharSetId, &CompCode, &Reason)
|
52
|
+
attach_function :mqai_inquire_string, :mqInquireString,
|
53
|
+
[:long, :long, :long, :long, :pointer, :pointer, :pointer, :pointer, :pointer], :void
|
54
|
+
|
55
|
+
# mqInquireInteger (Bag, Selector, ItemIndex, &ItemValue, &CompCode, &Reason);
|
56
|
+
attach_function :mqai_inquire_integer, :mqInquireInteger,
|
57
|
+
[:long, :long, :long, :pointer, :pointer, :pointer], :void
|
58
|
+
|
59
|
+
# mqAddInquiry (Bag, Selector, &CompCode, &Reason)
|
60
|
+
attach_function :mqai_add_inquiry, :mqAddInquiry,
|
61
|
+
[:long, :long, :pointer, :pointer], :void
|
62
|
+
|
63
|
+
# mqExecute (Hconn, Command, OptionsBag, AdminBag, ResponseBag, AdminQ, ResponseQ, CompCode, Reason)
|
64
|
+
attach_function :mqai_execute, :mqExecute,
|
65
|
+
[:long, :long, :long, :long, :long, :long, :long, :pointer, :pointer], :void
|
66
|
+
|
67
|
+
# mqCountItems (Bag, Selector, &ItemCount, &CompCode, &Reason)
|
68
|
+
attach_function :mqai_count_items, :mqCountItems,
|
69
|
+
[:long, :long, :pointer, :pointer, :pointer], :void
|
70
|
+
|
71
|
+
# mqInquireBag (Bag, Selector, ItemIndex, &ItemValue, &CompCode, &Reason)
|
72
|
+
attach_function :mqai_inquire_bag, :mqInquireBag,
|
73
|
+
[:long, :long, :long, :pointer, :pointer, :pointer], :void
|
74
|
+
|
75
|
+
# mqDeleteBag (&Bag, CompCode, Reason)
|
76
|
+
attach_function :mqai_delete_bag, :mqDeleteBag,
|
77
|
+
[:pointer, :pointer, :pointer], :void
|
78
|
+
|
79
|
+
|
80
|
+
def create_admin_bag
|
81
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
82
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
83
|
+
|
84
|
+
adminbag_handle_ptr = FFI::MemoryPointer.new :long
|
85
|
+
mqai_create_bag(MQCBO_ADMIN_BAG, adminbag_handle_ptr, completion_code_ptr, reason_code_ptr)
|
86
|
+
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
|
87
|
+
|
88
|
+
adminbag_handle_ptr.read_long
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_response_bag
|
92
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
93
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
94
|
+
|
95
|
+
responsebag_handle_ptr = FFI::MemoryPointer.new :long
|
96
|
+
mqai_create_bag(MQCBO_ADMIN_BAG, responsebag_handle_ptr, completion_code_ptr, reason_code_ptr)
|
97
|
+
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
|
98
|
+
|
99
|
+
responsebag_handle_ptr.read_long
|
100
|
+
end
|
101
|
+
|
102
|
+
def add_string_to_bag(bag_handle, selector, value)
|
103
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
104
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
105
|
+
|
106
|
+
mqai_add_string(bag_handle, selector, MQBL_NULL_TERMINATED, value, completion_code_ptr, reason_code_ptr)
|
107
|
+
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
|
108
|
+
end
|
109
|
+
|
110
|
+
def add_integer_to_bag(bag_handle, selector, value)
|
111
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
112
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
113
|
+
|
114
|
+
mqai_add_integer(bag_handle, selector, value, completion_code_ptr, reason_code_ptr)
|
115
|
+
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
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_inquiry(bag_handle, selector)
|
119
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
120
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
121
|
+
|
122
|
+
mqai_add_inquiry(bag_handle, selector, completion_code_ptr, reason_code_ptr)
|
123
|
+
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
|
124
|
+
end
|
125
|
+
|
126
|
+
def execute(connection_handle, command, options_bag, admin_bag, response_bag,
|
127
|
+
admin_queue, response_queue)
|
128
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
129
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
130
|
+
|
131
|
+
mqai_execute(connection_handle, command, options_bag, admin_bag,
|
132
|
+
response_bag, admin_queue, response_queue, completion_code_ptr, reason_code_ptr)
|
133
|
+
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
|
134
|
+
end
|
135
|
+
|
136
|
+
def count_items(bag_handle, selector)
|
137
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
138
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
139
|
+
|
140
|
+
number_of_bags_ptr = FFI::MemoryPointer.new :long
|
141
|
+
mqai_count_items(bag_handle, selector, number_of_bags_ptr, completion_code_ptr, reason_code_ptr)
|
142
|
+
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
|
143
|
+
|
144
|
+
number_of_bags_ptr.read_long
|
145
|
+
end
|
146
|
+
|
147
|
+
def inquire_bag(bag_handle, selector, item_index)
|
148
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
149
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
150
|
+
|
151
|
+
item_value_ptr = FFI::MemoryPointer.new :long
|
152
|
+
mqai_inquire_bag(bag_handle, selector, item_index, item_value_ptr, completion_code_ptr, reason_code_ptr)
|
153
|
+
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
|
154
|
+
|
155
|
+
item_value_ptr.read_long
|
156
|
+
end
|
157
|
+
|
158
|
+
def inquire_string(bag_handle, selector, item_index)
|
159
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
160
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
161
|
+
|
162
|
+
string_ptr = FFI::MemoryPointer.new :char, 255
|
163
|
+
length_ptr = FFI::MemoryPointer.new :long
|
164
|
+
mqai_inquire_string(bag_handle, selector, item_index, 255, string_ptr, length_ptr, nil, completion_code_ptr, reason_code_ptr)
|
165
|
+
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
|
166
|
+
|
167
|
+
string_ptr.read_string.strip
|
168
|
+
end
|
169
|
+
|
170
|
+
def inquire_integer(bag_handle, selector, item_index)
|
171
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
172
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
173
|
+
item_value_ptr = FFI::MemoryPointer.new :long
|
174
|
+
|
175
|
+
mqai_inquire_integer(bag_handle, selector, item_index, item_value_ptr, completion_code_ptr, reason_code_ptr)
|
176
|
+
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
|
177
|
+
|
178
|
+
item_value_ptr.read_long
|
179
|
+
end
|
180
|
+
|
181
|
+
def delete_bag(bag_handle)
|
182
|
+
unless bag_handle == MQHB_UNUSABLE_HBAG
|
183
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
184
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
185
|
+
bag_handle_ptr = FFI::MemoryPointer.new :long
|
186
|
+
bag_handle_ptr.write_long(bag_handle)
|
187
|
+
|
188
|
+
mqai_delete_bag(bag_handle_ptr, completion_code_ptr, reason_code_ptr)
|
189
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot delete bag" if completion_code_ptr.read_long != MQCC_OK
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def open_queue(connection_handle, queue_name, options)
|
194
|
+
object_descriptor = MQClient::ObjectDescriptor.new
|
195
|
+
object_descriptor[:StrucId] = MQClient::ObjectDescriptor::MQOD_STRUC_ID
|
196
|
+
object_descriptor[:Version] = MQClient::ObjectDescriptor::MQOD_VERSION_1
|
197
|
+
object_descriptor[:ObjectType] = MQClient::ObjectDescriptor::MQOT_Q
|
198
|
+
object_descriptor[:ObjectName] = queue_name
|
199
|
+
|
200
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
201
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
202
|
+
queue_handle_ptr = FFI::MemoryPointer.new :long
|
203
|
+
|
204
|
+
mqopen(connection_handle, object_descriptor, options, queue_handle_ptr,
|
205
|
+
completion_code_ptr, reason_code_ptr)
|
206
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot open queue" if completion_code_ptr.read_long != MQCC_OK
|
207
|
+
|
208
|
+
queue_handle_ptr.read_long
|
209
|
+
end
|
210
|
+
|
211
|
+
def close_queue(connection_handle, queue_handle, options)
|
212
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
213
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
214
|
+
|
215
|
+
queue_handle_ptr = FFI::MemoryPointer.new :long
|
216
|
+
queue_handle_ptr.write_long(queue_handle)
|
217
|
+
|
218
|
+
mqclose(connection_handle, queue_handle_ptr, options, completion_code_ptr, reason_code_ptr)
|
219
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot close queue" if completion_code_ptr.read_long != MQCC_OK
|
220
|
+
end
|
221
|
+
|
222
|
+
def put_message_on_queue(connection_handle, queue_handle, payload, reply_queue_name = "")
|
223
|
+
message_options = MQClient::PutMessageOptions.new
|
224
|
+
message_options[:StrucId] = MQClient::PutMessageOptions::MQPMO_STRUC_ID
|
225
|
+
message_options[:Version] = MQClient::PutMessageOptions::MQPMO_VERSION_1
|
226
|
+
|
227
|
+
message_descriptor = MQClient::MessageDescriptor.new
|
228
|
+
message_descriptor[:StrucId] = MQClient::MessageDescriptor::MQMD_STRUC_ID
|
229
|
+
message_descriptor[:Version] = MQClient::MessageDescriptor::MQMD_VERSION_1
|
230
|
+
message_descriptor[:Expiry] = MQClient::MessageDescriptor::MQEI_UNLIMITED
|
231
|
+
message_descriptor[:Report] = MQClient::MessageDescriptor::MQRO_NONE
|
232
|
+
message_descriptor[:MsgType] = MQClient::MessageDescriptor::MQMT_DATAGRAM
|
233
|
+
message_descriptor[:Priority] = 1
|
234
|
+
message_descriptor[:Persistence] = MQClient::MessageDescriptor::MQPER_PERSISTENT
|
235
|
+
message_descriptor[:ReplyToQ] = reply_queue_name
|
236
|
+
|
237
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
238
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
239
|
+
|
240
|
+
mqput(connection_handle, queue_handle, message_descriptor, message_options, payload.length, payload, completion_code_ptr, reason_code_ptr)
|
241
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot send message" if completion_code_ptr.read_long != MQCC_OK
|
242
|
+
end
|
243
|
+
|
244
|
+
def queue_depth(connection_handle, queue_name)
|
245
|
+
adminbag_handle = create_admin_bag
|
246
|
+
responsebag_handle = create_response_bag
|
247
|
+
|
248
|
+
add_string_to_bag(adminbag_handle, MQCA_Q_NAME, queue_name)
|
249
|
+
add_integer_to_bag(adminbag_handle, MQIA_Q_TYPE, MQQT_LOCAL)
|
250
|
+
add_inquiry(adminbag_handle, MQIA_CURRENT_Q_DEPTH)
|
251
|
+
|
252
|
+
execute(connection_handle, MQCMD_INQUIRE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
|
253
|
+
|
254
|
+
attributes_bag_handle = inquire_bag(responsebag_handle, MQHA_BAG_HANDLE, 0)
|
255
|
+
queue_depth = inquire_integer(attributes_bag_handle, MQIA_CURRENT_Q_DEPTH, 0)
|
256
|
+
|
257
|
+
delete_bag(adminbag_handle)
|
258
|
+
delete_bag(responsebag_handle)
|
259
|
+
|
260
|
+
queue_depth
|
261
|
+
end
|
262
|
+
|
263
|
+
def get_message_from_queue(connection_handle, queue_handle, timeout)
|
264
|
+
puts "--- get message from queue"
|
265
|
+
completion_code_ptr = FFI::MemoryPointer.new :long
|
266
|
+
reason_code_ptr = FFI::MemoryPointer.new :long
|
267
|
+
data_length_ptr = FFI::MemoryPointer.new :long
|
268
|
+
|
269
|
+
message_options = prepare_get_message_options(timeout, false)
|
270
|
+
message_descriptor = prepare_get_message_descriptor
|
271
|
+
|
272
|
+
data_length = 8 * 1024
|
273
|
+
buffer_ptr = FFI::MemoryPointer.new :char, data_length
|
274
|
+
|
275
|
+
mqget(connection_handle, queue_handle, message_descriptor, message_options, data_length, buffer_ptr, data_length_ptr, completion_code_ptr, reason_code_ptr)
|
276
|
+
|
277
|
+
if (completion_code_ptr.read_long == MQCC_WARNING && reason_code_ptr.read_long == MQRC_TRUNCATED_MSG_FAILED)
|
278
|
+
msg_id = message_descriptor[:MsgId]
|
279
|
+
data_length = data_length_ptr.read_long
|
280
|
+
buffer_ptr = FFI::MemoryPointer.new :char, data_length
|
281
|
+
message_descriptor = prepare_get_message_descriptor(msg_id)
|
282
|
+
mqget(connection_handle, queue_handle, message_descriptor, message_options, data_length, buffer_ptr, data_length_ptr, completion_code_ptr, reason_code_ptr)
|
283
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot read message again after learning message length" if completion_code_ptr.read_long == MQCC_FAILED
|
284
|
+
else
|
285
|
+
raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot learn message length" unless completion_code_ptr.read_long == MQCC_OK
|
286
|
+
end
|
287
|
+
|
288
|
+
Message.new(buffer_ptr.read_string, message_descriptor)
|
289
|
+
end
|
290
|
+
|
291
|
+
private
|
292
|
+
|
293
|
+
def prepare_get_message_options(timeout, accept_truncated_msg)
|
294
|
+
message_options = GetMessageOptions.new
|
295
|
+
message_options[:StrucId] = GetMessageOptions::MQGMO_STRUC_ID
|
296
|
+
message_options[:Version] = GetMessageOptions::MQGMO_VERSION_1
|
297
|
+
message_options[:Options] = 0
|
298
|
+
|
299
|
+
if accept_truncated_msg
|
300
|
+
message_options[:Options] = GetMessageOptions::MQGMO_ACCEPT_TRUNCATED_MSG | message_options[:Options]
|
301
|
+
end
|
302
|
+
|
303
|
+
if timeout > 0
|
304
|
+
message_options[:Options] = GetMessageOptions::MQGMO_WAIT | message_options[:Options]
|
305
|
+
message_options[:WaitInterval] = timeout * 1000
|
306
|
+
end
|
307
|
+
|
308
|
+
message_options
|
309
|
+
end
|
310
|
+
|
311
|
+
def print_msg_id(msg_id)
|
312
|
+
puts "printing msg id"
|
313
|
+
for i in (0..MQClient::MessageDescriptor::MSG_ID_LENGTH-1) do
|
314
|
+
puts "#{i} = #{msg_id[i]}"
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
def prepare_get_message_descriptor(msg_id = nil)
|
319
|
+
message_descriptor = MQClient::MessageDescriptor.new
|
320
|
+
message_descriptor[:StrucId] = MQClient::MessageDescriptor::MQMD_STRUC_ID
|
321
|
+
message_descriptor[:Version] = MQClient::MessageDescriptor::MQMD_VERSION_1
|
322
|
+
|
323
|
+
if !msg_id.nil?
|
324
|
+
for i in (0..MQClient::MessageDescriptor::MSG_ID_LENGTH-1) do
|
325
|
+
message_descriptor[:MsgId][i] = msg_id[i]
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
message_descriptor
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
end
|