freddy 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,21 +10,17 @@ describe 'Concurrency' do
10
10
 
11
11
  it 'supports multiple requests in #respond_to' do
12
12
  freddy1.respond_to 'Concurrency1' do |_payload, msg_handler|
13
- begin
14
- freddy1.deliver_with_response 'Concurrency2', msg: 'noop'
15
- result2 = freddy1.deliver_with_response 'Concurrency3', msg: 'noop'
16
- msg_handler.success(result2)
17
- rescue Freddy::InvalidRequestError => e
18
- msg_handler.error(e.response)
19
- end
13
+ freddy1.deliver_with_response 'Concurrency2', msg: 'noop'
14
+ result2 = freddy1.deliver_with_response 'Concurrency3', msg: 'noop'
15
+ msg_handler.success(result2)
16
+ rescue Freddy::InvalidRequestError => e
17
+ msg_handler.error(e.response)
20
18
  end
21
19
 
22
20
  freddy2.respond_to 'Concurrency2' do |_payload, msg_handler|
23
- begin
24
- msg_handler.success(from: 'Concurrency2')
25
- rescue Freddy::InvalidRequestError => e
26
- msg_handler.error(e.response)
27
- end
21
+ msg_handler.success(from: 'Concurrency2')
22
+ rescue Freddy::InvalidRequestError => e
23
+ msg_handler.error(e.response)
28
24
  end
29
25
 
30
26
  freddy3.respond_to 'Concurrency3' do |_payload, msg_handler|
@@ -10,6 +10,11 @@ describe 'Tapping into with group identifier' do
10
10
 
11
11
  after { [deliverer, responder1, responder2].each(&:close) }
12
12
 
13
+ it 'raises an exception if option :durable is provided without group' do
14
+ expect { responder1.tap_into(destination, durable: true) }
15
+ .to raise_error(RuntimeError)
16
+ end
17
+
13
18
  it 'receives a message once' do
14
19
  msg_counter = Hamster::MutableSet[]
15
20
 
@@ -21,4 +26,33 @@ describe 'Tapping into with group identifier' do
21
26
  default_sleep
22
27
  expect(msg_counter.count).to eq(1)
23
28
  end
29
+
30
+ it 'can requeue message on exception' do
31
+ counter = 0
32
+
33
+ responder1.tap_into(destination, group: arbitrary_id, on_exception: :requeue) do
34
+ counter += 1
35
+ raise 'error' if counter == 1
36
+ end
37
+
38
+ deliverer.deliver(destination, {})
39
+
40
+ wait_for { counter == 2 }
41
+ expect(counter).to eq(2)
42
+ end
43
+
44
+ it 'taps into multiple topics' do
45
+ destination2 = random_destination
46
+ counter = 0
47
+
48
+ responder1.tap_into([destination, destination2], group: arbitrary_id) do
49
+ counter += 1
50
+ end
51
+
52
+ deliverer.deliver(destination, {})
53
+ deliverer.deliver(destination2, {})
54
+
55
+ wait_for { counter == 2 }
56
+ expect(counter).to eq(2)
57
+ end
24
58
  end
@@ -1,13 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'opentracing_test_tracer'
3
2
 
4
3
  describe 'Tracing' do
5
- let(:tracer) { OpenTracingTestTracer.build(logger: logger) }
6
4
  let(:logger) { spy }
7
5
 
8
- before { OpenTracing.global_tracer = tracer }
9
- after { OpenTracing.global_tracer = nil }
10
-
11
6
  context 'when receiving a traced request' do
12
7
  let(:freddy) { Freddy.build(logger, config) }
13
8
  let(:freddy2) { Freddy.build(logger, config) }
@@ -18,21 +13,13 @@ describe 'Tracing' do
18
13
  before do
19
14
  freddy.respond_to(destination) do |_payload, msg_handler|
20
15
  msg_handler.success(
21
- trace_initiator: {
22
- trace_id: active_span.context.trace_id,
23
- parent_id: active_span.context.parent_id,
24
- span_id: active_span.context.span_id
25
- },
16
+ trace_initiator: current_span_attributes,
26
17
  current_receiver: freddy.deliver_with_response(destination2, {})
27
18
  )
28
19
  end
29
20
 
30
21
  freddy2.respond_to(destination2) do |_payload, msg_handler|
31
- msg_handler.success(
32
- trace_id: active_span.context.trace_id,
33
- parent_id: active_span.context.parent_id,
34
- span_id: active_span.context.span_id
35
- )
22
+ msg_handler.success(current_span_attributes)
36
23
  end
37
24
  end
38
25
 
@@ -75,31 +62,19 @@ describe 'Tracing' do
75
62
  before do
76
63
  freddy.respond_to(destination) do |_payload, msg_handler|
