protobuf-nats 0.3.0 → 0.3.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
  SHA1:
3
- metadata.gz: 28a6d2646c7aa30566ecf3042f164df413453b6f
4
- data.tar.gz: e0f1fc04823c3da16ec32eb8c17f49ae5d8a73c5
3
+ metadata.gz: 6d293e4b986f3f85b53bfa414a672e80b15c9ff3
4
+ data.tar.gz: e910a6511d0539b811948193466fa0e9789297b7
5
5
  SHA512:
6
- metadata.gz: 9fefcb0855bd3467316bcfff911585f09b57a93d93bd6eeca5fff07f15a64da5bf80939553a5650b33f2f2edf5654406c6790b251aa789ccef1a23f3b8d63571
7
- data.tar.gz: c4bb2859a7082516118805e5232b89218c668a813b03b7d936b972fc91cd948eb67dee10d77759904f934a91325030b5f7979eb9e1453df83d2b4913d3a01cc4
6
+ metadata.gz: 27ef6bb9f6c23dce96a92848545eef7309f953c3e424e89086fc1e6cf1841fca5f11b9cfb518b53fb7f40051a780cdbe89ee262cd1bfe03c92ab922043befe9d
7
+ data.tar.gz: 7316ec766c74fc63b2c5c3f09fd046bacb64a63333e5a36720476368ecd8dd58fcaf93a59eecb2ebc3f5aea2ab87c4ee42d514459228c8cf5f521696811f455d
data/README.md CHANGED
@@ -38,11 +38,13 @@ You can also use the following environment variables to tune parameters:
38
38
  ### YAML Config
39
39
 
40
40
  The client and server are configured via environment variables defined in the `pure-ruby-nats` gem. However, there are a
41
- few params which cannot be set: `servers`, `uses_tls` and `connect_timeout`, so those my be defined in a yml file.
41
+ few params which cannot be set: `servers`, `uses_tls`, `subscription_key_replacements`, and `connect_timeout`, so those my be defined in a yml file.
42
42
 
43
43
  The library will automatically look for a file with a relative path of `config/protobuf_nats.yml`, but you may override
44
44
  this by specifying a different file via the `PROTOBUF_NATS_CONFIG_PATH` env variable.
45
45
 
46
+ The `subscription_key_replacements` feature is something we have found useful for local testing, but it is subject to breaking changes.
47
+
46
48
  An example config looks like this:
47
49
  ```
48
50
  # Stored at config/protobuf_nats.yml
@@ -58,6 +60,8 @@ An example config looks like this:
58
60
  tls_client_key: "/path/to/client-key.pem"
59
61
  tls_ca_cert: "/path/to/ca.pem"
60
62
  connect_timeout: 2
63
+ subscription_key_replacements:
64
+ - "original_service": "replacement_service"
61
65
  ```
62
66
 
63
67
  ## Usage
data/lib/protobuf/nats.rb CHANGED
@@ -45,7 +45,9 @@ module Protobuf
45
45
  def self.subscription_key(service_klass, service_method)
46
46
  service_class_name = service_klass.name.underscore.gsub("/", ".")
47
47
  service_method_name = service_method.to_s.underscore
48
- "rpc.#{service_class_name}.#{service_method_name}"
48
+
49
+ subscription_key = "rpc.#{service_class_name}.#{service_method_name}"
50
+ subscription_key = config.make_subscription_key_replacements(subscription_key)
49
51
  end
50
52
 
51
53
  def self.start_client_nats_connection
@@ -4,7 +4,7 @@ require "yaml"
4
4
  module Protobuf
5
5
  module Nats
6
6
  class Config
7
- attr_accessor :uses_tls, :servers, :connect_timeout, :tls_client_cert, :tls_client_key, :tls_ca_cert, :max_reconnect_attempts
7
+ attr_accessor :uses_tls, :servers, :connect_timeout, :tls_client_cert, :tls_client_key, :tls_ca_cert, :max_reconnect_attempts, :subscription_key_replacements
8
8
 
9
9
  CONFIG_MUTEX = ::Mutex.new
10
10
 
@@ -16,6 +16,7 @@ module Protobuf
16
16
  :tls_client_key => nil,
17
17
  :tls_ca_cert => nil,
18
18
  :uses_tls => false,
19
+ :subscription_key_replacements => [],
19
20
  }.freeze
20
21
 
21
22
  def initialize
@@ -60,7 +61,8 @@ module Protobuf
60
61
  tls_client_cert: tls_client_cert,
61
62
  tls_client_key: tls_client_key,
62
63
  tls_ca_cert: tls_ca_cert,
63
- connect_timeout: connect_timeout
64
+ connect_timeout: connect_timeout,
65
+ subscription_key_replacements: subscription_key_replacements,
64
66
  }
65
67
  options[:tls] = {:context => new_tls_context} if uses_tls
66
68
  options
@@ -75,6 +77,18 @@ module Protobuf
75
77
  tls_context
76
78
  end
77
79
 
80
+ def make_subscription_key_replacements(subscription_key)
81
+ subscription_key_replacements.each do |replacement|
82
+ match = replacement.keys.first
83
+ replacement = replacement[match]
84
+
85
+ if subscription_key.include?(match)
86
+ return subscription_key.gsub(match, replacement)
87
+ end
88
+ end
89
+
90
+ subscription_key
91
+ end
78
92
  end
79
93
  end
80
94
  end
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module Nats
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-nats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: protobuf