freddy 2.5.1 → 2.7.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: 6d1f9939bd9e7f0a172fc7a4d33a75e7fc8c2ca0f5d955efcdb7a650fba7799d
4
- data.tar.gz: 06e3027b141fd5416d2e875f8fce78b1b7e969db3e5f8990821c6b5fea03d6ef
3
+ metadata.gz: addf621163f5d1faf987bf6ab91d027a538631303543833e1aea8946d3bc0e0b
4
+ data.tar.gz: 22d6eddbd383a2d7b7b46a4e69b2f78b1a0ba6e8a803a1c8b13be7a8be9d3948
5
5
  SHA512:
6
- metadata.gz: c4624e65aaa2837868783c660dbd1ed8e6d51618c8c062a26812bd873b8f95464a8cd0df39c33220c1ee21f0b485dbf2d9e9b4d8337c22af0821e2f58c156c7e
7
- data.tar.gz: 48c0e50064604225a46bb2060cf1c9e7a9bd92da221189eac1b2c902ab1ca6b7ef2c78290827142d263ea71fd624e9df602572bbef455929d88971196ba8c16a
6
+ metadata.gz: 569d91cfe03265013e808bd1847c023b5e307e0411b12ef8113e54e3c471953f21f7a0ed3603c81513cf4a4d628447347d1d582e808b14cdd7f58ef5c8d5023c
7
+ data.tar.gz: bdeb3e75486d8f026e30d1766db834f2d6f7bad2e788f8d74eaaa836e428d02f56101d1e67b8ec5697cbd04ed9b891e6b98933d5c483c17e200b64cf8b877afd
@@ -15,8 +15,7 @@ jobs:
15
15
 
16
16
 
17
17
  - name: Release Gem
18
- uses: discourse/publish-rubygems-action@b55d7b91b55e61752dc6cbc2972f8e16fe6c1a02
18
+ uses: discourse/publish-rubygems-action@ec5415e2cc3509a5cc8c4eef9499cf3fb05f8391
19
19
  env:
20
- GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21
20
  RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
21
  RELEASE_COMMAND: rake release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freddy (2.5.1)
4
+ freddy (2.7.0)
5
5
  bunny (~> 2.11)
6
6
  concurrent-ruby (~> 1.0)
7
7
  oj (~> 3.6)
@@ -14,16 +14,16 @@ GEM
14
14
  specs:
15
15
  amq-protocol (2.3.2)
16
16
  ast (2.4.2)
17
- bunny (2.19.0)
17
+ bunny (2.22.0)
18
18
  amq-protocol (~> 2.3, >= 2.3.1)
19
19
  sorted_set (~> 1, >= 1.0.2)
20
20
  coderay (1.1.3)
21
- concurrent-ruby (1.1.9)
21
+ concurrent-ruby (1.2.2)
22
22
  diff-lcs (1.4.4)
23
23
  hamster (3.0.0)
24
24
  concurrent-ruby (~> 1.0)
25
25
  method_source (1.0.0)
26
- oj (3.13.21)
26
+ oj (3.15.0)
27
27
  opentelemetry-api (1.1.0)
28
28
  opentelemetry-common (0.19.6)
29
29
  opentelemetry-api (~> 1.0)
@@ -34,7 +34,7 @@ GEM
34
34
  opentelemetry-common (~> 0.19.3)
35
35
  opentelemetry-registry (~> 0.2)
36
36
  opentelemetry-semantic_conventions
37
- opentelemetry-semantic_conventions (1.8.0)
37
+ opentelemetry-semantic_conventions (1.10.0)
38
38
  opentelemetry-api (~> 1.0)
39
39
  parallel (1.22.1)
40
40
  parser (3.1.2.0)
@@ -44,7 +44,7 @@ GEM
44
44
  method_source (~> 1.0)
45
45
  rainbow (3.1.1)
46
46
  rake (13.0.6)
47
- rbtree (0.4.5)
47
+ rbtree (0.4.6)
48
48
  regexp_parser (2.5.0)
49
49
  rexml (3.2.5)
50
50
  rspec (3.10.0)
@@ -3,8 +3,8 @@
3
3
  class Freddy
4
4
  module Consumers
5
5
  class RespondToConsumer
6
- def self.consume(*attrs, &block)
7
- new(*attrs).consume(&block)
6
+ def self.consume(**attrs, &block)
7
+ new(**attrs).consume(&block)
8
8
  end
9
9
 
10
10
  def initialize(thread_pool:, destination:, channel:, handler_adapter_factory:)
@@ -3,8 +3,8 @@
3
3
  class Freddy
4
4
  module Consumers
5
5
  class TapIntoConsumer
6
- def self.consume(*attrs, &block)
7
- new(*attrs).consume(&block)
6
+ def self.consume(**attrs, &block)
7
+ new(**attrs).consume(&block)
8
8
  end