77
64
  msg_handler.success({
78
- trace_initiator: {
79
- trace_id: active_span.context.trace_id,
80
- parent_id: active_span.context.parent_id,
81
- span_id: active_span.context.span_id
82
- }
65
+ trace_initiator: current_span_attributes
83
66
  }.merge(freddy.deliver_with_response(destination2, {})))
84
67
  end
85
68
 
86
69
  freddy2.respond_to(destination2) do |_payload, msg_handler|
87
70
  msg_handler.success(
88
- previous_receiver: {
89
- trace_id: active_span.context.trace_id,
90
- parent_id: active_span.context.parent_id,
91
- span_id: active_span.context.span_id
92
- },
71
+ previous_receiver: current_span_attributes,
93
72
  current_receiver: freddy2.deliver_with_response(destination3, {})
94
73
  )
95
74
  end
96
75
 
97
76
  freddy3.respond_to(destination3) do |_payload, msg_handler|
98
- msg_handler.success(
99
- trace_id: active_span.context.trace_id,
100
- parent_id: active_span.context.parent_id,
101
- span_id: active_span.context.span_id
102
- )
77
+ msg_handler.success(current_span_attributes)
103
78
  end
104
79
  end
105
80
 
@@ -131,7 +106,15 @@ describe 'Tracing' do
131
106
  end
132
107
  end
133
108
 
134
- def active_span
135
- OpenTracing.active_span
109
+ def current_span_attributes
110
+ {
111
+ trace_id: current_span.context.trace_id,
112
+ parent_id: current_span.parent_span_id,
113
+ span_id: current_span.context.span_id
114
+ }
115
+ end
116
+
117
+ def current_span
118
+ OpenTelemetry::Trace.current_span
136
119
  end
137
120
  end
data/spec/spec_helper.rb CHANGED
@@ -2,14 +2,9 @@ require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.setup
4
4
 
5
- require 'codeclimate-test-reporter'
6
- SimpleCov.start do
7
- formatter SimpleCov::Formatter::MultiFormatter.new([
8
- SimpleCov::Formatter::HTMLFormatter,
9
- CodeClimate::TestReporter::Formatter
10
- ])
11
- add_filter '/spec/'
12
- end
5
+ ENV['OTEL_TRACES_EXPORTER'] = 'none'
6
+ require 'opentelemetry/sdk'
7
+ OpenTelemetry::SDK.configure
13
8
 
14
9
  require 'pry'
15
10
  require 'freddy'
@@ -22,10 +17,6 @@ RSpec.configure do |config|
22
17
  config.run_all_when_everything_filtered = true
23
18
  config.filter_run :focus
24
19
  config.order = 'random'
25
-
26
- config.before do
27
- OpenTracing.global_tracer ||= OpenTracing::Tracer.new
28
- end
29
20
  end
30
21
 
31
22
  def random_destination
@@ -43,6 +34,7 @@ end
43
34
  def wait_for
44
35
  100.times do
45
36
  return if yield
37
+
46
38
  sleep 0.005
47
39
  end
48
40
  end
@@ -53,7 +45,7 @@ def deliver(custom_destination = destination)
53
45
  end
54
46
 
55
47
  def logger
56
- Logger.new(STDOUT).tap { |l| l.level = Logger::ERROR }
48
+ Logger.new($stdout).tap { |l| l.level = Logger::ERROR }
57
49
  end
58
50
 
59
51
  def config
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: 1.4.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Salemove TechMovers
7
+ - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-05 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,28 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.13'
61
+ version: '3.6'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.13'
68
+ version: '3.6'
69
69
  - !ruby/object:Gem::Dependency
70
- name: opentracing
70
+ name: opentelemetry-api
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.4'
75
+ version: 1.0.0.rc3
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.4'
82
+ version: 1.0.0.rc3
83
+ - !ruby/object:Gem::Dependency
84
+ name: opentelemetry-semantic_conventions
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: thread
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -101,13 +115,12 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - ".github/workflows/ci.yml"
104
119
  - ".gitignore"
105
- - ".npmignore"
106
120
  - ".rspec"
107
121
  - ".rubocop.yml"
108
122
  - ".ruby-gemset"
109
123
  - ".ruby-version"
110
- - ".travis.yml"
111
124
  - Gemfile
112
125
  - LICENCE.txt
113
126
  - README.md
@@ -116,7 +129,6 @@ files:
116
129
  - lib/freddy.rb
117
130
  - lib/freddy/adapters.rb
118
131
  - lib/freddy/adapters/bunny_adapter.rb
119
- - lib/freddy/adapters/march_hare_adapter.rb
120
132
  - lib/freddy/consumers.rb
121
133
  - lib/freddy/consumers/respond_to_consumer.rb
122
134
  - lib/freddy/consumers/response_consumer.rb
@@ -135,7 +147,9 @@ files:
135
147
  - lib/freddy/responder_handler.rb
136
148
  - lib/freddy/sync_response_container.rb
