freddy 1.7.0 → 2.2.1

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: b7b2906e383a27fec45165c162d2a0a7a3a299dfdf390c599cf42288d75e5f3e
4
- data.tar.gz: 882a6d64838f723c43c58189cd0b9786df758bdd357ea23dfcb2954c454fb92f
3
+ metadata.gz: 9c7e04742f9d67bcdce9f6bf6335d4ff12a1ac684a6059cffaeee00e44002426
4
+ data.tar.gz: 2bb02e320d0b0458a182105a82931f48681a27b4f995c789cd6e7a655f3b9251
5
5
  SHA512:
6
- metadata.gz: b0d5031e6308383f5905f40ecc817945be9dd6df1f0abc6be662867d8d5b39b6c57ed0615d56d26d46ddcfe9dc05b4bc2d7a86b8f46d89d5ed118963b0c36063
7
- data.tar.gz: 816406b89fb3fbac83fffd15b5d283755096675dc4f9095b041c585d950a47a11c46bb1ef1545747b08775c705531b7c383327d06bdba2175a96cb7bf6f3732b
6
+ metadata.gz: 3666fe665db677115174ae5d3d864cf3f67beccad3b5d7832be9497cece4296c516086b62af4c1b90514a67c69663dd56d9238ea02903880b6c9b8fb0fa26859
7
+ data.tar.gz: 14578870d95999f972b7638f0ad5a6d80ea3d326a0d1f565ea6a673bb9f9133a316b00f11506fec3ec6d13db94d157cbd70aea1023f20664d4532365dd3d8982
@@ -0,0 +1,31 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.6']
15
+ services:
16
+ rabbitmq:
17
+ image: rabbitmq
18
+ ports:
19
+ - 5672:5672
20
+ options: --health-cmd "rabbitmqctl node_health_check" --health-interval 10s --health-timeout 5s --health-retries 5
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ with:
24
+ submodules: true
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true
30
+ - name: Run lint & tests
31
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,39 +1,23 @@
1
- require: rubocop-rspec
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
2
4
 
3
- Metrics/AbcSize:
4
- Enabled: no
5
-
6
- Metrics/BlockLength:
7
- Enabled: no
8
-
9
- Metrics/LineLength:
5
+ Layout/LineLength:
10
6
  Max: 120
11
7
 
12
- Metrics/MethodLength:
13
- Enabled: no
14
-
15
- Style/Documentation:
16
- Enabled: no
17
-
18
- RSpec/ExampleLength:
19
- Enabled: no
20
-
21
- RSpec/MultipleExpectations:
8
+ Lint/EmptyBlock:
22
9
  Enabled: no
23
10
 
24
- RSpec/MessageSpies:
25
- Enabled: no
26
-
27
- RSpec/VerifiedDoubles:
11
+ Metrics/AbcSize:
28
12
  Enabled: no
29
13
 
30
- RSpec/InstanceVariable:
14
+ Metrics/BlockLength:
31
15
  Enabled: no
32
16
 
33
- RSpec/NestedGroups:
17
+ Metrics/MethodLength:
34
18
  Enabled: no
35
19
 
36
- RSpec/DescribeClass:
20
+ Style/Documentation:
37
21
  Enabled: no
38
22
 
39
23
  Style/FrozenStringLiteralComment:
@@ -42,8 +26,5 @@ Style/FrozenStringLiteralComment:
42
26
  Include:
43
27
  - 'lib/**/*'
44
28
 
45
- Performance/TimesMap:
46
- Enabled: no
47
-
48
29
  Naming/FileName:
49
30
  Enabled: no
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- sm-messaging
1
+ freddy
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4
1
+ 2.6
data/Gemfile CHANGED
@@ -1,11 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'codeclimate-test-reporter'
4
3
  gem 'hamster', '~> 3.0'
5
- gem 'opentracing_test_tracer', '~> 0.1'
4
+ gem 'opentelemetry-sdk', '~> 1.0.0.rc3'
6
5
  gem 'pry'
7
6
  gem 'rspec'