9
9
 
10
10
  def initialize(thread_pool:, patterns:, channel:, options:)
@@ -29,7 +29,7 @@ class Freddy
29
29
  private
30
30
 
31
31
  def create_queue
32
- topic_exchange = @channel.topic(Freddy::FREDDY_TOPIC_EXCHANGE_NAME)
32
+ topic_exchange = @channel.topic(exchange_name)
33
33
 
34
34
  queue =
35
35
  if group
@@ -48,7 +48,7 @@ class Freddy
48
48
  def process_message(_queue, delivery)
49
49
  @consume_thread_pool.post do
50
50
  delivery.in_span do
51
- yield delivery.payload, delivery.routing_key
51
+ yield delivery.payload, delivery.routing_key, delivery.timestamp
52
52
  @channel.acknowledge(delivery.tag)
53
53
  end
54
54
  rescue StandardError
@@ -76,6 +76,10 @@ class Freddy
76
76
  def on_exception
77
77
  @options.fetch(:on_exception, :ack)
78
78
  end
79
+
80
+ def exchange_name
81
+ @options.fetch(:exchange_name, Freddy::FREDDY_TOPIC_EXCHANGE_NAME)
82
+ end
79
83
  end
80
84
  end
81
85
  end
@@ -24,6 +24,10 @@ class Freddy
24
24
  @metadata.reply_to
25
25
  end
26
26
 
27
+ def timestamp
28
+ @metadata[:timestamp]
29
+ end
30
+
27
31
  def in_span(&block)
28
32
  name = "#{Tracing.span_destination(@exchange, @routing_key)} process"
29
33
  kind = OpenTelemetry::Trace::SpanKind::CONSUMER
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Freddy
4
- VERSION = '2.5.1'
4
+ VERSION = '2.7.0'
5
5
  end
data/lib/freddy.rb CHANGED
@@ -85,10 +85,12 @@ class Freddy
85
85
  handler_adapter_factory = MessageHandlerAdapters::Factory.new(producer)
86
86
 
87
87
  Consumers::RespondToConsumer.consume(
88
- thread_pool: Concurrent::FixedThreadPool.new(@prefetch_buffer_size),
89
- destination: destination,
90
- channel: channel,
91
- handler_adapter_factory: handler_adapter_factory,
88
+ **{
89
+ thread_pool: Concurrent::FixedThreadPool.new(@prefetch_buffer_size),
90
+ destination: destination,
91
+ channel: channel,
92
+ handler_adapter_factory: handler_adapter_factory
93
+ },
92
94
  &callback
93
95
  )
94
96
  end
@@ -115,8 +117,16 @@ class Freddy
115
117
  # `:ack` simply acknowledges the message and re-raises the exception. `:reject`
116
118
  # rejects the message without requeueing it. `:requeue` rejects the message with
117
119
  # `requeue` flag.
120
+ # @option options [String] :exchange_name
121
+ # Exchange to bind to. Default is `freddy-topic`.
118
122
  #
119
- # @yield [message] Yields received message to the block
123
+ # @yield [message] Yields received message to the block.
124
+ # @yieldparam [Object] payload
125
+ # Yields the received message's payload.
126
+ # @yieldparam [String] routing_key
127
+ # Yields the received message's routing key.
128
+ # @yieldparam [Time] timestamp
129
+ # Yields received message's timestamp.
120
130
  #
121
131
  # @return [#shutdown]
122
132
  #
@@ -128,10 +138,12 @@ class Freddy
128
138
  @logger.debug "Tapping into messages that match #{pattern_or_patterns}"
129
139
 
130
140
  Consumers::TapIntoConsumer.consume(
131
- thread_pool: Concurrent::FixedThreadPool.new(@prefetch_buffer_size),
132
- patterns: Array(pattern_or_patterns),
133
- channel: @connection.create_channel(prefetch: @prefetch_buffer_size),
134
- options: options,
141
+ **{
142
+ thread_pool: Concurrent::FixedThreadPool.new(@prefetch_buffer_size),
143
+ patterns: Array(pattern_or_patterns),
144
+ channel: @connection.create_channel(prefetch: @prefetch_buffer_size),
145
+ options: options
146
+ },
135
147
  &callback
136
148
  )
137
149
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freddy do
4
- let(:freddy) { described_class.build(logger, config) }
4
+ let(:freddy) { described_class.build(logger, **config) }
5
5
 
6
6
  let(:destination) { random_destination }
7
7
  let(:destination2) { random_destination }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freddy::ResponderHandler do
4
- let(:freddy) { Freddy.build(logger, config) }
4
+ let(:freddy) { Freddy.build(logger, **config) }
5
5
 
6
6
  let(:destination) { random_destination }
7
7
  let(:payload) { { pay: 'load' } }
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
  require 'hamster/experimental/mutable_set'
