twingly-amqp 5.2.0 → 6.1.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 +8 -1
- data/lib/twingly/amqp/default_exchange_publisher.rb +4 -2
- data/lib/twingly/amqp/publisher.rb +7 -7
- 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: 72327e797eeb0baacb83fa4a8680f6108a2cacdc6aa1185bbd3dfd855a1738c9
|
4
|
+
data.tar.gz: a0fee780601c0d0bed3afa6f4a70e99fe775c09c3f72b8674f5ac840103252c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d7692b89922e73d8c9056a863f5039371c4ac1962d2419fe5144d00f553ad343b989d3dcc70e727902f3a3c3dc6ad981a6de0cdacd9cb189295413a5b7428ca
|
7
|
+
data.tar.gz: d50510058e01960b482712b3719182ca32a88854c0ded35c967b91cca087cd083f37ac67e892c9f960ca0fc6d00da73ab3792cc9f38bf5d0347db91ffe7d3f41
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Twingly::AMQP
|
2
2
|
|
3
|
-
[](https://github.com/twingly/twingly-amqp/actions)
|
4
4
|
|
5
5
|
A gem for subscribing and publishing messages via RabbitMQ.
|
6
6
|
|
@@ -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}" }
|
@@ -130,6 +132,9 @@ publisher.configure_publish_options do |options|
|
|
130
132
|
end
|
131
133
|
|
132
134
|
publisher.publish({ my: "data" })
|
135
|
+
|
136
|
+
publisher.publish({ my: "other_data" }, routing_key: "my_other_key") # Override routing_key or other publishing options
|
137
|
+
# accepted by Bunny::Exchange#publish
|
133
138
|
```
|
134
139
|
|
135
140
|
### Publish delayed messages
|
@@ -141,6 +146,8 @@ publisher = Twingly::AMQP::DefaultExchangePublisher.delayed(
|
|
141
146
|
target_queue_name: "my_queue", # Queue which delayed messages will be
|
142
147
|
# published to after the delay has elapsed
|
143
148
|
delay_ms: 60_000,
|
149
|
+
delay_queue_type: :quorum, # Optional. Which type of queue to define the delay queue
|
150
|
+
# as. Possible values are :quorum (default) or :classic
|
144
151
|
)
|
145
152
|
|
146
153
|
# 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|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Twingly
|
2
2
|
module AMQP
|
3
3
|
module Publisher
|
4
|
-
def publish(message)
|
4
|
+
def publish(message, opts = {})
|
5
5
|
payload =
|
6
6
|
if message.kind_of?(Array)
|
7
7
|
message
|
@@ -11,17 +11,17 @@ module Twingly
|
|
11
11
|
raise ArgumentError
|
12
12
|
end
|
13
13
|
|
14
|
-
json_payload
|
15
|
-
|
16
|
-
@exchange.publish(json_payload,
|
14
|
+
json_payload = payload.to_json
|
15
|
+
publishing_options = options.to_h.merge(opts)
|
16
|
+
@exchange.publish(json_payload, publishing_options)
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
20
|
-
def publish_with_confirm(message)
|
19
|
+
# Only used by tests to lessen the time we need to sleep
|
20
|
+
def publish_with_confirm(message, opts = {})
|
21
21
|
channel = @exchange.channel
|
22
22
|
channel.confirm_select unless channel.using_publisher_confirmations?
|
23
23
|
|
24
|
-
publish(message)
|
24
|
+
publish(message, opts)
|
25
25
|
|
26
26
|
@exchange.wait_for_confirms
|
27
27
|
end
|
@@ -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.1.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-12-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
|