twingly-amqp 5.2.0 → 6.0.0
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 +4 -0
- data/lib/twingly/amqp/default_exchange_publisher.rb +4 -2
- data/lib/twingly/amqp/publisher.rb +1 -1
- data/lib/twingly/amqp/subscription.rb +22 -5
- data/lib/twingly/amqp/utilities.rb +12 -6
- data/lib/twingly/amqp/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cfce02de5ea28c844564b13473a31afd438dbc2001392092902666da3a8721a
|
|
4
|
+
data.tar.gz: 05db74046a863f23a0e541cc60402e0f3ae91e5ca6e01131e8aa16c0cc15fc29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 556a43b0b4229225828678fe9f23f3912e39e7a8ec72f6fd2a549cfbd6db7dfa6043aa1f3e0f23998a5fea38f329fb110a3904db84ddd16a8657aad21a3a2d1a
|
|
7
|
+
data.tar.gz: fb0b7fa69facd940accfabbab125ae116d20101f9e33e87b010087d800687c21953a52983035c66bcc95e58fae2ba0ba78b529ba7d398680b56e405129d82b19
|
data/README.md
CHANGED
|
@@ -59,6 +59,8 @@ subscription = Twingly::AMQP::Subscription.new(
|
|
|
59
59
|
consumer_threads: 4, # Optional
|
|
60
60
|
prefetch: 20, # Optional
|
|
61
61
|
max_length: 10_000, # Optional
|
|
62
|
+
queue_type: :quorum, # Optional, which type of queue to create,
|
|
63
|
+
# possible values are :quorum (default) or :classic
|
|
62
64
|
)
|
|
63
65
|
|
|
64
66
|
subscription.on_exception { |exception| puts "Oh noes! #{exception.message}" }
|
|
@@ -141,6 +143,8 @@ publisher = Twingly::AMQP::DefaultExchangePublisher.delayed(
|
|
|
141
143
|
target_queue_name: "my_queue", # Queue which delayed messages will be
|
|
142
144
|
# published to after the delay has elapsed
|
|
143
145
|
delay_ms: 60_000,
|
|
146
|
+
delay_queue_type: :quorum, # Optional. Which type of queue to define the delay queue
|
|
147
|
+
# as. Possible values are :quorum (default) or :classic
|
|
144
148
|
)
|
|
145
149
|
|
|
146
150
|
# Publishes message to the delay queue. After delay_ms has passed,
|
|
@@ -11,12 +11,14 @@ module Twingly
|
|
|
11
11
|
@exchange = connection.create_channel.default_exchange
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def self.delayed(delay_queue_name:, target_queue_name:, delay_ms:,
|
|
14
|
+
def self.delayed(delay_queue_name:, target_queue_name:, delay_ms:, delay_queue_type: :quorum,
|
|
15
|
+
connection: Connection.instance)
|
|
15
16
|
Utilities.create_queue(delay_queue_name,
|
|
16
17
|
arguments: {
|
|
17
18
|
"x-dead-letter-exchange": DEFAULT_EXCHANGE,
|
|
18
19
|
"x-dead-letter-routing-key": target_queue_name,
|
|
19
|
-
}
|
|
20
|
+
},
|
|
21
|
+
queue_type: delay_queue_type)
|
|
20
22
|
|
|
21
23
|
new(queue_name: delay_queue_name, connection: connection).tap do |publisher|
|
|
22
24
|
publisher.configure_publish_options do |options|
|
|
@@ -16,7 +16,7 @@ module Twingly
|
|
|
16
16
|
@exchange.publish(json_payload, opts)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
#
|
|
19
|
+
# Only used by tests to lessen the time we need to sleep
|
|
20
20
|
def publish_with_confirm(message)
|
|
21
21
|
channel = @exchange.channel
|
|
22
22
|
channel.confirm_select unless channel.using_publisher_confirmations?
|
|
@@ -3,14 +3,18 @@ module Twingly
|
|
|
3
3
|
class Subscription
|
|
4
4
|
def initialize(queue_name:, exchange_topic: nil, routing_key: nil,
|
|
5
5
|
routing_keys: nil, consumer_threads: 1, prefetch: 20,
|
|
6
|
-
connection: Connection.instance, max_length: nil
|
|
6
|
+
connection: Connection.instance, max_length: nil,
|
|
7
|
+
queue_type: :quorum)
|
|
7
8
|
@queue_name = queue_name
|
|
8
9
|
@exchange_topic = exchange_topic
|
|
9
10
|
@routing_keys = Array(routing_keys || routing_key)
|
|
10
11
|
@consumer_threads = consumer_threads
|
|
11
12
|
@prefetch = prefetch
|
|
12
13
|
@max_length = max_length
|
|
14
|
+
@queue_type = queue_type
|
|
13
15
|
@cancel = false
|
|
16
|
+
@consumer = nil
|
|
17
|
+
@blocking = false
|
|
14
18
|
|
|
15
19
|
if routing_key
|
|
16
20
|
warn "[DEPRECATION] `routing_key` is deprecated. "\
|
|
@@ -18,7 +22,7 @@ module Twingly
|
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
@channel = create_channel(connection)
|
|
21
|
-
@queue =
|
|
25
|
+
@queue = create_queue
|
|
22
26
|
|
|
23
27
|
if @exchange_topic && @routing_keys.any?
|
|
24
28
|
exchange = @channel.topic(@exchange_topic, durable: true)
|
|
@@ -33,12 +37,13 @@ module Twingly
|
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
def each_message(blocking: true, &block)
|
|
36
|
-
|
|
40
|
+
@blocking = blocking
|
|
41
|
+
@consumer = create_consumer(&block)
|
|
37
42
|
|
|
38
|
-
if blocking
|
|
43
|
+
if @blocking
|
|
39
44
|
sleep 0.01 until cancel?
|
|
40
45
|
|
|
41
|
-
consumer.cancel
|
|
46
|
+
@consumer.cancel
|
|
42
47
|
end
|
|
43
48
|
end
|
|
44
49
|
|
|
@@ -63,6 +68,7 @@ module Twingly
|
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
def cancel!
|
|
71
|
+
@consumer.cancel unless @blocking
|
|
66
72
|
@cancel = true
|
|
67
73
|
end
|
|
68
74
|
|
|
@@ -93,6 +99,17 @@ module Twingly
|
|
|
93
99
|
channel
|
|
94
100
|
end
|
|
95
101
|
|
|
102
|
+
def create_queue
|
|
103
|
+
case @queue_type
|
|
104
|
+
when :quorum
|
|
105
|
+
@channel.quorum_queue(@queue_name, queue_options)
|
|
106
|
+
when :classic
|
|
107
|
+
@channel.queue(@queue_name, queue_options)
|
|
108
|
+
else
|
|
109
|
+
raise ArgumentError, "Unknown queue type #{@queue_type}"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
96
113
|
def queue_options
|
|
97
114
|
{
|
|
98
115
|
durable: true,
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
module Twingly
|
|
2
2
|
module AMQP
|
|
3
3
|
module Utilities
|
|
4
|
-
def self.create_queue(queue_name, durable: true, arguments: {}, connection: Connection.instance)
|
|
4
|
+
def self.create_queue(queue_name, durable: true, arguments: {}, queue_type: :quorum, connection: Connection.instance)
|
|
5
5
|
connection.with_channel do |channel|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
case queue_type
|
|
7
|
+
when :quorum
|
|
8
|
+
# Quorum queues are always durable, see https://www.rabbitmq.com/quorum-queues.html#feature-matrix
|
|
9
|
+
raise ArgumentError, "durable: false is not supported by quorum queues" unless durable
|
|
10
|
+
|
|
11
|
+
return channel.quorum_queue(queue_name, arguments: arguments)
|
|
12
|
+
when :classic
|
|
13
|
+
return channel.queue(queue_name, durable: durable, arguments: arguments)
|
|
14
|
+
else
|
|
15
|
+
raise ArgumentError, "Unknown queue type '#{queue_type}'"
|
|
16
|
+
end
|
|
11
17
|
end
|
|
12
18
|
end
|
|
13
19
|
end
|
data/lib/twingly/amqp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: twingly-amqp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 6.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Twingly AB
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-10-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bunny
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 2.
|
|
19
|
+
version: 2.20.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 2.
|
|
26
|
+
version: 2.20.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
91
91
|
- !ruby/object:Gem::Version
|
|
92
92
|
version: '0'
|
|
93
93
|
requirements: []
|
|
94
|
-
rubygems_version: 3.
|
|
94
|
+
rubygems_version: 3.4.4
|
|
95
95
|
signing_key:
|
|
96
96
|
specification_version: 4
|
|
97
97
|
summary: Ruby library for talking to RabbitMQ
|