3
3
 
4
4
  describe 'Concurrency' do
5
- let(:freddy1) { Freddy.build(logger, config) }
6
- let(:freddy2) { Freddy.build(logger, config) }
7
- let(:freddy3) { Freddy.build(logger, config) }
5
+ let(:freddy1) { Freddy.build(logger, **config) }
6
+ let(:freddy2) { Freddy.build(logger, **config) }
7
+ let(:freddy3) { Freddy.build(logger, **config) }
8
8
 
9
9
  after { [freddy1, freddy2, freddy3].each(&:close) }
10
10
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Reply' do
4
- let(:freddy) { Freddy.build(logger, config) }
4
+ let(:freddy) { Freddy.build(logger, **config) }
5
5
 
6
6
  let(:destination) { random_destination }
7
7
  let(:request_payload) { { req: 'load' } }
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Tapping into with exchange identifier' do
4
+ let(:freddy) { Freddy.build(logger, **config) }
5
+
6
+ let(:connection) { Freddy::Adapters.determine.connect(config) }
7
+ let(:topic) { 'test_topic_exchange' }
8
+ let(:channel) { connection.create_channel }
9
+ let(:message_payload) { { test: 'test' }.to_json }
10
+ let(:expected_payload) { { test: 'test' } }
11
+ let(:publish_timestamp) { Time.now.to_i }
12
+
13
+ after do
14
+ connection.close
15
+ freddy.close
16
+ end
17
+
18
+ it 'receives message' do
19
+ freddy.tap_into('pattern.*', exchange_name: topic) do |payload, _routing_key, timestamp|
20
+ @received_payload = payload
21
+ @received_timestamp = timestamp
22
+ end
23
+
24
+ channel.topic(topic).publish(message_payload, { routing_key: 'pattern.random', timestamp: publish_timestamp })
25
+
26
+ wait_for { @received_payload }
27
+ wait_for { @received_timestamp }
28
+
29
+ expect(@received_payload).to eq(expected_payload)
30
+ expect(@received_timestamp.to_i).to eq(publish_timestamp)
31
+ end
32
+
33
+ it 'receives message with nil timestamp when timestamp is not published' do
34
+ received_timestamp = 0
35
+ freddy.tap_into('pattern.*', exchange_name: topic) do |_payload, _routing_key, timestamp|
36
+ received_timestamp = timestamp
37
+ end
38
+
39
+ channel.topic(topic).publish(message_payload, { routing_key: 'pattern.random' })
40
+ default_sleep
41
+
42
+ expect(received_timestamp).to eq(nil)
43
+ end
44
+ end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
  require 'hamster/experimental/mutable_set'
3
3
 
4
4
  describe 'Tapping into with group identifier' do
5
- let(:deliverer) { Freddy.build(logger, config) }
6
- let(:responder1) { Freddy.build(logger, config) }
7
- let(:responder2) { Freddy.build(logger, config) }
5
+ let(:deliverer) { Freddy.build(logger, **config) }
6
+ let(:responder1) { Freddy.build(logger, **config) }
7
+ let(:responder2) { Freddy.build(logger, **config) }
8
8
 
9
9
  let(:destination) { random_destination }
10
10
 
@@ -8,8 +8,8 @@ describe 'Tracing' do
8
8
  end
9
9
 
10
10
  context 'when receiving a traced request' do
11
- let(:freddy) { Freddy.build(logger, config) }
12
- let(:freddy2) { Freddy.build(logger, config) }
11
+ let(:freddy) { Freddy.build(logger, **config) }
12
+ let(:freddy2) { Freddy.build(logger, **config) }
13
13
 
14
14
  let(:destination) { random_destination }
15
15
  let(:destination2) { random_destination }
@@ -63,9 +63,9 @@ describe 'Tracing' do
63
63
  end
64
64
 
65
65
  context 'when receiving a nested traced request' do
66
- let(:freddy) { Freddy.build(logger, config) }
67
- let(:freddy2) { Freddy.build(logger, config) }
68
- let(:freddy3) { Freddy.build(logger, config) }
66
+ let(:freddy) { Freddy.build(logger, **config) }
67
+ let(:freddy2) { Freddy.build(logger, **config) }
68
+ let(:freddy3) { Freddy.build(logger, **config) }
69
69
 
70
70
  let(:destination) { random_destination }
71
71
  let(:destination2) { random_destination }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-29 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -176,6 +176,7 @@ files:
176
176
  - spec/freddy/sync_response_container_spec.rb
177
177
  - spec/integration/concurrency_spec.rb
178
178
  - spec/integration/reply_spec.rb
179
+ - spec/integration/tap_into_with_exchange_spec.rb
179
180
  - spec/integration/tap_into_with_group_spec.rb
180
181
  - spec/integration/tracing_spec.rb
181
182
  - spec/spec_helper.rb