twingly-amqp 5.0.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c61cf032af90e6b91d1c690ad02f89c6a46e3cc7879813e47f1ee89a1367609a
4
- data.tar.gz: 6508f9911ef9dcb8c64854522915129878905e62620dbf022ec104e8a911354a
3
+ metadata.gz: 9addd8c457e9a56236f8e77d5c8a695859b39c8e2f77660e5cea41d66b515095
4
+ data.tar.gz: e9c37097b065eeb9a60f25f659597975452a7b26c643d8fd81bd165bf2b6fa0a
5
5
  SHA512:
6
- metadata.gz: 0f66b4eda7c713585780fa20f1bae2948b3251f00929f16fd01273f3298a32fb921eaa334e5814f464eac85446bdc17be227e9f850293a0bb753131f061a6f37
7
- data.tar.gz: 87c30a0c5e817ea29be19da7b99e3d156f4ba6ca303abd63ebb265827673c90ac3b64ca22bd9d3e5df355163fb29b888931e41d6637282460d598c2bff4114b4
6
+ metadata.gz: eebc4870eeca8f9c58298b5f839569338da8e1e862b785512babd5f7fa28492a40a069762c136d65d4c31142d1360b27cf23e5b1044dc3b4f9feac8b1ace623e
7
+ data.tar.gz: bfbd5d0598e5ba0abbf2d292ef4bee8847ee67dfd1e2d67f9a5c4b8a64a2e2131aa73c91267b9088ee5fa36162f3e7138be0b22c8c081205f290ca8de68cb035
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Twingly::AMQP
2
2
 
3
- [![Build Status](https://travis-ci.org/twingly/twingly-amqp.svg?branch=master)](https://travis-ci.org/twingly/twingly-amqp)
4
-
3
+ [![GitHub Build Status](https://github.com/twingly/twingly-amqp/workflows/CI/badge.svg?branch=master)](https://github.com/twingly/twingly-amqp/actions)
5
4
 
6
5
  A gem for subscribing and publishing messages via RabbitMQ.
7
6
 
@@ -133,6 +132,22 @@ end
133
132
  publisher.publish({ my: "data" })
134
133
  ```
135
134
 
135
+ ### Publish delayed messages
136
+
137
+ ```ruby
138
+ publisher = Twingly::AMQP::DefaultExchangePublisher.delayed(
139
+ delay_queue_name: "my_queue.delayed", # Queue where delayed messages will
140
+ # wait until delay_ms has passed
141
+ target_queue_name: "my_queue", # Queue which delayed messages will be
142
+ # published to after the delay has elapsed
143
+ delay_ms: 60_000,
144
+ )
145
+
146
+ # Publishes message to the delay queue. After delay_ms has passed,
147
+ # the message will be rerouted to the target queue specified above
148
+ publisher.publish({ my: "data" })
149
+ ```
150
+
136
151
  ### Ping urls
137
152
 
138
153
  ```ruby
@@ -199,6 +214,12 @@ connection = Twingly::AMQP::Connection.instance
199
214
 
200
215
  The integration tests run by default and require a local RabbitMQ server to run.
201
216
 
217
+ Start RabbitMQ server with
218
+
219
+ ```shell
220
+ docker-compose up
221
+ ```
222
+
202
223
  Run tests with
203
224
 
204
225
  ```shell
@@ -230,7 +251,7 @@ To run static code analysis:
230
251
 
231
252
  bundle exec rake release
232
253
 
233
- * If you are not logged in as [twingly][twingly-rubygems] with ruby gems, the rake task will fail and tell you to set credentials via `gem push`, do that and run the `release` task again. It will be okay.
254
+ * If you are not logged in as [twingly][twingly-rubygems] with ruby gems, the rake task will fail. Login using `gem signin` and run the `release` task again. It will be okay.
234
255
 
235
256
  * Update the changelog with [GitHub Changelog Generator](https://github.com/skywinder/github-changelog-generator/) (`gem install github_changelog_generator` if you don't have it, set `CHANGELOG_GITHUB_TOKEN` to a personal access token to avoid rate limiting by GitHub). This command will update `CHANGELOG.md`, commit and push manually.
236
257
 
data/lib/twingly/amqp.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "twingly/amqp/version"
2
2
  require "twingly/amqp/session"
3
3
  require "twingly/amqp/connection"
4
+ require "twingly/amqp/utilities"
4
5
  require "twingly/amqp/subscription"
5
6
  require "twingly/amqp/ping_options"
6
7
  require "twingly/amqp/pinger"
@@ -8,7 +9,10 @@ require "twingly/amqp/publisher"
8
9
  require "twingly/amqp/default_exchange_publisher"
9
10
  require "twingly/amqp/topic_exchange_publisher"
10
11
  require "twingly/amqp/null_logger"
12
+ require "twingly/amqp/message"
11
13
 
14
+ require "bunny"
15
+ require "json"
12
16
  require "ostruct"
13
17
 
14
18
  module Twingly
@@ -1,5 +1,3 @@
1
- require "twingly/amqp"
2
-
3
1
  module Twingly
4
2
  module AMQP
5
3
  class Connection
@@ -1,17 +1,29 @@
1
- require "twingly/amqp/publisher"
2
- require "twingly/amqp/connection"
3
-
4
1
  module Twingly
5
2
  module AMQP
6
3
  class DefaultExchangePublisher
7
4
  include Publisher
8
5
 
9
- def initialize(queue_name:, connection: nil)
6
+ DEFAULT_EXCHANGE = ""
7
+
8
+ def initialize(queue_name:, connection: Connection.instance)
10
9
  options.routing_key = queue_name
11
10
 
12
- connection ||= Connection.instance
13
11
  @exchange = connection.create_channel.default_exchange
14
12
  end
13
+
14
+ def self.delayed(delay_queue_name:, target_queue_name:, delay_ms:, connection: Connection.instance)
15
+ Utilities.create_queue(delay_queue_name,
16
+ arguments: {
17
+ "x-dead-letter-exchange": DEFAULT_EXCHANGE,
18
+ "x-dead-letter-routing-key": target_queue_name,
19
+ })
20
+
21
+ new(queue_name: delay_queue_name, connection: connection).tap do |publisher|
22
+ publisher.configure_publish_options do |options|
23
+ options.expiration = delay_ms
24
+ end
25
+ end
26
+ end
15
27
  end
16
28
  end
17
29
  end
@@ -1,5 +1,3 @@
1
- require "json"
2
-
3
1
  module Twingly
4
2
  module AMQP
5
3
  class Message
@@ -1,14 +1,8 @@
1
- require "twingly/amqp/connection"
2
- require "twingly/amqp/ping_options"
3
- require "twingly/amqp/default_exchange_publisher"
4
- require "json"
5
-
6
1
  module Twingly
7
2
  module AMQP
8
3
  class Pinger
9
- def initialize(queue_name:, ping_expiration: nil, url_cache: NullCache, connection: nil, confirm_publish: false)
4
+ def initialize(queue_name:, ping_expiration: nil, url_cache: NullCache, connection: Connection.instance, confirm_publish: false)
10
5
  @url_cache = url_cache
11
- connection ||= Connection.instance
12
6
 
13
7
  @publisher = DefaultExchangePublisher.new(queue_name: queue_name, connection: connection)
14
8
  @publisher.configure_publish_options do |options|
@@ -1,6 +1,3 @@
1
- require "json"
2
- require "ostruct"
3
-
4
1
  module Twingly
5
2
  module AMQP
6
3
  module Publisher
@@ -1,5 +1,3 @@
1
- require "bunny"
2
-
3
1
  module Twingly
4
2
  module AMQP
5
3
  class Session
@@ -1,25 +1,22 @@
1
- require "twingly/amqp/connection"
2
- require "twingly/amqp/message"
3
-
4
1
  module Twingly
5
2
  module AMQP
6
3
  class Subscription
7
4
  def initialize(queue_name:, exchange_topic: nil, routing_key: nil,
8
5
  routing_keys: nil, consumer_threads: 1, prefetch: 20,
9
- connection: nil, max_length: nil)
6
+ connection: Connection.instance, max_length: nil)
10
7
  @queue_name = queue_name
11
8
  @exchange_topic = exchange_topic
12
9
  @routing_keys = Array(routing_keys || routing_key)
13
10
  @consumer_threads = consumer_threads
14
11
  @prefetch = prefetch
15
12
  @max_length = max_length
13
+ @cancel = false
16
14
 
17
15
  if routing_key
18
16
  warn "[DEPRECATION] `routing_key` is deprecated. "\
19
17
  "Please use `routing_keys` instead."
20
18
  end
21
19
 
22
- connection ||= Connection.instance
23
20
  @channel = create_channel(connection)
24
21
  @queue = @channel.queue(@queue_name, queue_options)
25
22
 
@@ -1,15 +1,11 @@
1
- require "twingly/amqp/publisher"
2
- require "twingly/amqp/connection"
3
-
4
1
  module Twingly
5
2
  module AMQP
6
3
  class TopicExchangePublisher
7
4
  include Publisher
8
5
 
9
- def initialize(exchange_name:, routing_key: nil, connection: nil, opts: {})
6
+ def initialize(exchange_name:, routing_key: nil, connection: Connection.instance, opts: {})
10
7
  options.routing_key = routing_key
11
8
 
12
- connection ||= Connection.instance
13
9
  @exchange = connection.create_channel.topic(exchange_name, opts)
14
10
  end
15
11
  end
@@ -0,0 +1,15 @@
1
+ module Twingly
2
+ module AMQP
3
+ module Utilities
4
+ def self.create_queue(queue_name, durable: true, arguments: {}, connection: Connection.instance)
5
+ connection.with_channel do |channel|
6
+ return channel.queue(
7
+ queue_name,
8
+ durable: durable,
9
+ arguments: arguments,
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Twingly
2
2
  module Amqp
3
- VERSION = "5.0.1".freeze
3
+ VERSION = "5.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twingly-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.2.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: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.6'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 2.6.2
19
+ version: 2.7.3
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.6'
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 2.6.2
26
+ version: 2.7.3
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rake
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +71,7 @@ files:
77
71
  - lib/twingly/amqp/session.rb
78
72
  - lib/twingly/amqp/subscription.rb
79
73
  - lib/twingly/amqp/topic_exchange_publisher.rb
74
+ - lib/twingly/amqp/utilities.rb
80
75
  - lib/twingly/amqp/version.rb
81
76
  homepage: https://github.com/twingly/twingly-amqp
82
77
  licenses: []