vx-common-amqp 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78c7ba1237547a68870877cf97e753e060e409a8
4
- data.tar.gz: b176e9a6819bca67fc9244da4fec6186ef6ca94e
3
+ metadata.gz: 16f3b92f0f5a953fcc9200b6704396461c8be8db
4
+ data.tar.gz: a411d13c2d1112634ccf107f7c00d334c098f9cc
5
5
  SHA512:
6
- metadata.gz: 5b71ffdcc44ec306ba4fdde80ae3f76df4cc708429a89651a7c7508f7dfb9439ea6280c426cc612a88dee7a04bd07e78ee0b69e1ec55c62b87c46deef5095816
7
- data.tar.gz: f3f3d0af052ef31fc59c39c12ee69453a5676c961c82814074fa8bd966d6c19dd50017a3e9c07c31ae586529d0a82ec277afa25648fee5f1b1b090662c6977c6
6
+ metadata.gz: b78866acd40c7871893af4e4bb058aeddacc32b7538f5c935ad0070e1cdd59e35ab96ca42eb34450711594ab92e68dd8f3fc23b5e8a5241993d5de4cd08f5002
7
+ data.tar.gz: e5d25fc001a9dfb0a20b9b2cbd56b9df593dfafb89700e96282b9fce6a18d46a9b50f015519cb15fefe2efa0963112dd8ea0b00cf8e05f7275554a6e89d407c1
@@ -1,4 +1,3 @@
1
- require 'logger'
2
1
  require 'vx/common/rack/builder'
3
2
 
4
3
  module Vx
@@ -7,8 +6,9 @@ module Vx
7
6
  class Config
8
7
 
9
8
  attr_accessor :default_exchange_options, :default_queue_options,
10
- :default_publish_options, :default_exchange_type, :logger, :pool_timeout,
11
- :heartbeat, :spawn_attempts, :content_type, :instrumenter, :debug, :on_error
9
+ :default_publish_options, :default_exchange_type, :pool_timeout,
10
+ :heartbeat, :spawn_attempts, :content_type, :instrumenter, :debug,
11
+ :on_error, :builder
12
12
 
13
13
  def initialize
14
14
  reset!
@@ -26,8 +26,11 @@ module Vx
26
26
  @debug || ENV['VX_COMMON_AMQP_DEBUG']
27
27
  end
28
28
 
29
+ def use(middleware, *args)
30
+ @builder.use middleware, *args
31
+ end
32
+
29
33
  def reset!
30
- @logger = ::Logger.new(STDOUT)
31
34
  @default_exchange_type = :topic
32
35
  @pool_timeout = 0.1
33
36
  @heartbeat = 10
@@ -44,6 +47,8 @@ module Vx
44
47
  @instrumenter = nil
45
48
  @on_error = ->(e, env){ nil }
46
49
 
50
+ @builder = Vx::Common::Rack::Builder.new
51
+
47
52
  @default_exchange_options = {
48
53
  durable: true,
49
54
  auto_delete: false
@@ -7,7 +7,7 @@ module Vx
7
7
  instrumentation = {
8
8
  consumer_id: self.class.consumer_id,
9
9
  consumer: self.class.consumer_name,
10
- message_id: properties[:message_id],
10
+ properties: properties,
11
11
  multiple: multiple,
12
12
  }
13
13
  self.class.session.channel.ack delivery_info.delivery_tag, multiple
@@ -18,7 +18,7 @@ module Vx
18
18
  instrumentation = {
19
19
  consumer_id: self.class.consumer_id,
20
20
  consumer: self.class.consumer_name,
21
- message_id: properties[:message_id],
21
+ properties: properties,
22
22
  multiple: multiple,
23
23
  requeue: requeue,
24
24
  }
@@ -21,7 +21,7 @@ module Vx
21
21
  exchange: x.name,
22
22
  consumer: consumer_name,
23
23
  consumer_id: consumer_id,
24
- message_id: options[:message_id]
24
+ properties: options,
25
25
  }
26
26
 
27
27
  instrument("process_publishing.consumer.amqp", instrumentation) do
@@ -64,10 +64,10 @@ module Vx
64
64
  consumer_id: consumer_id,
65
65
  consumer: consumer_name,
66
66
  payload: payload,
67
- message_id: properties[:message_id]
67
+ properties: properties,
68
68
  }
69
69
 
70
- Instrument.with request_id: uuid do
70
+ with_middlewares instrumentation do
71
71
  instrument("start_processing.consumer.amqp", instrumentation)
72
72
  instrument("process.consumer.amqp", instrumentation) do
73
73
  result = run_instance delivery_info, properties, payload, uuid
@@ -89,6 +89,10 @@ module Vx
89
89
  end.perform payload
90
90
  end
91
91
 
92
+ def with_middlewares(env, &block)
93
+ Common::AMQP.config.builder.to_app(block).call(env)
94
+ end
95
+
92
96
  def deserialize_message(properties, payload)
93
97
  Common::AMQP::Formatter.unpack(
94
98
  properties[:content_type],
@@ -3,20 +3,8 @@ module Vx
3
3
  module AMQP
4
4
  module Instrument
5
5
 
6
- def self.with(new_params)
7
- old_params = Thread.current["vx_common_amqp_instrument_with"]
8
- begin
9
- Thread.current["vx_common_amqp_instrument_with"] = new_params
10
- yield if block_given?
11
- ensure
12
- Thread.current["vx_common_amqp_instrument_with"] = old_params
13
- end
14
- end
15
-
16
6
  def instrument(name, payload, &block)
17
- append = Thread.current["vx_common_amqp_instrument_with"]
18
- append ||= {}
19
- Common::AMQP.instrument name, payload.merge(append), &block
7
+ Common::AMQP.instrument name, payload, &block
20
8
  end
21
9
 
22
10
  end
@@ -1,7 +1,7 @@
1
1
  module Vx
2
2
  module Common
3
3
  module AMQP
4
- VERSION = "0.3.4"
4
+ VERSION = "0.3.5"
5
5
  end
6
6
  end
7
7
  end
@@ -3,4 +3,16 @@ require 'spec_helper'
3
3
  describe Vx::Common::AMQP::Config do
4
4
  let(:config) { described_class.new }
5
5
 
6
+ it "should use builder" do
7
+ mid = Struct.new(:app) do
8
+ def call(env)
9
+ env.merge!(a: 1)
10
+ end
11
+ end
12
+
13
+ config.use mid
14
+ rs = config.builder.to_app(->(e) { e }).call({})
15
+ expect(rs).to eq(a: 1)
16
+ end
17
+
6
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-common-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny