carrot_rpc 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: 4ba255fb6d2e277988ef84326c30193fe9dc0ca7
4
- data.tar.gz: 7c8a26c482a1041887f7ac73eb5bd9396966a3fe
3
+ metadata.gz: 7e96c407c46a0ad19683945d17d3994632ff201b
4
+ data.tar.gz: bdfc99b0940899499998b799974a9ec9b025cd47
5
5
  SHA512:
6
- metadata.gz: ca9b37d0788166fe678d7281cfeac3846f662370b6a5ac6de02fc3567df59ddce010999f61555603ba7c0170f338ee5f32a9d70e7e7f71f2bc86e0cac7bf358b
7
- data.tar.gz: 71d2becd5fa8dab667c8b82c3e98e194c29cd46ab95d1997304597aa929741cb2a7287fdb936d46d991c160e06642fde18b504953c868e628329a71fb8d9ad7e
6
+ metadata.gz: 86f4f8e38c488b1ece54d10ba3ad5a8cd97db8d39103d99801d6b44849da75531fdc448ba5ab968068cc65751179734e3bd723b45d9c721e1d4c927ac17f7aa0
7
+ data.tar.gz: 9f334bc0fd7b57c9155936a2ac5f5894291fad40ac1ca538509147ae41edc5502fb376a310d10fad8f8fde8c214f46c6c6fac9ed2b967b61ca8b3bc05db053f6
data/CHANGELOG.md CHANGED
@@ -3,49 +3,52 @@
3
3
  **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4
4
 