8
- gem 'rubocop', '~> 0.54.0'
9
- gem 'rubocop-rspec', '~> 1.24.0'
7
+ gem 'rubocop', '~> 1.19'
8
+ gem 'rubocop-rspec', '~> 2.4'
10
9
 
11
10
  gemspec
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Messaging API supporting acknowledgements and request-response
2
2
 
3
- [![Build Status](https://travis-ci.org/salemove/freddy.svg?branch=master)](https://travis-ci.org/salemove/freddy)
4
- [![Code Climate](https://codeclimate.com/github/salemove/freddy/badges/gpa.svg)](https://codeclimate.com/github/salemove/freddy)
5
- [![Test Coverage](https://codeclimate.com/github/salemove/freddy/badges/coverage.svg)](https://codeclimate.com/github/salemove/freddy/coverage)
3
+ [![Build Status](https://github.com/salemove/freddy/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/salemove/freddy/actions/workflows/ci.yml?query=branch%3Amaster)
6
4
 
7
5
  ## Setup
8
6
 
@@ -24,39 +22,60 @@ These message queues have been tested and are working with Freddy. Other queues
24
22
  ### Simple delivery
25
23
 
26
24
  #### Send and forget
25
+
27
26
  Sends a `message` to the given `destination`. If there is no consumer then the
28
27
  message stays in the queue until somebody consumes it.
28
+
29
29
  ```ruby
30
- freddy.deliver(destination, message)
30
+ freddy.deliver(destination, message)
31
31
  ```
32
32
 
33
33
  #### Expiring messages
34
+
34
35
  Sends a `message` to the given `destination`. If nobody consumes the message in
35
36
  `timeout` seconds then the message is discarded. This is useful for showing
36
37
  notifications that must happen in a certain timeframe but where we don't really
37
38
  care if it reached the destination or not.
39
+
38
40
  ```ruby
39
41
  freddy.deliver(destination, message, timeout: 5)
40
42
  ```
41
43
 
44
+ #### Compressed messages
45
+
46
+ Sends a `message` to the given `destination`. If `compress` is passed as an option parameter, it will compress the
47
+ payload according to the algorithm provided. Currently the `zlib` algorithm is implemented to compress the payload.
48
+ The message heading specify the `content-encoding` indicating the compression algorithm used.
49
+
50
+ ```ruby
51
+ freddy.deliver(destination, message, compress: 'zlib')
52
+ ```
53
+
42
54
  ### Request delivery
55
+
43
56
  #### Expiring messages
57
+
44
58
  Sends a `message` to the given `destination`. Has a default timeout of 3 and
45
59
  discards the message from the queue if a response hasn't been returned in that
46
60
  time.
61
+
47
62
  ```ruby
48
63
  response = freddy.deliver_with_response(destination, message)
49
64
  ```
50
65
 
51
66
  #### Persistant messages
67
+
52
68
  Sends a `message` to the given `destination`. Keeps the message in the queue if
53
69
  a timeout occurs.
70
+
54
71
  ```ruby
55
72
  response = freddy.deliver_with_response(destination, message, timeout: 4, delete_on_timeout: false)
56
73
  ```
57
74
 
58
75
  #### Errors
76
+
59
77
  `deliver_with_response` raises an error if an error is returned. This can be handled by rescuing from `Freddy::InvalidRequestError` and `Freddy::TimeoutError` as:
78
+
60
79
  ```ruby
61
80
  begin
62
81
  response = freddy.deliver_with_response 'Q', {}
@@ -68,6 +87,7 @@ rescue Freddy::TimeoutError => e
68
87
  ```
69
88
 
70
89
  ## Responding to messages
90
+
71
91
  ```ruby
72
92
  freddy.respond_to destination do |message, msg_handler|
73
93
  # ...
@@ -75,8 +95,9 @@ end
75
95
  ```
76
96
 
77
97
  The callback is called with 2 arguments
78
- * the parsed message (note that in the message all keys are symbolized)
79
- * the `MessageHandler` (described further down)
98
+
99
+ * the parsed message (note that in the message all keys are symbolized)
100
+ * the `MessageHandler` (described further down)
80
101
 
81
102
  ## The MessageHandler
82
103
 
@@ -84,17 +105,20 @@ When responding to messages the MessageHandler is given as the second argument.
84
105
 
85
106
  The following operations are supported:
86
107
 
87
- * responding with a successful response
108
+ * responding with a successful response
109
+
88
110
  ```ruby
89
111
  msg_handler.success(response = nil)
90
112
  ```
91
113
 
92
- * responding with an error response
114
+ * responding with an error response
115
+
93
116
  ```ruby
94
117
  msg_handler.error(error: "Couldn't process message")
95
118
  ```
96
119
 
97
120
  ## Tapping into messages
121
+
98
122
  When it's necessary to receive messages but not consume them, consider tapping.
99
123
 
100
124
  ```ruby
@@ -134,37 +158,34 @@ end
134
158
  ## The ResponderHandler
135
159
 
136
160
  When responding to a message or tapping the ResponderHandler is returned.
161
+
137
162
  ```ruby
138
163
  responder_handler = freddy.respond_to ....
139
164
  ```
140
165
 
141
166
  The following operations are supported:
142
167
 
143
- * stop responding
168
+ * stop responding
169
+
144
170
  ```ruby
145
171
  responder_handler.shutdown
146
172
  ```
147
173
 
148
174
  ## Request Tracing
149
175
 
150
- Freddy supports [OpenTracing API|https://github.com/opentracing/opentracing-ruby]. You must set a global tracer which then freddy will use:
151
- ```ruby
152
- OpenTracing.global_tracing = MyTracerImplementation.new(...)
153
- ```
176
+ Freddy supports [OpenTelemetry API|https://github.com/open-telemetry/opentelemetry-ruby].
177
+ The trace information is automatically passed through `deliver`,
178
+ `deliver_with_response`, `respond_to` and `tap_into` calls.
154
179
 
155
- Current trace can be accessed through a thread-local variable `OpenTracing.active_span`. Calling `deliver` or `deliver_with_response` will pass trace context to down-stream services.
156
-
157
- See [opentracing-ruby](https://github.com/opentracing/opentracing-ruby) for more information.
180
+ This is not compatible with `opentelemetry-instrumentation-bunny` library.
158
181
 
159
182
  ## Notes about concurrency
160
183
 
161
184
  *freddy* uses a thread pool to run concurrent responders. The thread pool is unique for each *tap_into* and *respond_to* responder. Thread pool size can be configured by passing the configuration option *max_concurrency*. Its default value is 4. e.g. If your application has 2 *respond_to* responders and 1 *tap_into* responder with *max_concurrency* set to 3 then your application may process up to 9 messages in parallel.
162
185
 
163
-
164
186
  Note that while it is possible to use *deliver_with_response* inside a *respond_to* block,
165
187
  it is not possible to use another *respond_to* block inside a different *respond_to* block.
166
188
 
167
-
168
189
  Note also that other configuration options for freddy users
169
190
  such as pool sizes for DB connections need to match or exceed *max_concurrency*
170
191
  to avoid running out of resources.
data/freddy.gemspec CHANGED
@@ -1,19 +1,17 @@
1
-
2
1
  lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'freddy/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = if RUBY_PLATFORM == 'java'
7
- 'freddy-jruby'
8
- else
9
- 'freddy'
10
- end
11
- spec.version = '1.7.0'
6
+ spec.name = 'freddy'
7
+ spec.version = Freddy::VERSION
12
8
  spec.authors = ['Glia TechMovers']
13
9
  spec.email = ['techmovers@salemove.com']
14
10
  spec.description = 'Messaging API'
15
11
  spec.summary = 'API for inter-application messaging supporting acknowledgements and request-response'
16
- spec.license = 'Private'
12
+ spec.license = 'MIT'
13
+ spec.homepage = 'https://github.com/salemove/freddy'
14
+ spec.required_ruby_version = '>= 2.6'
17
15
 
18
16
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -23,14 +21,10 @@ Gem::Specification.new do |spec|
23
21
  spec.add_development_dependency 'bundler'
24
22
  spec.add_development_dependency 'rake'
25
23
 
26
- if RUBY_PLATFORM == 'java'
27
- spec.add_dependency 'march_hare', '~> 2.12.0'
28
- spec.add_dependency 'symbolizer'
29
- else
30
- spec.add_dependency 'bunny', '~> 2.11'
31
- spec.add_dependency 'oj', '~> 3.6'
32
- end
33
-
34
- spec.add_dependency 'opentracing', '~> 0.4'
24
+ spec.add_dependency 'bunny', '~> 2.11'
25
+ spec.add_dependency 'oj', '~> 3.6'
26
+ spec.add_dependency 'opentelemetry-api', '~> 1.0.0.rc3'
27
+ spec.add_dependency 'opentelemetry-semantic_conventions', '~> 1.0'
35
28
  spec.add_dependency 'thread', '~> 0.1'
29
+ spec.add_dependency 'zlib', '~> 1.1'
36
30
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bunny'
4
+ require 'forwardable'
4
5
 
5
6
  class Freddy
6
7
  module Adapters
@@ -47,12 +48,29 @@ class Freddy
47
48
  end
48
49
  end
49
50
 
50
- class Queue < Shared::Queue
51
+ class Queue
52
+ def initialize(queue)
53
+ @queue = queue
54
+ end
55
+
56
+ def bind(*args)
57
+ @queue.bind(*args)
58
+ self
59
+ end
60
+
61
+ def name
62
+ @queue.name
63
+ end
64
+
65
+ def message_count
66
+ @queue.message_count
67
+ end
68
+
51
69
  def subscribe(manual_ack: false)
52
70
  @queue.subscribe(manual_ack: manual_ack) do |info, properties, payload|
53
- parsed_payload = Payload.parse(payload)
71
+ parsed_payload = Payload.parse(payload, properties[:content_encoding])
54
72
  delivery = Delivery.new(
55
- parsed_payload, properties, info.routing_key, info.delivery_tag
73
+ parsed_payload, properties, info.routing_key, info.delivery_tag, info.exchange
56
74
  )
57
75
  yield(delivery)
58
76
  end
@@ -1,36 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'adapters/bunny_adapter'
4
+
3
5
  class Freddy
4
6
  module Adapters
5
7
  def self.determine
6
- if RUBY_PLATFORM == 'java'
7
- require_relative 'adapters/march_hare_adapter'
8
- MarchHareAdapter
9
- else
10
- require_relative 'adapters/bunny_adapter'
11
- BunnyAdapter
12
- end
13
- end
14
-
15
- module Shared
16
- class Queue
17
- def initialize(queue)
18
- @queue = queue
19
- end
20
-
21
- def bind(*args)
22
- @queue.bind(*args)
23
- self
24
- end
25
-
26
- def name
27
- @queue.name
28
- end
29
-
30
- def message_count
31
- @queue.message_count
32
- end
33
- end
8
+ BunnyAdapter
34
9
  end
35
10
  end
36
11
  end
@@ -35,21 +35,11 @@ class Freddy
35
35
 
36
36
  def process_message(delivery)
37
37
  @consume_thread_pool.process do
38
- begin
39
- scope = delivery.build_trace("freddy:respond:#{@destination}",
40
- tags: {
41
- 'peer.address' => "#{@destination}:#{delivery.payload[:type]}",
42
- 'component' => 'freddy',
43
- 'span.kind' => 'server', # RPC
44
- 'message_bus.destination' => @destination,
45
- 'message_bus.correlation_id' => delivery.correlation_id
46
- })
47
-
38
+ delivery.in_span do
48
39
  yield(delivery)
49
- ensure
50
- @channel.acknowledge(delivery.tag, false)
51
- scope.close
52
40
  end
41
+ ensure
42
+ @channel.acknowledge(delivery.tag, false)
53
43
  end
54
44
  end
55
45
  end
@@ -7,11 +7,9 @@ class Freddy
7
7
  @logger = logger
8
8
  end
9
9
 
10
- def consume(_channel, queue)
10
+ def consume(_channel, queue, &block)
11
11
  @logger.debug "Consuming messages on #{queue.name}"
12
- queue.subscribe do |delivery|
13
- yield(delivery)
14
- end
12
+ queue.subscribe(&block)
15
13
  end
16
14
  end
17
15
  end