amqp-client 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,9 @@ module AMQP
5
5
  # Encode and decode an AMQP table to/from hash, only used internally
6
6
  # @api private
7
7
  module Table
8
- module_function
9
-
10
8
  # Encodes a hash into a byte array
11
9
  # @return [String] Byte array
12
- def encode(hash)
10
+ def self.encode(hash)
13
11
  tbl = StringIO.new
14
12
  hash.each do |k, v|
15
13
  key = k.to_s
@@ -21,11 +19,11 @@ module AMQP
21
19
 
22
20
  # Decodes an AMQP table into a hash
23
21
  # @return [Hash<String, Object>]
24
- def decode(bytes)
22
+ def self.decode(bytes)
25
23
  hash = {}
26
24
  pos = 0
27
25
  while pos < bytes.bytesize
28
- key_len = bytes[pos].ord
26
+ key_len = bytes.getbyte(pos)
29
27
  pos += 1
30
28
  key = bytes.byteslice(pos, key_len).force_encoding("utf-8")
31
29
  pos += key_len
@@ -39,7 +37,7 @@ module AMQP
39
37
 
40
38
  # Encoding a single value in a table
41
39
  # @api private
42
- def encode_field(value)
40
+ def self.encode_field(value)
43
41
  case value
44
42
  when Integer
45
43
  if value > 2**31
@@ -72,7 +70,7 @@ module AMQP
72
70
  # Decodes a single value
73
71
  # @return [Array<Integer, Object>] Bytes read and the parsed object
74
72
  # @api private
75
- def decode_field(bytes)
73
+ def self.decode_field(bytes)
76
74
  type = bytes[0]
77
75
  pos = 1
78
76
  case type
@@ -94,7 +92,7 @@ module AMQP
94
92
  end
95
93
  [4 + len, a]
96
94
  when "t"
97
- [1, bytes[pos].ord == 1]
95
+ [1, bytes.getbyte(pos) == 1]
98
96
  when "b"
99
97
  [1, bytes.byteslice(pos, 1).unpack1("c")]
100
98
  when "B"
@@ -114,7 +112,7 @@ module AMQP
114
112
  when "d"
115
113
  [8, bytes.byteslice(pos, 8).unpack1("G")]
116
114
  when "D"
117
- scale = bytes[pos].ord
115
+ scale = bytes.getbyte(pos)
118
116
  pos += 1
119
117
  value = bytes.byteslice(pos, 4).unpack1("L>")
120
118
  d = value / 10**scale
@@ -3,6 +3,6 @@
3
3
  module AMQP
4
4
  class Client
5
5
  # Version of the client library
6
- VERSION = "1.0.2"
6
+ VERSION = "1.1.0"
7
7
  end
8
8
  end
data/lib/amqp/client.rb CHANGED
@@ -23,7 +23,7 @@ module AMQP
23
23
  # the smallest of the client's and the broker's values will be used
24
24
  # @option options [Integer] channel_max (2048) Maxium number of channels the client will be allowed to have open.
25
25
  # Maxium allowed is 65_536. The smallest of the client's and the broker's value will be used.
26
- def initialize(uri, **options)
26
+ def initialize(uri = "", **options)
27
27
  @uri = uri
28
28
  @options = options
29
29
 
@@ -35,11 +35,11 @@ module AMQP
35
35
 
36
36
  # @!group Connect and disconnect
37
37
 
38
- # Establishes a new AMQP connection, does not try to reconnect
39
- # @see Connection.connect
38
+ # Establishes and returns a new AMQP connection
39
+ # @see Connection#initialize
40
40
  # @return [Connection]
41
41
  def connect(read_loop_thread: true)
42
- Connection.connect(@uri, read_loop_thread: read_loop_thread, **@options)
42
+ Connection.new(@uri, read_loop_thread: read_loop_thread, **@options)
43
43
  end
44
44
 
45
45
  # Opens an AMQP connection using the high level API, will try to reconnect if successfully connected at first
