rabbitmq 0.2.5 → 1.0.0.pre.pre
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.
- checksums.yaml +4 -4
- data/README.md +67 -2
- data/lib/rabbitmq.rb +1 -1
- data/lib/rabbitmq/channel.rb +117 -81
- data/lib/rabbitmq/client.rb +332 -0
- data/lib/rabbitmq/{connection/transport.rb → client/connection.rb} +32 -11
- data/lib/rabbitmq/ffi.rb +486 -483
- data/lib/rabbitmq/util.rb +6 -3
- metadata +6 -7
- data/lib/rabbitmq/connection.rb +0 -382
- data/lib/rabbitmq/connection/channel_manager.rb +0 -61
- data/lib/rabbitmq/connection/event_manager.rb +0 -55
@@ -2,21 +2,37 @@
|
|
2
2
|
require 'socket'
|
3
3
|
|
4
4
|
module RabbitMQ
|
5
|
-
class
|
5
|
+
class Client
|
6
6
|
|
7
|
+
# Raised when an operation is performed on an alread-destroyed {Client}.
|
7
8
|
class DestroyedError < RuntimeError; end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
# Represents a connection to a single RabbitMQ server.
|
11
|
+
# Used internally by the {Client} class.
|
12
|
+
# @api private
|
13
|
+
class Connection
|
11
14
|
attr_reader :ptr
|
15
|
+
attr_reader :options
|
12
16
|
|
13
|
-
def initialize(
|
17
|
+
def initialize(*args)
|
14
18
|
@ptr = FFI.amqp_new_connection
|
15
19
|
@frame = FFI::Frame.new
|
16
|
-
@connection = connnection
|
17
20
|
|
18
21
|
create_socket!
|
19
22
|
|
23
|
+
info = Util.connection_info(*args)
|
24
|
+
@options = {
|
25
|
+
ssl: (info.fetch(:ssl) ? true : false),
|
26
|
+
host: info.fetch(:host).to_s,
|
27
|
+
port: Integer(info.fetch(:port)),
|
28
|
+
user: info.fetch(:user).to_s,
|
29
|
+
password: info.fetch(:password).to_s,
|
30
|
+
vhost: info.fetch(:vhost).to_s,
|
31
|
+
max_channels: Integer(info.fetch(:max_channels, FFI::CHANNEL_MAX_ID)),
|
32
|
+
max_frame_size: Integer(info.fetch(:max_frame_size, 131072)),
|
33
|
+
heartbeat_interval: 0, # not fully implemented in librabbitmq
|
34
|
+
}
|
35
|
+
|
20
36
|
@finalizer = self.class.create_finalizer_for(@ptr)
|
21
37
|
ObjectSpace.define_finalizer(self, @finalizer)
|
22
38
|
end
|
@@ -42,6 +58,11 @@ module RabbitMQ
|
|
42
58
|
@ptr
|
43
59
|
end
|
44
60
|
|
61
|
+
def start
|
62
|
+
connect_socket!
|
63
|
+
login!
|
64
|
+
end
|
65
|
+
|
45
66
|
def close
|
46
67
|
raise DestroyedError unless @ptr
|
47
68
|
FFI.amqp_connection_close(@ptr, 200)
|
@@ -56,11 +77,11 @@ module RabbitMQ
|
|
56
77
|
|
57
78
|
def connect_socket!
|
58
79
|
raise DestroyedError unless @ptr
|
59
|
-
raise NotImplementedError if @
|
80
|
+
raise NotImplementedError if @options[:ssl]
|
60
81
|
|
61
82
|
create_socket!
|
62
83
|
Util.error_check :"opening a socket",
|
63
|
-
FFI.amqp_socket_open(@socket, @
|
84
|
+
FFI.amqp_socket_open(@socket, @options[:host], @options[:port])
|
64
85
|
|
65
86
|
@ruby_socket = Socket.for_fd(FFI.amqp_get_sockfd(@ptr))
|
66
87
|
@ruby_socket.autoclose = false
|
@@ -69,10 +90,10 @@ module RabbitMQ
|
|
69
90
|
def login!
|
70
91
|
raise DestroyedError unless @ptr
|
71
92
|
|
72
|
-
res = FFI.amqp_login(@ptr, @
|
73
|
-
@
|
74
|
-
@
|
75
|
-
:string, @
|
93
|
+
res = FFI.amqp_login(@ptr, @options[:vhost],
|
94
|
+
@options[:max_channels], @options[:max_frame_size],
|
95
|
+
@options[:heartbeat_interval], :plain,
|
96
|
+
:string, @options[:user], :string, @options[:password])
|
76
97
|
|
77
98
|
case res[:reply_type]
|
78
99
|
when :library_exception; Util.error_check :"logging in", res[:library_error]
|
data/lib/rabbitmq/ffi.rb
CHANGED
@@ -3,6 +3,11 @@ require 'ffi'
|
|
3
3
|
|
4
4
|
|
5
5
|
module RabbitMQ
|
6
|
+
|
7
|
+
# Bindings and wrappers for the native functions and structures exposed by
|
8
|
+
# the librabbitmq C library. This module is for internal use only so that
|
9
|
+
# all dependencies on the implementation of the C library are abstracted.
|
10
|
+
# @api private
|
6
11
|
module FFI
|
7
12
|
extend ::FFI::Library
|
8
13
|
|
@@ -12,493 +17,491 @@ module RabbitMQ
|
|
12
17
|
ffi_lib \
|
13
18
|
File.expand_path("../../ext/rabbitmq/#{libfile}", File.dirname(__FILE__))
|
14
19
|
|
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
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
end
|
20
|
+
opts = {
|
21
|
+
blocking: true # only necessary on MRI to deal with the GIL.
|
22
|
+
}
|
23
|
+
|
24
|
+
attach_function :free, [:pointer], :void, **opts
|
25
|
+
attach_function :malloc, [:size_t], :pointer, **opts
|
26
|
+
|
27
|
+
attach_function :amqp_version_number, [], :uint32, **opts
|
28
|
+
attach_function :amqp_version, [], :string, **opts
|
29
|
+
|
30
|
+
Status = enum ::FFI::TypeDefs[:int], [
|
31
|
+
:ok, 0x0,
|
32
|
+
:no_memory, -0x0001,
|
33
|
+
:bad_amqp_data, -0x0002,
|
34
|
+
:unknown_class, -0x0003,
|
35
|
+
:unknown_method, -0x0004,
|
36
|
+
:hostname_resolution_failed, -0x0005,
|
37
|
+
:incompatible_amqp_version, -0x0006,
|
38
|
+
:connection_closed, -0x0007,
|
39
|
+
:bad_url, -0x0008,
|
40
|
+
:socket_error, -0x0009,
|
41
|
+
:invalid_parameter, -0x000A,
|
42
|
+
:table_too_big, -0x000B,
|
43
|
+
:wrong_method, -0x000C,
|
44
|
+
:timeout, -0x000D,
|
45
|
+
:timer_failure, -0x000E,
|
46
|
+
:heartbeat_timeout, -0x000F,
|
47
|
+
:unexpected_state, -0x0010,
|
48
|
+
:unexpected_socket_closed, -0x0011,
|
49
|
+
:unexpected_socket_inuse, -0x0012,
|
50
|
+
:tcp_error, -0x0100,
|
51
|
+
:tcp_socketlib_init_error, -0x0101,
|
52
|
+
:ssl_error, -0x0200,
|
53
|
+
:ssl_hostname_verify_failed, -0x0201,
|
54
|
+
:ssl_peer_verify_failed, -0x0202,
|
55
|
+
:ssl_connection_failed, -0x0203,
|
56
|
+
]
|
57
|
+
|
58
|
+
DeliveryMode = enum ::FFI::TypeDefs[:uint8], [
|
59
|
+
:nonpersistent, 1,
|
60
|
+
:persistent, 2,
|
61
|
+
]
|
62
|
+
|
63
|
+
class Timeval < ::FFI::Struct
|
64
|
+
layout :tv_sec, :time_t,
|
65
|
+
:tv_usec, :suseconds_t
|
66
|
+
end
|
67
|
+
|
68
|
+
class Boolean
|
69
|
+
extend ::FFI::DataConverter
|
70
|
+
native_type ::FFI::TypeDefs[:int]
|
71
|
+
def self.to_native val, ctx; val ? 1 : 0; end
|
72
|
+
def self.from_native val, ctx; val != 0; end
|
73
|
+
end
|
74
|
+
|
75
|
+
MethodNumber = enum ::FFI::TypeDefs[:uint32], [
|
76
|
+
:connection_start, 0x000A000A, # 10, 10; 655370
|
77
|
+
:connection_start_ok, 0x000A000B, # 10, 11; 655371
|
78
|
+
:connection_secure, 0x000A0014, # 10, 20; 655380
|
79
|
+
:connection_secure_ok, 0x000A0015, # 10, 21; 655381
|
80
|
+
:connection_tune, 0x000A001E, # 10, 30; 655390
|
81
|
+
:connection_tune_ok, 0x000A001F, # 10, 31; 655391
|
82
|
+
:connection_open, 0x000A0028, # 10, 40; 655400
|
83
|
+
:connection_open_ok, 0x000A0029, # 10, 41; 655401
|
84
|
+
:connection_close, 0x000A0032, # 10, 50; 655410
|
85
|
+
:connection_close_ok, 0x000A0033, # 10, 51; 655411
|
86
|
+
:connection_blocked, 0x000A003C, # 10, 60; 655420
|
87
|
+
:connection_unblocked, 0x000A003D, # 10, 61; 655421
|
88
|
+
:channel_open, 0x0014000A, # 20, 10; 1310730
|
89
|
+
:channel_open_ok, 0x0014000B, # 20, 11; 1310731
|
90
|
+
:channel_flow, 0x00140014, # 20, 20; 1310740
|
91
|
+
:channel_flow_ok, 0x00140015, # 20, 21; 1310741
|
92
|
+
:channel_close, 0x00140028, # 20, 40; 1310760
|
93
|
+
:channel_close_ok, 0x00140029, # 20, 41; 1310761
|
94
|
+
:access_request, 0x001E000A, # 30, 10; 1966090
|
95
|
+
:access_request_ok, 0x001E000B, # 30, 11; 1966091
|
96
|
+
:exchange_declare, 0x0028000A, # 40, 10; 2621450
|
97
|
+
:exchange_declare_ok, 0x0028000B, # 40, 11; 2621451
|
98
|
+
:exchange_delete, 0x00280014, # 40, 20; 2621460
|
99
|
+
:exchange_delete_ok, 0x00280015, # 40, 21; 2621461
|
100
|
+
:exchange_bind, 0x0028001E, # 40, 30; 2621470
|
101
|
+
:exchange_bind_ok, 0x0028001F, # 40, 31; 2621471
|
102
|
+
:exchange_unbind, 0x00280028, # 40, 40; 2621480
|
103
|
+
:exchange_unbind_ok, 0x00280033, # 40, 51; 2621491
|
104
|
+
:queue_declare, 0x0032000A, # 50, 10; 3276810
|
105
|
+
:queue_declare_ok, 0x0032000B, # 50, 11; 3276811
|
106
|
+
:queue_bind, 0x00320014, # 50, 20; 3276820
|
107
|
+
:queue_bind_ok, 0x00320015, # 50, 21; 3276821
|
108
|
+
:queue_purge, 0x0032001E, # 50, 30; 3276830
|
109
|
+
:queue_purge_ok, 0x0032001F, # 50, 31; 3276831
|
110
|
+
:queue_delete, 0x00320028, # 50, 40; 3276840
|
111
|
+
:queue_delete_ok, 0x00320029, # 50, 41; 3276841
|
112
|
+
:queue_unbind, 0x00320032, # 50, 50; 3276850
|
113
|
+
:queue_unbind_ok, 0x00320033, # 50, 51; 3276851
|
114
|
+
:basic_qos, 0x003C000A, # 60, 10; 3932170
|
115
|
+
:basic_qos_ok, 0x003C000B, # 60, 11; 3932171
|
116
|
+
:basic_consume, 0x003C0014, # 60, 20; 3932180
|
117
|
+
:basic_consume_ok, 0x003C0015, # 60, 21; 3932181
|
118
|
+
:basic_cancel, 0x003C001E, # 60, 30; 3932190
|
119
|
+
:basic_cancel_ok, 0x003C001F, # 60, 31; 3932191
|
120
|
+
:basic_publish, 0x003C0028, # 60, 40; 3932200
|
121
|
+
:basic_return, 0x003C0032, # 60, 50; 3932210
|
122
|
+
:basic_deliver, 0x003C003C, # 60, 60; 3932220
|
123
|
+
:basic_get, 0x003C0046, # 60, 70; 3932230
|
124
|
+
:basic_get_ok, 0x003C0047, # 60, 71; 3932231
|
125
|
+
:basic_get_empty, 0x003C0048, # 60, 72; 3932232
|
126
|
+
:basic_ack, 0x003C0050, # 60, 80; 3932240
|
127
|
+
:basic_reject, 0x003C005A, # 60, 90; 3932250
|
128
|
+
:basic_recover_async, 0x003C0064, # 60, 100; 3932260
|
129
|
+
:basic_recover, 0x003C006E, # 60, 110; 3932270
|
130
|
+
:basic_recover_ok, 0x003C006F, # 60, 111; 3932271
|
131
|
+
:basic_nack, 0x003C0078, # 60, 120; 3932280
|
132
|
+
:tx_select, 0x005A000A, # 90, 10; 5898250
|
133
|
+
:tx_select_ok, 0x005A000B, # 90, 11; 5898251
|
134
|
+
:tx_commit, 0x005A0014, # 90, 20; 5898260
|
135
|
+
:tx_commit_ok, 0x005A0015, # 90, 21; 5898261
|
136
|
+
:tx_rollback, 0x005A001E, # 90, 30; 5898270
|
137
|
+
:tx_rollback_ok, 0x005A001F, # 90, 31; 5898271
|
138
|
+
:confirm_select, 0x0055000A, # 85, 10; 5570570
|
139
|
+
:confirm_select_ok, 0x0055000B, # 85, 11; 5570571
|
140
|
+
]
|
141
|
+
|
142
|
+
Flags = :uint32
|
143
|
+
|
144
|
+
Channel = ::FFI::TypeDefs[:uint16]
|
145
|
+
CHANNEL_MAX_ID = 2 ** (Channel.size * 8) - 1
|
146
|
+
|
147
|
+
class Bytes < ::FFI::Struct
|
148
|
+
layout :len, :size_t,
|
149
|
+
:bytes, :pointer
|
150
|
+
end
|
151
|
+
|
152
|
+
class Decimal < ::FFI::Struct
|
153
|
+
layout :decimals, :uint8,
|
154
|
+
:value, :uint32
|
155
|
+
end
|
156
|
+
|
157
|
+
class Table < ::FFI::Struct
|
158
|
+
layout :num_entries, :int,
|
159
|
+
:entries, :pointer
|
160
|
+
end
|
161
|
+
|
162
|
+
class Array < ::FFI::Struct
|
163
|
+
layout :num_entries, :int,
|
164
|
+
:entries, :pointer
|
165
|
+
end
|
166
|
+
|
167
|
+
FieldValueKind = enum ::FFI::TypeDefs[:uint8], [
|
168
|
+
:boolean, 't'.ord,
|
169
|
+
:i8, 'b'.ord,
|
170
|
+
:u8, 'B'.ord,
|
171
|
+
:i16, 's'.ord,
|
172
|
+
:u16, 'u'.ord,
|
173
|
+
:i32, 'I'.ord,
|
174
|
+
:u32, 'i'.ord,
|
175
|
+
:i64, 'l'.ord,
|
176
|
+
:u64, 'L'.ord,
|
177
|
+
:f32, 'f'.ord,
|
178
|
+
:f64, 'd'.ord,
|
179
|
+
:decimal, 'D'.ord,
|
180
|
+
:utf8, 'S'.ord,
|
181
|
+
:array, 'A'.ord,
|
182
|
+
:timestamp, 'T'.ord,
|
183
|
+
:table, 'F'.ord,
|
184
|
+
:void, 'V'.ord,
|
185
|
+
:bytes, 'x'.ord,
|
186
|
+
]
|
187
|
+
|
188
|
+
class FieldValueValue < ::FFI::Union
|
189
|
+
layout :boolean, Boolean,
|
190
|
+
:i8, :int8,
|
191
|
+
:u8, :uint8,
|
192
|
+
:i16, :int16,
|
193
|
+
:u16, :uint16,
|
194
|
+
:i32, :int32,
|
195
|
+
:u32, :uint32,
|
196
|
+
:i64, :int64,
|
197
|
+
:u64, :uint64,
|
198
|
+
:f32, :float,
|
199
|
+
:f64, :double,
|
200
|
+
:decimal, Decimal,
|
201
|
+
:bytes, Bytes,
|
202
|
+
:table, Table,
|
203
|
+
:array, Array
|
204
|
+
end
|
205
|
+
|
206
|
+
class FieldValue < ::FFI::Struct
|
207
|
+
layout :kind, FieldValueKind,
|
208
|
+
:value, FieldValueValue
|
209
|
+
end
|
210
|
+
|
211
|
+
class TableEntry < ::FFI::Struct
|
212
|
+
layout :key, Bytes,
|
213
|
+
:value, FieldValue
|
214
|
+
end
|
215
|
+
|
216
|
+
class PoolBlocklist < ::FFI::Struct
|
217
|
+
layout :num_blocks, :int,
|
218
|
+
:blocklist, :pointer
|
219
|
+
end
|
220
|
+
|
221
|
+
class Pool < ::FFI::Struct
|
222
|
+
layout :pagesize, :size_t,
|
223
|
+
:pages, PoolBlocklist,
|
224
|
+
:large_blocks, PoolBlocklist,
|
225
|
+
:next_pages, :int,
|
226
|
+
:alloc_block, :pointer,
|
227
|
+
:alloc_used, :size_t
|
228
|
+
end
|
229
|
+
|
230
|
+
class Method < ::FFI::Struct
|
231
|
+
layout :id, MethodNumber,
|
232
|
+
:decoded, :pointer
|
233
|
+
end
|
234
|
+
|
235
|
+
FrameType = enum ::FFI::TypeDefs[:uint8], [
|
236
|
+
:method, 1,
|
237
|
+
:header, 2,
|
238
|
+
:body, 3,
|
239
|
+
:heartbeat, 8,
|
240
|
+
]
|
241
|
+
|
242
|
+
class FramePayloadProperties < ::FFI::Struct
|
243
|
+
layout :class_id, :uint16,
|
244
|
+
:body_size, :uint64,
|
245
|
+
:decoded, :pointer,
|
246
|
+
:raw, Bytes
|
247
|
+
end
|
248
|
+
|
249
|
+
class FramePayloadProtocolHeader < ::FFI::Struct
|
250
|
+
layout :transport_high, :uint8,
|
251
|
+
:transport_low, :uint8,
|
252
|
+
:protocol_version_major, :uint8,
|
253
|
+
:protocol_version_minor, :uint8
|
254
|
+
end
|
255
|
+
|
256
|
+
class FramePayload < ::FFI::Union
|
257
|
+
layout :method, Method,
|
258
|
+
:properties, FramePayloadProperties,
|
259
|
+
:body_fragment, Bytes,
|
260
|
+
:protocol_header, FramePayloadProtocolHeader
|
261
|
+
end
|
262
|
+
|
263
|
+
class Frame < ::FFI::Struct
|
264
|
+
layout :frame_type, FrameType,
|
265
|
+
:channel, Channel,
|
266
|
+
:payload, FramePayload
|
267
|
+
end
|
268
|
+
|
269
|
+
ResponseType = enum [
|
270
|
+
:none, 0,
|
271
|
+
:normal,
|
272
|
+
:library_exception,
|
273
|
+
:server_exception,
|
274
|
+
]
|
275
|
+
|
276
|
+
class RpcReply < ::FFI::Struct
|
277
|
+
layout :reply_type, ResponseType,
|
278
|
+
:reply, Method,
|
279
|
+
:library_error, Status
|
280
|
+
end
|
281
|
+
|
282
|
+
SaslMethod = enum [
|
283
|
+
:plain, 0,
|
284
|
+
]
|
285
|
+
|
286
|
+
ConnectionState = :pointer
|
287
|
+
|
288
|
+
attach_function :amqp_constant_name, [:int], :string, **opts
|
289
|
+
attach_function :amqp_constant_is_hard_error, [:int], Boolean, **opts
|
290
|
+
|
291
|
+
attach_function :amqp_method_name, [MethodNumber], :string, **opts
|
292
|
+
attach_function :amqp_method_has_content, [MethodNumber], Boolean, **opts
|
293
|
+
attach_function :amqp_decode_method, [MethodNumber, Pool.ptr, Bytes.val, :pointer], Status, **opts
|
294
|
+
attach_function :amqp_decode_properties, [:uint16, Pool.ptr, Bytes.val, :pointer], Status, **opts
|
295
|
+
attach_function :amqp_encode_method, [MethodNumber, :pointer, Bytes.val], Status, **opts
|
296
|
+
attach_function :amqp_encode_properties, [:uint16, :pointer, Bytes.val], Status, **opts
|
297
|
+
|
298
|
+
require_relative 'ffi/gen'
|
299
|
+
|
300
|
+
class ConnectionProperties < ::FFI::Struct
|
301
|
+
layout :flags, Flags,
|
302
|
+
:dummy, :char
|
303
|
+
end
|
300
304
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
+
class ChannelProperties < ::FFI::Struct
|
306
|
+
layout :flags, Flags,
|
307
|
+
:dummy, :char
|
308
|
+
end
|
305
309
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
+
class AccessProperties < ::FFI::Struct
|
311
|
+
layout :flags, Flags,
|
312
|
+
:dummy, :char
|
313
|
+
end
|
310
314
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
+
class ExchangeProperties < ::FFI::Struct
|
316
|
+
layout :flags, Flags,
|
317
|
+
:dummy, :char
|
318
|
+
end
|
315
319
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
end
|
501
|
-
def self.has_ssl?; @has_ssl; end
|
320
|
+
class QueueProperties < ::FFI::Struct
|
321
|
+
layout :flags, Flags,
|
322
|
+
:dummy, :char
|
323
|
+
end
|
324
|
+
|
325
|
+
class TxProperties < ::FFI::Struct
|
326
|
+
layout :flags, Flags,
|
327
|
+
:dummy, :char
|
328
|
+
end
|
329
|
+
|
330
|
+
class ExchangeProperties < ::FFI::Struct
|
331
|
+
layout :flags, Flags,
|
332
|
+
:dummy, :char
|
333
|
+
end
|
334
|
+
|
335
|
+
class BasicProperties < ::FFI::Struct
|
336
|
+
layout :_flags, Flags,
|
337
|
+
:content_type, Bytes,
|
338
|
+
:content_encoding, Bytes,
|
339
|
+
:headers, Table,
|
340
|
+
:delivery_mode, DeliveryMode,
|
341
|
+
:priority, :uint8,
|
342
|
+
:correlation_id, Bytes,
|
343
|
+
:reply_to, Bytes,
|
344
|
+
:expiration, Bytes,
|
345
|
+
:message_id, Bytes,
|
346
|
+
:timestamp, :uint64,
|
347
|
+
:type, Bytes,
|
348
|
+
:user_id, Bytes,
|
349
|
+
:app_id, Bytes,
|
350
|
+
:cluster_id, Bytes
|
351
|
+
|
352
|
+
FLAGS = {
|
353
|
+
content_type: (1 << 15),
|
354
|
+
content_encoding: (1 << 14),
|
355
|
+
headers: (1 << 13),
|
356
|
+
delivery_mode: (1 << 12),
|
357
|
+
priority: (1 << 11),
|
358
|
+
correlation_id: (1 << 10),
|
359
|
+
reply_to: (1 << 9),
|
360
|
+
expiration: (1 << 8),
|
361
|
+
message_id: (1 << 7),
|
362
|
+
timestamp: (1 << 6),
|
363
|
+
type: (1 << 5),
|
364
|
+
user_id: (1 << 4),
|
365
|
+
app_id: (1 << 3),
|
366
|
+
cluster_id: (1 << 2),
|
367
|
+
}
|
368
|
+
end
|
369
|
+
|
370
|
+
attach_function :amqp_channel_open, [ConnectionState, Channel], ChannelOpenOk.ptr, **opts
|
371
|
+
attach_function :amqp_channel_flow, [ConnectionState, Channel, Boolean], ChannelFlowOk.ptr, **opts
|
372
|
+
attach_function :amqp_exchange_declare, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, Table.val], ExchangeDeclareOk.ptr, **opts
|
373
|
+
attach_function :amqp_exchange_delete, [ConnectionState, Channel, Bytes.val, Boolean], ExchangeDeleteOk.ptr, **opts
|
374
|
+
attach_function :amqp_exchange_bind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], ExchangeBindOk.ptr, **opts
|
375
|
+
attach_function :amqp_exchange_unbind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], ExchangeUnbindOk.ptr, **opts
|
376
|
+
attach_function :amqp_queue_declare, [ConnectionState, Channel, Bytes.val, Boolean, Boolean, Boolean, Boolean, Table.val], QueueDeclareOk.ptr, **opts
|
377
|
+
attach_function :amqp_queue_bind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], QueueBindOk.ptr, **opts
|
378
|
+
attach_function :amqp_queue_purge, [ConnectionState, Channel, Bytes.val], QueuePurgeOk.ptr, **opts
|
379
|
+
attach_function :amqp_queue_delete, [ConnectionState, Channel, Bytes.val, Boolean, Boolean], QueueDeleteOk.ptr, **opts
|
380
|
+
attach_function :amqp_queue_unbind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], QueueUnbindOk.ptr, **opts
|
381
|
+
attach_function :amqp_basic_qos, [ConnectionState, Channel, :uint32, :uint16, Boolean], BasicQosOk.ptr, **opts
|
382
|
+
attach_function :amqp_basic_consume, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, Boolean, Table.val], BasicConsumeOk.ptr, **opts
|
383
|
+
attach_function :amqp_basic_cancel, [ConnectionState, Channel, Bytes.val], BasicCancelOk.ptr, **opts
|
384
|
+
attach_function :amqp_basic_recover, [ConnectionState, Channel, Boolean], BasicRecoverOk.ptr, **opts
|
385
|
+
attach_function :amqp_tx_select, [ConnectionState, Channel], TxSelect.ptr, **opts
|
386
|
+
attach_function :amqp_tx_commit, [ConnectionState, Channel], TxCommit.ptr, **opts
|
387
|
+
attach_function :amqp_tx_rollback, [ConnectionState, Channel], TxRollback.ptr, **opts
|
388
|
+
attach_function :amqp_confirm_select, [ConnectionState, Channel], ConfirmSelect.ptr, **opts
|
389
|
+
|
390
|
+
attach_function :init_amqp_pool, [Pool.ptr, :size_t], :void, **opts
|
391
|
+
attach_function :recycle_amqp_pool, [Pool.ptr], :void, **opts
|
392
|
+
attach_function :empty_amqp_pool, [Pool.ptr], :void, **opts
|
393
|
+
attach_function :amqp_pool_alloc, [Pool.ptr, :size_t], :pointer, **opts
|
394
|
+
attach_function :amqp_pool_alloc_bytes, [Pool.ptr, :size_t, Bytes.ptr], :void, **opts
|
395
|
+
|
396
|
+
attach_function :amqp_cstring_bytes, [:string], Bytes.val, **opts
|
397
|
+
attach_function :amqp_bytes_malloc_dup, [Bytes.val], Bytes.val, **opts
|
398
|
+
attach_function :amqp_bytes_malloc, [:size_t], Bytes.val, **opts
|
399
|
+
attach_function :amqp_bytes_free, [Bytes.val], :void, **opts
|
400
|
+
|
401
|
+
attach_function :amqp_new_connection, [], ConnectionState, **opts
|
402
|
+
attach_function :amqp_get_sockfd, [ConnectionState], :int, **opts
|
403
|
+
attach_function :amqp_set_sockfd, [ConnectionState, :int], :void, **opts
|
404
|
+
attach_function :amqp_tune_connection, [ConnectionState, :int, :int, :int], Status, **opts
|
405
|
+
attach_function :amqp_get_channel_max, [ConnectionState], :int, **opts
|
406
|
+
attach_function :amqp_get_frame_max, [ConnectionState], :int, **opts
|
407
|
+
attach_function :amqp_get_heartbeat, [ConnectionState], :int, **opts
|
408
|
+
attach_function :amqp_destroy_connection, [ConnectionState], Status, **opts
|
409
|
+
|
410
|
+
attach_function :amqp_handle_input, [ConnectionState, Bytes.val, Frame.ptr], Status, **opts
|
411
|
+
attach_function :amqp_release_buffers_ok, [ConnectionState], Boolean, **opts
|
412
|
+
attach_function :amqp_release_buffers, [ConnectionState], :void, **opts
|
413
|
+
attach_function :amqp_maybe_release_buffers, [ConnectionState], :void, **opts
|
414
|
+
attach_function :amqp_maybe_release_buffers_on_channel, [ConnectionState, Channel], :void, **opts
|
415
|
+
attach_function :amqp_send_frame, [ConnectionState, Frame.ptr], Status, **opts
|
416
|
+
|
417
|
+
attach_function :amqp_table_entry_cmp, [:pointer, :pointer], :int, **opts
|
418
|
+
|
419
|
+
attach_function :amqp_open_socket, [:string, :int], Status, **opts
|
420
|
+
|
421
|
+
attach_function :amqp_send_header, [ConnectionState], Status, **opts
|
422
|
+
attach_function :amqp_frames_enqueued, [ConnectionState], Boolean, **opts
|
423
|
+
attach_function :amqp_simple_wait_frame, [ConnectionState, Frame.ptr], Status, **opts
|
424
|
+
attach_function :amqp_simple_wait_frame_noblock, [ConnectionState, Frame.ptr, Timeval.ptr], Status, **opts
|
425
|
+
attach_function :amqp_simple_wait_method, [ConnectionState, Channel, MethodNumber, Method.ptr], Status, **opts
|
426
|
+
attach_function :amqp_send_method, [ConnectionState, Channel, MethodNumber, :pointer], Status, **opts
|
427
|
+
|
428
|
+
attach_function :amqp_simple_rpc, [ConnectionState, Channel, MethodNumber, :pointer, :pointer], RpcReply.val, **opts
|
429
|
+
attach_function :amqp_simple_rpc_decoded, [ConnectionState, Channel, MethodNumber, MethodNumber, :pointer], :pointer, **opts
|
430
|
+
attach_function :amqp_get_rpc_reply, [ConnectionState], RpcReply.val, **opts
|
431
|
+
attach_function :amqp_login, [ConnectionState, :string, :int, :int, :int, SaslMethod, :varargs], RpcReply.val, **opts
|
432
|
+
attach_function :amqp_login_with_properties, [ConnectionState, :string, :int, :int, :int, Table.ptr, SaslMethod, :varargs], RpcReply.val, **opts
|
433
|
+
attach_function :amqp_channel_close, [ConnectionState, Channel, :int], RpcReply.val, **opts
|
434
|
+
attach_function :amqp_connection_close, [ConnectionState, :int], RpcReply.val, **opts
|
435
|
+
|
436
|
+
attach_function :amqp_basic_publish, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, BasicProperties.ptr, Bytes.val], Status, **opts
|
437
|
+
|
438
|
+
attach_function :amqp_basic_get, [ConnectionState, Channel, Bytes.val, Boolean], Status, **opts
|
439
|
+
attach_function :amqp_basic_ack, [ConnectionState, Channel, :uint64, Boolean], Status, **opts
|
440
|
+
attach_function :amqp_basic_reject, [ConnectionState, Channel, :uint64, Boolean], Status, **opts
|
441
|
+
attach_function :amqp_basic_nack, [ConnectionState, Channel, :uint64, Boolean, Boolean], Status, **opts
|
442
|
+
|
443
|
+
attach_function :amqp_data_in_buffer, [ConnectionState], Boolean, **opts
|
444
|
+
|
445
|
+
attach_function :amqp_error_string, [:int], :string, **opts
|
446
|
+
attach_function :amqp_error_string2, [:int], :string, **opts
|
447
|
+
|
448
|
+
attach_function :amqp_decode_table, [Bytes.val, Pool.ptr, Table.ptr, :pointer], Status, **opts
|
449
|
+
attach_function :amqp_encode_table, [Bytes.val, Table.ptr, :pointer], Status, **opts
|
450
|
+
attach_function :amqp_table_clone, [Table.ptr, Table.ptr, Pool.ptr], Status, **opts
|
451
|
+
|
452
|
+
class Message < ::FFI::Struct
|
453
|
+
layout :properties, BasicProperties,
|
454
|
+
:body, Bytes,
|
455
|
+
:pool, Pool
|
456
|
+
end
|
457
|
+
|
458
|
+
attach_function :amqp_read_message, [ConnectionState, Channel, Message.ptr, :int], RpcReply.val, **opts
|
459
|
+
attach_function :amqp_destroy_message, [Message.ptr], :void, **opts
|
460
|
+
|
461
|
+
class Envelope < ::FFI::Struct
|
462
|
+
layout :channel, Channel,
|
463
|
+
:consumer_tag, Bytes,
|
464
|
+
:delivery_tag, :uint64,
|
465
|
+
:redelivered, Boolean,
|
466
|
+
:exchange, Bytes,
|
467
|
+
:routing_key, Bytes,
|
468
|
+
:message, Message
|
469
|
+
end
|
470
|
+
|
471
|
+
attach_function :amqp_consume_message, [ConnectionState, Envelope.ptr, Timeval.ptr, :int], RpcReply.val, **opts
|
472
|
+
attach_function :amqp_destroy_envelope, [Envelope.ptr], :void, **opts
|
473
|
+
|
474
|
+
class ConnectionInfo < ::FFI::Struct
|
475
|
+
layout :user, :string,
|
476
|
+
:password, :string,
|
477
|
+
:host, :string,
|
478
|
+
:vhost, :string,
|
479
|
+
:port, :int,
|
480
|
+
:ssl, Boolean
|
481
|
+
end
|
482
|
+
|
483
|
+
attach_function :amqp_default_connection_info, [ConnectionInfo.ptr], :void, **opts
|
484
|
+
attach_function :amqp_parse_url, [:pointer, ConnectionInfo.ptr], Status, **opts
|
485
|
+
attach_function :amqp_socket_open, [:pointer, :string, :int], Status, **opts
|
486
|
+
attach_function :amqp_socket_open_noblock, [:pointer, :string, :int, Timeval.ptr], Status, **opts
|
487
|
+
attach_function :amqp_socket_get_sockfd, [:pointer], :int, **opts
|
488
|
+
attach_function :amqp_get_socket, [ConnectionState], :pointer, **opts
|
489
|
+
attach_function :amqp_get_server_properties, [ConnectionState], Table, **opts
|
490
|
+
|
491
|
+
attach_function :amqp_tcp_socket_new, [ConnectionState], :pointer, **opts
|
492
|
+
attach_function :amqp_tcp_socket_set_sockfd, [:pointer, :int], :void, **opts
|
493
|
+
|
494
|
+
begin # SSL support is optional
|
495
|
+
attach_function :amqp_ssl_socket_new, [ConnectionState], :pointer, **opts
|
496
|
+
attach_function :amqp_ssl_socket_set_cacert, [:pointer, :string], Status, **opts
|
497
|
+
attach_function :amqp_ssl_socket_set_key, [:pointer, :string, :string], Status, **opts
|
498
|
+
attach_function :amqp_ssl_socket_set_key_buffer, [:pointer, :string, :pointer, :size_t], Status, **opts
|
499
|
+
attach_function :amqp_ssl_socket_set_verify, [:pointer, Boolean], :void, **opts
|
500
|
+
attach_function :amqp_set_initialize_ssl_library, [Boolean], :void, **opts
|
501
|
+
@has_ssl = true
|
502
|
+
rescue LoadError
|
503
|
+
@has_ssl = false
|
502
504
|
end
|
505
|
+
def self.has_ssl?; @has_ssl; end
|
503
506
|
end
|
504
507
|
end
|