amqp-client 1.0.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
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,15 +35,21 @@ 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
+ # @example
42
+ # connection = AMQP::Client.new("amqps://server.rmq.cloudamqp.com", connection_name: "My connection").connect
41
43
  def connect(read_loop_thread: true)
42
- Connection.connect(@uri, read_loop_thread: read_loop_thread, **@options)
44
+ Connection.new(@uri, read_loop_thread: read_loop_thread, **@options)
43
45
  end
44
46
 
45
47
  # Opens an AMQP connection using the high level API, will try to reconnect if successfully connected at first
46
48
  # @return [self]
49
+ # @example
50
+ # amqp = AMQP::Client.new("amqps://server.rmq.cloudamqp.com")
51
+ # amqp.start
52
+ # amqp.queue("foobar")
47
53
  def start
48
54
  @stopped = false
49
55
  Thread.new(connect(read_loop_thread: false)) do |conn|
@@ -95,6 +101,10 @@ module AMQP
95
101
  # (it won't be deleted until at least one consumer has consumed from it)
96
102
  # @param arguments [Hash] Custom arguments, such as queue-ttl etc.
97
103
  # @return [Queue]
104
+ # @example
105
+ # amqp = AMQP::Client.new.start
106
+ # q = amqp.queue("foobar")
107
+ # q.publish("body")
98
108
  def queue(name, durable: true, auto_delete: false, arguments: {})
99
109
  raise ArgumentError, "Currently only supports named, durable queues" if name.empty?
100
110
 
@@ -108,6 +118,10 @@ module AMQP
108
118
 
109
119
  # Declare an exchange and return a high level Exchange object
110
120
  # @return [Exchange]
121
+ # @example
122
+ # amqp = AMQP::Client.new.start
123
+ # x = amqp.exchange("my.hash.exchange", "x-consistent-hash")
124
+ # x.publish("body", "routing-key")
111
125
  def exchange(name, type, durable: true, auto_delete: false, internal: false, arguments: {})
112
126
  @exchanges.fetch(name) do
113
127
  with_connection do |conn|
@@ -122,7 +136,10 @@ module AMQP
122
136
  # @!group Publish
123
137
 
124
138
  # Publish a (persistent) message and wait for confirmation
125
- # @return [nil]
139
+ # @param (see Connection::Channel#basic_publish_confirm)
140
+ # @option (see Connection::Channel#basic_publish_confirm)
141
+ # @return (see Connection::Channel#basic_publish_confirm)
142
+ # @raise (see Connection::Channel#basic_publish_confirm)
126
143
  def publish(body, exchange, routing_key, **properties)
127
144
  with_connection do |conn|
128
145
  properties = { delivery_mode: 2 }.merge!(properties)
@@ -131,7 +148,10 @@ module AMQP
131
148
  end
132
149
 
133
150
  # Publish a (persistent) message but don't wait for a confirmation
134
- # @return [nil]
151
+ # @param (see Connection::Channel#basic_publish)
152
+ # @option (see Connection::Channel#basic_publish)
153
+ # @return (see Connection::Channel#basic_publish)
154
+ # @raise (see Connection::Channel#basic_publish)
135
155
  def publish_and_forget(body, exchange, routing_key, **properties)
136
156
  with_connection do |conn|
137
157
  properties = { delivery_mode: 2 }.merge!(properties)
@@ -166,9 +186,7 @@ module AMQP
166
186
  with_connection do |conn|
167
187
  ch = conn.channel
168
188
  ch.basic_qos(prefetch)
169
- ch.basic_consume(queue, no_ack: no_ack, worker_threads: worker_threads, arguments: arguments) do |msg|
170
- blk.call(msg)
171
- end
189
+ ch.basic_consume(queue, no_ack: no_ack, worker_threads: worker_threads, arguments: arguments, &blk)
172
190
  end
173
191
  end
174
192
 
@@ -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.1
4
+ version: 1.1.2
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-06 00:00:00.000000000 Z
11
+ date: 2021-10-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Work in progress
14
14
  email:
@@ -37,12 +37,13 @@ files:
37
37
  - lib/amqp/client/connection.rb
38
38
  - lib/amqp/client/errors.rb
39
39
  - lib/amqp/client/exchange.rb
40
- - lib/amqp/client/frames.rb
40
+ - lib/amqp/client/frame_bytes.rb
41
41
  - lib/amqp/client/message.rb
42
42
  - lib/amqp/client/properties.rb
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
  - - ">="