137
149
  - lib/freddy/timeout_error.rb
138
- - lib/freddy/trace_carrier.rb
150
+ - lib/freddy/tracing.rb
151
+ - lib/freddy/version.rb
152
+ - spec/.rubocop.yml
139
153
  - spec/freddy/consumers/respond_to_consumer_spec.rb
140
154
  - spec/freddy/error_response_spec.rb
141
155
  - spec/freddy/freddy_spec.rb
@@ -143,15 +157,14 @@ files:
143
157
  - spec/freddy/payload_spec.rb
144
158
  - spec/freddy/responder_handler_spec.rb
145
159
  - spec/freddy/sync_response_container_spec.rb
146
- - spec/freddy/trace_carrier_spec.rb
147
160
  - spec/integration/concurrency_spec.rb
148
161
  - spec/integration/reply_spec.rb
149
162
  - spec/integration/tap_into_with_group_spec.rb
150
163
  - spec/integration/tracing_spec.rb
151
164
  - spec/spec_helper.rb
152
- homepage:
165
+ homepage: https://github.com/salemove/freddy
153
166
  licenses:
154
- - Private
167
+ - MIT
155
168
  metadata: {}
156
169
  post_install_message:
157
170
  rdoc_options: []
@@ -161,19 +174,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
174
  requirements:
162
175
  - - ">="
163
176
  - !ruby/object:Gem::Version
164
- version: '0'
177
+ version: '2.7'
165
178
  required_rubygems_version: !ruby/object:Gem::Requirement
166
179
  requirements:
167
180
  - - ">="
168
181
  - !ruby/object:Gem::Version
169
182
  version: '0'
170
183
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.6.11
184
+ rubygems_version: 3.1.4
173
185
  signing_key:
174
186
  specification_version: 4
175
187
  summary: API for inter-application messaging supporting acknowledgements and request-response
176
188
  test_files:
189
+ - spec/.rubocop.yml
177
190
  - spec/freddy/consumers/respond_to_consumer_spec.rb
178
191
  - spec/freddy/error_response_spec.rb
179
192
  - spec/freddy/freddy_spec.rb
@@ -181,7 +194,6 @@ test_files:
181
194
  - spec/freddy/payload_spec.rb
182
195
  - spec/freddy/responder_handler_spec.rb
183
196
  - spec/freddy/sync_response_container_spec.rb
184
- - spec/freddy/trace_carrier_spec.rb
185
197
  - spec/integration/concurrency_spec.rb
186
198
  - spec/integration/reply_spec.rb
187
199
  - spec/integration/tap_into_with_group_spec.rb
data/.npmignore DELETED
@@ -1,8 +0,0 @@
1
- .git*
2
- .rspec
3
- .ruby*
4
- Gemfile*
5
- *.gemspec
6
- spec/
7
- *.rb
8
- lib/messaging
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4.1
4
- - jruby-9.1.5.0
5
- addons:
6
- code_climate:
7
- repo_token: 1f3842b985fdeff6a36168165d491ca5f444667e9381a85c899a61706a9dd285
8
- services:
9
- - rabbitmq
10
- before_script:
11
- - gem install bundler
12
- - bundle install
13
- script: bundle exec rake
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'march_hare'
4
-
5
- class Freddy
6
- module Adapters
7
- class MarchHareAdapter
8
- def self.connect(config)
9
- hare = MarchHare.connect(config)
10
- new(hare)
11
- end
12
-
13
- def initialize(hare)
14
- @hare = hare
15
- end
16
-
17
- def create_channel(prefetch: nil)
18
- hare_channel = @hare.create_channel
19
- hare_channel.basic_qos(prefetch) if prefetch
20
- Channel.new(hare_channel)
21
- end
22
-
23
- def close
24
- @hare.close
25
- end
26
-
27
- class Channel
28
- extend Forwardable
29
-
30
- NO_ROUTE = 312
31
-
32
- def initialize(channel)
33
- @channel = channel
34
- end
35
-
36
- def_delegators :@channel, :topic, :default_exchange, :consumers, :acknowledge
37
-
38
- def queue(*args)
39
- Queue.new(@channel.queue(*args))
40
- end
41
-
42
- def on_no_route
43
- @channel.on_return do |reply_code, _, exchange_name, _, properties|
44
- if exchange_name != Freddy::FREDDY_TOPIC_EXCHANGE_NAME && reply_code == NO_ROUTE
45
- yield(properties.correlation_id)
46
- end
47
- end
48
- end
49
- end
50
-
51
- class Queue < Shared::Queue
52
- def subscribe(manual_ack: false)
53
- @queue.subscribe(manual_ack: manual_ack) do |meta, payload|
54
- parsed_payload = Payload.parse(payload)
55
- delivery = Delivery.new(
56
- parsed_payload, meta, meta.routing_key, meta.delivery_tag
57
- )
58
- yield(delivery)
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end