freddy 2.6.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish.yml +1 -2
- data/Gemfile.lock +6 -6
- data/README.md +5 -0
- data/lib/freddy/consumers/tap_into_consumer.rb +6 -2
- data/lib/freddy/delivery.rb +4 -0
- data/lib/freddy/version.rb +1 -1
- data/lib/freddy.rb +12 -1
- data/spec/freddy/freddy_spec.rb +27 -1
- data/spec/integration/tap_into_with_exchange_spec.rb +44 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d728d028687af2cb365212bcbdc4bb278b2116ff665f64aa35ee75c057126455
|
4
|
+
data.tar.gz: '019059f31b8da95352ec6b66e47ec73ff762b5b8c82b912d044b6e1820f717b2'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eae3c233c958e0936d1da27dc99bc83274a2e673bc4107e2716617fd23c389a4c27632777ecefebb8a7a17a73246a3ba5c208436143d5a39b7030f446bb9e6b
|
7
|
+
data.tar.gz: 17901b6c33f2a454032b23e8afb195e5f37cc1481f75f77b9f88c759f225dd4b3e1bb5a0547d6c62c0730df8d9757215ec5d2fd3c35a199a71595e07348c3277
|
@@ -15,8 +15,7 @@ jobs:
|
|
15
15
|
|
16
16
|
|
17
17
|
- name: Release Gem
|
18
|
-
uses: discourse/publish-rubygems-action@
|
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.
|
4
|
+
freddy (2.8.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.
|
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.
|
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.
|
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.
|
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.
|
47
|
+
rbtree (0.4.6)
|
48
48
|
regexp_parser (2.5.0)
|
49
49
|
rexml (3.2.5)
|
50
50
|
rspec (3.10.0)
|
data/README.md
CHANGED
@@ -55,6 +55,11 @@ The message heading specify the `content-encoding` indicating the compression al
|
|
55
55
|
freddy.deliver(destination, message, compress: 'zlib')
|
56
56
|
```
|
57
57
|
|
58
|
+
#### Metadata through headers
|
59
|
+
|
60
|
+
Send a message with arbitrary message metadata included in the message headers
|
61
|
+
freddy.deliver(destination, message, headers: {'my-key' => 'my-value'})
|
62
|
+
|
58
63
|
### Request delivery
|
59
64
|
|
60
65
|
#### Expiring messages
|
@@ -29,7 +29,7 @@ class Freddy
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def create_queue
|
32
|
-
topic_exchange = @channel.topic(
|
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
|
data/lib/freddy/delivery.rb
CHANGED
data/lib/freddy/version.rb
CHANGED
data/lib/freddy.rb
CHANGED
@@ -117,8 +117,16 @@ class Freddy
|
|
117
117
|
# `:ack` simply acknowledges the message and re-raises the exception. `:reject`
|
118
118
|
# rejects the message without requeueing it. `:requeue` rejects the message with
|
119
119
|
# `requeue` flag.
|
120
|
+
# @option options [String] :exchange_name
|
121
|
+
# Exchange to bind to. Default is `freddy-topic`.
|
120
122
|
#
|
121
|
-
# @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.
|
122
130
|
#
|
123
131
|
# @return [#shutdown]
|
124
132
|
#
|
@@ -158,6 +166,8 @@ class Freddy
|
|
158
166
|
# won't be discarded if timeout it set to 0 (default).
|
159
167
|
# @option options [String] :compress (nil)
|
160
168
|
# - 'zlib' - compresses the payload with zlib
|
169
|
+
# @option options [Hash] :headers (nil)
|
170
|
+
# Arbitrary headers to add as message metadata
|
161
171
|
# @return [void]
|
162
172
|
#
|
163
173
|
# @example
|
@@ -168,6 +178,7 @@ class Freddy
|
|
168
178
|
opts = {}
|
169
179
|
opts[:expiration] = (timeout * 1000).to_i if timeout.positive?
|
170
180
|
opts[:content_encoding] = compression_algorithm if compression_algorithm
|
181
|
+
opts[:headers] = options[:headers] if options[:headers]
|
171
182
|
|
172
183
|
@send_and_forget_producer.produce(destination, payload, opts)
|
173
184
|
end
|
data/spec/freddy/freddy_spec.rb
CHANGED
@@ -7,7 +7,15 @@ describe Freddy do
|
|
7
7
|
let(:destination2) { random_destination }
|
8
8
|
let(:payload) { { pay: 'load' } }
|
9
9
|
|
10
|
-
|
10
|
+
before do
|
11
|
+
@bunny = Bunny.new(config)
|
12
|
+
@bunny.start
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
@bunny.close
|
17
|
+
freddy.close
|
18
|
+
end
|
11
19
|
|
12
20
|
def respond_to(&block)
|
13
21
|
freddy.respond_to(destination, &block)
|
@@ -72,6 +80,24 @@ describe Freddy do
|
|
72
80
|
expect(@tapped_message).to eq(payload)
|
73
81
|
end
|
74
82
|
end
|
83
|
+
|
84
|
+
it 'accepts custom headers' do
|
85
|
+
headers = nil
|
86
|
+
queue = exclusive_subscribe do |_info, metadata, _payload|
|
87
|
+
headers = metadata[:headers]
|
88
|
+
end
|
89
|
+
freddy.deliver(queue, payload, headers: { 'foo' => 'bar' })
|
90
|
+
|
91
|
+
wait_for { headers }
|
92
|
+
expect(headers).to include({ 'foo' => 'bar' })
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def exclusive_subscribe(&block)
|
97
|
+
channel = @bunny.create_channel
|
98
|
+
queue = channel.queue('', exclusive: true)
|
99
|
+
queue.subscribe(&block)
|
100
|
+
queue.name
|
75
101
|
end
|
76
102
|
|
77
103
|
context 'when making a synchronized request' do
|
@@ -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
|
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.
|
4
|
+
version: 2.8.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: 2023-
|
11
|
+
date: 2023-09-07 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
|