5
5
  - [Changelog](#changelog)
6
+ - [v1.1.0](#v110)
7
+ - [Enhancements](#enhancements)
8
+ - [Bug Fixes](#bug-fixes)
6
9
  - [v1.0.0](#v100)
7
10
  - [Incompatible Changes](#incompatible-changes)
8
11
  - [v0.8.1](#v081)
9
- - [Enhancements](#enhancements)
10
- - [v0.8.0](#v080)
11
12
  - [Enhancements](#enhancements-1)
13
+ - [v0.8.0](#v080)
14
+ - [Enhancements](#enhancements-2)
12
15
  - [v0.7.1](#v071)
13
- - [Bug Fixes](#bug-fixes)
14
- - [v0.7.0](#v070)
15
16
  - [Bug Fixes](#bug-fixes-1)
17
+ - [v0.7.0](#v070)
18
+ - [Bug Fixes](#bug-fixes-2)
16
19
  - [Incompatible Changes](#incompatible-changes-1)
17
20
  - [v0.6.0](#v060)
18
- - [Enhancements](#enhancements-2)
21
+ - [Enhancements](#enhancements-3)
19
22
  - [v0.5.1](#v051)
20
- - [Bug Fixes](#bug-fixes-2)
23
+ - [Bug Fixes](#bug-fixes-3)
21
24
  - [v0.5.0](#v050)
22
- - [Enhancements](#enhancements-3)
25
+ - [Enhancements](#enhancements-4)
23
26
  - [Incompatible Changes](#incompatible-changes-2)
24
27
  - [v0.4.1](#v041)
25
- - [Bug Fixes](#bug-fixes-3)
26
- - [v0.4.0](#v040)
27
- - [Enhancements](#enhancements-4)
28
28
  - [Bug Fixes](#bug-fixes-4)
29
- - [Incompatible Changes](#incompatible-changes-3)
30
- - [v0.3.0](#v030)
29
+ - [v0.4.0](#v040)
31
30
  - [Enhancements](#enhancements-5)
32
31
  - [Bug Fixes](#bug-fixes-5)
33
- - [v0.2.3](#v023)
32
+ - [Incompatible Changes](#incompatible-changes-3)
33
+ - [v0.3.0](#v030)
34
34
  - [Enhancements](#enhancements-6)
35
35
  - [Bug Fixes](#bug-fixes-6)
36
+ - [v0.2.3](#v023)
37
+ - [Enhancements](#enhancements-7)
38
+ - [Bug Fixes](#bug-fixes-7)
36
39
  - [Upgrading](#upgrading)
37
40
  - [v0.2.1](#v021)
38
- - [Bug Fixes](#bug-fixes-7)
39
- - [v0.2.0](#v020)
40
- - [Enhancements](#enhancements-7)
41
41
  - [Bug Fixes](#bug-fixes-8)
42
- - [Incompatible Changes](#incompatible-changes-4)
43
- - [v0.1.2](#v012)
42
+ - [v0.2.0](#v020)
44
43
  - [Enhancements](#enhancements-8)
45
44
  - [Bug Fixes](#bug-fixes-9)
46
- - [v0.1.1](#v011)
45
+ - [Incompatible Changes](#incompatible-changes-4)
46
+ - [v0.1.2](#v012)
47
47
  - [Enhancements](#enhancements-9)
48
48
  - [Bug Fixes](#bug-fixes-10)
49
+ - [v0.1.1](#v011)
50
+ - [Enhancements](#enhancements-10)
51
+ - [Bug Fixes](#bug-fixes-11)
49
52
  - [Incompatible Changes](#incompatible-changes-5)
50
53
 
51
54
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -53,6 +56,22 @@
53
56
  # Changelog
54
57
  All significant changes in the project are documented here.
55
58
 
59
+ ## v1.1.0
60
+
61
+ ### Enhancements
62
+ * [#55](https://github.com/C-S-D/carrot_rpc/pull/55) - [@shamil614](https://github.com/shamil614)
63
+ * `ActiveSupport::Notifications` to enable universal metrics gathering
64
+ * `client.SERVER_QUEUE.remote_call` will include `correlation_id` of request
65
+ * `server.SERVER_QUEUE.consume` will include `correlation_id` of request
66
+ * [#56](https://github.com/C-S-D/carrot_rpc/pull/56) - [@KronicDeth](https://gitub.com/KronicDeth)
67
+ * Match client log tags to server log tags.
68
+ * Client tags will start with `client` as server tags start with `server`.
69
+ * When available, it will have `server_queue=SERVER_QUEUE_NAME`.
70
+ * Finally, it will always have `correlation_id=CORRELATION_ID`.
71
+
72
+ ### Bug Fixes
73
+ * [#56](https://github.com/C-S-D/carrot_rpc/pull/56) - `client.SERVER_QUEUE_NAME.remote_call` `ActiveSupport::Notification` was using the server queue object instead of name, so it interpolated as `#<...>`. - [@KronicDeth](https://gitub.com/KronicDeth)
74
+
56
75
  ## v1.0.0
57
76
  ### Incompatible Changes
58
77
  * [#48](https://github.com/C-S-D/carrot_rpc/pull/48) - Remove queue for correlation_id when RpcClient#wait_for_result raises an exception. -[@nward](https://github.com/nward)
data/lib/carrot_rpc.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require "active_support/core_ext/hash/indifferent_access"
3
3
  require "active_support/core_ext/hash/except"
4
4
  require "active_support/dependencies/autoload"
5
+ require "active_support/notifications"
5
6
  require "bunny"
6
7
 
7
8
  # standard library
@@ -70,16 +70,26 @@ class CarrotRpc::RpcClient
70
70
  # @param remote_method [String, Symbol] the method to be called on current receiver
71
71
  # @param params [Hash] the arguments for the method being called.
72
72
  # @return [Object] the result of the method call.
73
+ #
74
+ # rubocop:disable Metrics/AbcSize
75
+ # rubocop:disable Metrics/MethodLength
73
76
  def remote_call(remote_method, params)
74
77
  start
75
78
  subscribe
79
+ server_queue_name = server_queue.name
76
80
  correlation_id = SecureRandom.uuid
77
- logger.with_correlation_id(correlation_id) do
78
- params = self.class.before_request.call(params) if self.class.before_request
79
- publish(correlation_id: correlation_id, method: remote_method, params: request_key_formatter(params))
80
- wait_for_result(correlation_id)
81
- end
81
+ extra = { correlation_id: correlation_id }
82
+
83
+ ActiveSupport::Notifications.instrument("client.#{server_queue_name}.remote_call", extra: extra) {
84
+ logger.tagged("client", "server_queue=#{server_queue_name}", "correlation_id=#{correlation_id}") {
85
+ params = self.class.before_request.call(params) if self.class.before_request
86
+ publish(correlation_id: correlation_id, method: remote_method, params: request_key_formatter(params))
87
+ wait_for_result(correlation_id)
88
+ }
89
+ }
82
90
  end
91
+ # rubocop:enable Metrics/AbcSize
92
+ # rubocop:enable Metrics/MethodLength
83
93
 
84
94
  def wait_for_result(correlation_id)
85
95
  # Should be good to timeout here because we're blocking in the main thread here.
@@ -138,15 +148,17 @@ class CarrotRpc::RpcClient
138
148
  private
139
149
 
140
150
  def consume(_delivery_info, properties, payload)
141
- logger.with_correlation_id(properties[:correlation_id]) do
151
+ correlation_id = properties[:correlation_id]
152
+
153
+ logger.tagged("client", "correlation_id=#{correlation_id}") {
142
154
  logger.debug "Receiving response: #{payload}"
143
155
 
144
156
  response = JSON.parse(payload).with_indifferent_access
145
157
 
146
158
  result = parse_response(response)
147
159
  result = response_key_formatter(result).with_indifferent_access if result.is_a? Hash
148
- @results[properties[:correlation_id]].push(result)
149
- end
160
+ @results[correlation_id].push(result)
161
+ }
150
162
  end
151
163
 
152
164
  # Logic to find the data from the RPC response.
@@ -59,19 +59,25 @@ class CarrotRpc::RpcServer
59
59
  request_message: request_message
60
60
  end
61
61
 
62
- def consume(_delivery_info, properties, payload)
63
- logger.tagged("server", "queue=#{server_queue.name}", "correlation_id=#{properties[:correlation_id]}") do
64
- logger.debug "Receiving request: #{payload}"
65
-
66
- # rubocop:disable Lint/RescueException
67
- begin
68
- request_message = JSON.parse(payload).with_indifferent_access
69
-
70
- process_request(request_message, properties: properties)
71
- rescue Exception => exception
72
- logger.error(exception)
62
+ def consume(_delivery_info, properties, payload) # rubocop:disable Metrics/MethodLength
63
+ queue_name = server_queue.name
64
+ correlation_id = properties[:correlation_id]
65
+ extra = { correlation_id: correlation_id }
66
+
67
+ ActiveSupport::Notifications.instrument("server.#{queue_name}.consume", extra: extra) do
68
+ logger.tagged("server", "queue=#{queue_name}", "correlation_id=#{correlation_id}") do
69
+ logger.debug "Receiving request: #{payload}"
70
+
71
+ # rubocop:disable Lint/RescueException
72
+ begin
73
+ request_message = JSON.parse(payload).with_indifferent_access
74
+
75
+ process_request(request_message, properties: properties)
76
+ rescue Exception => exception
77
+ logger.error(exception)
78
+ end
79
+ # rubocop:enable Lint/RescueException
73
80
  end
74
- # rubocop:enable Lint/RescueException
75
81
  end
76
82
  end
77
83
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module CarrotRpc
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrot_rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Hamilton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-16 00:00:00.000000000 Z
12
+ date: 2017-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  requirements: []
203
203
  rubyforge_project:
204
- rubygems_version: 2.4.8
204
+ rubygems_version: 2.6.11
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: Remote Procedure Call (RPC) using the Bunny Gem over RabbitMQ