@@ -0,0 +1,264 @@
1
+ # TypeProf 0.15.3
2
+
3
+ # Classes
4
+ module AMQP
5
+ class Client
6
+ VERSION: String
7
+ @uri: String
8
+ @options: Hash[Symbol, (String | Integer | bool)]
9
+ @queues: Hash[String, Queue]
10
+ @exchanges: Hash[String, Exchange]
11
+ @subscriptions: Set[[String, bool, Integer, Integer, Hash[Symbol, untyped], nil]]
12
+ @connq: Thread::SizedQueue
13
+ @stopped: bool
14
+
15
+ def initialize: (?String uri, **untyped) -> void
16
+ def connect: (?read_loop_thread: bool) -> Connection
17
+ def start: -> Client
18
+ def stop: -> nil
19
+ def queue: (String name, ?durable: bool, ?auto_delete: bool, ?arguments: Hash[Symbol | String, (String | Integer | bool)]) -> Queue
20
+ def exchange: (String name, String `type`, ?durable: bool, ?auto_delete: bool, ?internal: bool, ?arguments: Hash[Symbol | String, untyped]) -> Exchange
21
+ def publish: (String body, String exchange, String routing_key, **untyped) -> bool
22
+ def publish_and_forget: (String body, String exchange, String routing_key, **untyped) -> nil
23
+ def wait_for_confirms: -> bool
24
+ def subscribe: (String queue, ?no_ack: bool, ?prefetch: Integer, ?worker_threads: Integer, ?arguments: Hash[Symbol | String, untyped]) { (Message) -> void } -> [String, Array[Thread]]?
25
+ def bind: (String queue, String exchange, String binding_key, ?arguments: Hash[Symbol | String, untyped]) -> nil
26
+ def unbind: (String queue, String exchange, String binding_key, ?arguments: Hash[Symbol | String, untyped]) -> nil
27
+ def purge: (String queue) -> nil
28
+ def delete_queue: (String name, ?if_unused: bool, ?if_empty: bool) -> Integer?
29
+ def exchange_bind: (String destination, String source, String binding_key, ?arguments: Hash[Symbol | String, untyped]) -> nil
30
+ def exchange_unbind: (String destination, String source, String binding_key, ?arguments: Hash[Symbol | String, untyped]) -> nil
31
+ def delete_exchange: (String name) -> nil
32
+ def with_connection: { (Connection) -> void } -> void
33
+
34
+ module Table
35
+ def self.encode: (Hash[Symbol | String, untyped] hash) -> String
36
+ def self.decode: (String bytes) -> Hash[String, untyped]
37
+ end
38
+
39
+ class Properties
40
+ attr_accessor content_type(): String?
41
+ attr_accessor content_encoding(): String?
42
+ attr_accessor headers(): Hash[String | Symbol, untyped]?
43
+ attr_accessor delivery_mode(): Integer?
44
+ attr_accessor priority(): Integer?
45
+ attr_accessor correlation_id(): String?
46
+ attr_accessor reply_to(): String?
47
+ attr_accessor expiration(): (Integer | String)?
48
+ attr_accessor message_id(): String?
49
+ attr_accessor timestamp(): Time?
50
+ attr_accessor type(): String?
51
+ attr_accessor user_id(): String?
52
+ attr_accessor app_id(): String?
53
+ end
54
+
55
+ module FrameBytes
56
+ def self.connection_start_ok: (String response, Hash[untyped, untyped] properties) -> String
57
+ def self.connection_tune_ok: ((Float | Integer | String)? channel_max, (Float | Integer | String)? frame_max, (Float | Integer | String)? heartbeat) -> String
58
+ def self.connection_open: (String vhost) -> String
59
+ def self.connection_close: (Integer code, String reason) -> String
60
+ def self.connection_close_ok: -> String
61
+ def self.channel_open: (Integer id) -> String
62
+ def self.channel_close: (Integer id, String reason, Integer code) -> String
63
+ def self.channel_close_ok: ((Float | Integer | String)? id) -> String
64
+ def self.exchange_declare: (Integer id, untyped name, untyped `type`, bool passive, bool durable, bool auto_delete, bool internal, Hash[untyped, untyped] arguments) -> String
65
+ def self.exchange_delete: (Integer id, untyped name, bool if_unused, bool no_wait) -> String
66
+ def self.exchange_bind: (Integer id, untyped destination, untyped source, untyped binding_key, bool no_wait, Hash[untyped, untyped] arguments) -> String
67
+ def self.exchange_unbind: (Integer id, untyped destination, untyped source, untyped binding_key, bool no_wait, Hash[untyped, untyped] arguments) -> String
68
+ def self.queue_declare: (Integer id, String name, bool passive, bool durable, bool exclusive, bool auto_delete, Hash[untyped, untyped] arguments) -> String
69
+ def self.queue_delete: (Integer id, untyped name, bool if_unused, bool if_empty, bool no_wait) -> String
70
+ def self.queue_bind: (Integer id, untyped queue, untyped exchange, untyped binding_key, bool no_wait, Hash[untyped, untyped] arguments) -> String
71
+ def self.queue_unbind: (Integer id, untyped queue, untyped exchange, untyped binding_key, Hash[untyped, untyped] arguments) -> String
72
+ def self.queue_purge: (Integer id, untyped queue, bool no_wait) -> String
73
+ def self.basic_get: (Integer id, untyped queue, bool no_ack) -> String
74
+ def self.basic_publish: (Integer id, untyped exchange, untyped routing_key, bool mandatory) -> String
75
+ def self.header: (Integer id, untyped body_size, Hash[(Symbol | String), untyped] properties) -> String
76
+ def self.body: (Integer id, untyped body_part) -> String
77
+ def self.basic_consume: (Integer id, String queue, String? tag, bool? no_ack, bool? exclusive, Hash[untyped, untyped]? arguments) -> String
78
+ def self.basic_cancel: (Integer id, untyped consumer_tag, ?no_wait: bool) -> String
79
+ def self.basic_cancel_ok: (Integer id, String consumer_tag) -> String
80
+ def self.basic_ack: (Integer id, untyped delivery_tag, bool multiple) -> String
81
+ def self.basic_nack: (Integer id, untyped delivery_tag, bool multiple, bool requeue) -> String
82
+ def self.basic_reject: (Integer id, untyped delivery_tag, bool requeue) -> String
83
+ def self.basic_qos: (Integer id, Integer? prefetch_size, Integer? prefetch_count, bool? global) -> String
84
+ def self.basic_recover: (Integer id, untyped requeue) -> String
85
+ def self.confirm_select: (Integer id, bool no_wait) -> String
86
+ def self.tx_select: (Integer id) -> String
87
+ def self.tx_commit: (Integer id) -> String
88
+ def self.tx_rollback: (Integer id) -> String
89
+ end
90
+
91
+ class Message
92
+ attr_reader channel(): Connection::Channel
93
+ attr_reader delivery_tag(): Integer
94
+ attr_reader exchange(): String
95
+ attr_reader routing_key(): String
96
+ attr_reader redelivered(): bool
97
+ attr_reader consumer_tag(): String?
98
+ attr_accessor properties(): Properties
99
+ attr_accessor body(): String
100
+ end
101
+
102
+ class ReturnMessage
103
+ attr_reader reply_code(): Integer
104
+ attr_reader reply_text(): String
105
+ attr_reader exchange(): String
106
+ attr_reader routing_key(): String
107
+ attr_accessor properties(): Properties
108
+ attr_accessor body(): String
109
+ end
110
+
111
+ class Connection
112
+ CLIENT_PROPERTIES: Hash[Symbol | String, untyped]
113
+ @socket: (IO | untyped)
114
+ @channel_max: Integer
115
+ @heartbeat: Integer
116
+ @channels: Hash[Integer, Channel]
117
+ @closed: Array[untyped]?
118
+ @replies: Thread::Queue
119
+ @write_lock: Thread::Mutex
120
+ @blocked: String?
121
+ @id: Integer
122
+
123
+ def initialize: (?String uri, ?read_loop_thread: bool, **untyped) -> void
124
+ def self.connect: (?String uri, ?read_loop_thread: bool, **untyped) -> Connection
125
+ attr_reader frame_max: Integer
126
+ def inspect: -> String
127
+ def channel: (?Integer? id) -> Channel
128
+ def with_channel: { (Channel) -> void } -> void
129
+ def close: (?reason: String, ?code: Integer) -> nil
130
+ def closed?: -> bool
131
+ def write_bytes: (*String bytes) -> Integer
132
+ def read_loop: -> nil
133
+
134
+ private
135
+ def parse_frame: (Integer `type`, Integer channel_id, String buf) -> bool
136
+ def expect: (:close_ok expected_frame_type) -> untyped
137
+ def open_socket: (String host, Integer port, bool tls, Hash[Symbol, untyped] options) -> (IO | untyped)
138
+ def establish: ((IO | untyped) socket, String user, String password, String vhost, Hash[Symbol, untyped] options) -> [Integer, Integer, Integer]
139
+ def enable_tcp_keepalive: ((IO | untyped) socket) -> void
140
+ def port_from_env: -> Integer?
141
+
142
+ class Channel
143
+ @connection: Connection
144
+ @replies: Thread::Queue
145
+ @consumers: Hash[String, Thread::Queue]
146
+ @closed: Array[(:channel | :connection | Integer | String)]?
147
+ @open: bool
148
+ @on_return: nil
149
+ @confirm: Integer?
150
+ @unconfirmed: Thread::Queue
151
+ @unconfirmed_empty: Thread::Queue
152
+ @basic_gets: Thread::Queue
153
+ @next_msg: (Message | ReturnMessage)?
154
+ @next_body: StringIO?
155
+ @next_body_size: (Float | Integer | String)?
156
+
157
+ def initialize: (Connection connection, Integer? id) -> void
158
+ def inspect: -> String
159
+ attr_reader id: Integer?
160
+ def open: -> Channel
161
+ def close: (?reason: String, ?code: Integer) -> nil
162
+ def closed!: (:channel | :connection level, (Float | Integer | String)? code, String reason, (Float | Integer | String)? classid, (Float | Integer | String)? methodid) -> nil
163
+ def on_return: { (ReturnMessage) -> void } -> void
164
+ def exchange_declare: (String name, String `type`, ?passive: bool, ?durable: bool, ?auto_delete: bool, ?internal: bool, ?arguments: Hash[untyped, untyped]) -> nil
165
+ def exchange_delete: (String name, ?if_unused: bool, ?no_wait: bool) -> nil
166
+ def exchange_bind: (String destination, String source, String binding_key, ?arguments: Hash[untyped, untyped]) -> nil
167
+ def exchange_unbind: (String destination, String source, String binding_key, ?arguments: Hash[untyped, untyped]) -> nil
168
+ def queue_declare: (?String name, ?passive: bool, ?durable: bool, ?exclusive: bool, ?auto_delete: bool, ?arguments: Hash[untyped, untyped]) -> QueueOk
169
+ def queue_delete: (String name, ?if_unused: bool, ?if_empty: bool, ?no_wait: bool) -> Integer?
170
+ def queue_bind: (String name, String exchange, String binding_key, ?arguments: Hash[untyped, untyped]) -> nil
171
+ def queue_purge: (String name, ?no_wait: bool) -> nil
172
+ def queue_unbind: (String name, String exchange, String binding_key, ?arguments: Hash[untyped, untyped]) -> nil
173
+ def basic_get: (String queue_name, ?no_ack: bool) -> Message?
174
+ def basic_publish: (String body, String exchange, String routing_key, **untyped) -> nil
175
+ def basic_publish_confirm: (String body, String exchange, String routing_key, **untyped) -> bool
176
+ def basic_consume: (String queue, ?tag: String, ?no_ack: bool?, ?exclusive: bool, ?arguments: Hash[untyped, untyped]?, ?worker_threads: Integer?) { (Message) -> void } -> [String, Array[Thread]]?
177
+ def basic_cancel: (String consumer_tag, ?no_wait: bool) -> nil
178
+ def basic_qos: (Integer prefetch_count, ?prefetch_size: Integer, ?global: bool) -> nil
179
+ def basic_ack: (Integer delivery_tag, ?multiple: bool) -> nil
180
+ def basic_nack: (Integer delivery_tag, ?multiple: bool, ?requeue: bool) -> nil
181
+ def basic_reject: (Integer delivery_tag, ?requeue: bool) -> nil
182
+ def basic_recover: (?requeue: bool) -> nil
183
+ def confirm_select: (?no_wait: bool) -> nil
184
+ def wait_for_confirms: -> bool
185
+ def tx_select: -> nil
186
+ def tx_commit: -> nil
187
+ def tx_rollback: -> nil
188
+ def reply: (Array[untyped] args) -> void
189
+ def confirm: (Array[(:ack | :nack | Integer | bool)] args) -> nil
190
+ def message_returned: ((Float | Integer | String)? reply_code, String reply_text, String exchange, String routing_key) -> ReturnMessage
191
+ def message_delivered: (String? consumer_tag, (Float | Integer | String)? delivery_tag, bool redelivered, String exchange, String routing_key) -> Message
192
+ def basic_get_empty: -> void
193
+ def header_delivered: (Integer body_size, Properties properties) -> void
194
+ def body_delivered: (String body_part) -> void
195
+ def close_consumer: (String tag) -> nil
196
+
197
+ private
198
+ def next_message_finished!: -> void
199
+ def write_bytes: (*String bytes) -> Integer
200
+ def expect: (Symbol expected_frame_type) -> Array[untyped]
201
+
202
+ class QueueOk < Struct[untyped]
203
+ attr_accessor queue_name(): String
204
+ attr_accessor message_count(): Integer
205
+ attr_accessor consumer_count(): Integer
206
+ end
207
+ end
208
+ end
209
+
210
+ class Error < StandardError
211
+ class UnexpectedFrame < Error
212
+ def initialize: (Symbol expected, Symbol actual) -> void
213
+ end
214
+
215
+ class UnexpectedFrameEnd < Error
216
+ def initialize: (untyped actual) -> void
217
+ end
218
+
219
+ class UnsupportedFrameType < Error
220
+ def initialize: (untyped `type`) -> void
221
+ end
222
+
223
+ class UnsupportedMethodFrame < Error
224
+ def initialize: (Integer class_id, Integer method_id) -> void
225
+ end
226
+
227
+ class Closed < Error
228
+ def self.new: (Integer id, (:channel | :connection) level, Integer code, String reason, ?Integer classid, ?Integer methodid) -> (ChannelClosed | ConnectionClosed)
229
+ end
230
+
231
+ class ChannelClosed < Error
232
+ def initialize: (Integer id, Integer code, String reason, ?Integer classid, ?Integer methodid) -> void
233
+ end
234
+
235
+ class ConnectionClosed < Error
236
+ def initialize: (Integer code, String reason, ?Integer classid, ?Integer methodid) -> void
237
+ end
238
+ end
239
+
240
+ class Exchange
241
+ @client: Client
242
+ @name: String
243
+
244
+ def initialize: (Client client, String name) -> void
245
+ def publish: (String body, String routing_key, **untyped) -> Exchange
246
+ def bind: (String exchange, String binding_key, ?arguments: Hash[String | Symbol, untyped]) -> Exchange
247
+ def unbind: (String exchange, String binding_key, ?arguments: Hash[String | Symbol, untyped]) -> Exchange
248
+ def delete: -> nil
249
+ end
250
+
251
+ class Queue
252
+ @client: Client
253
+ @name: String
254
+
255
+ def initialize: (Client client, String name) -> void
256
+ def publish: (String body, **untyped) -> Queue
257
+ def subscribe: (?no_ack: bool, ?prefetch: Integer, ?worker_threads: Integer, ?arguments: Hash[String | Symbol, untyped]) { (Message) -> void } -> Queue
258
+ def bind: (String exchange, String binding_key, ?arguments: Hash[String | Symbol, untyped]) -> Queue
259
+ def unbind: (String exchange, String binding_key, ?arguments: Hash[String | Symbol, untyped]) -> Queue
260
+ def purge: -> Queue
261
+ def delete: -> nil
262
+ end
263
+ end
264
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Hörberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-07 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Work in progress
14
14
  email:
@@ -43,6 +43,7 @@ files:
43
43
  - lib/amqp/client/queue.rb
44
44
  - lib/amqp/client/table.rb
45
45
  - lib/amqp/client/version.rb
46
+ - sig/amqp-client.rbs
46
47
  homepage: https://github.com/cloudamqp/amqp-client.rb
47
48
  licenses:
48
49
  - MIT
@@ -58,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - ">="
60
61
  - !ruby/object:Gem::Version
61
- version: 2.5.0
62
+ version: 2.6.0
62
63
  required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  requirements:
64
65
  - - ">="