ElmerFudd 0.1.0 → 0.1.2

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: 1f3b594d1565a291ef8f3ea7fd8974e7f5881710
4
- data.tar.gz: 4437ba2cf870d5a76cbee31dec91dcdc1e5541d0
3
+ metadata.gz: 5c77507d5550d32879e421a33c9c667eceed1bb5
4
+ data.tar.gz: 7016a77b2fd57fd16f022fd27867e2d68543f93c
5
5
  SHA512:
6
- metadata.gz: 8487db7dbd04a30b7cda67f0a923cf7f2edd1d1cfbc810409a33412bb6fbb9b999050abf791232a3716ec4fbc2aa8915acfcdcb5d63cc4c6838f507541879a6f
7
- data.tar.gz: 21f18bace52a65eaca2f72adc4b901b15f2c6d469fdb1879bcf0be1b1f7afcffc8282393d445c68ea3634276b57b1e0c7e6db02444d3b88409c24effea85b94a
6
+ metadata.gz: e5e12979ea5778ac402d96698f5d5b73b116fabfc6c840a6ada53efdd2bfd8fed60283abd24a2de0d6c48b2516c897e1d360f93bf581c53cc05dea2a762298a2
7
+ data.tar.gz: 7cfede537d36e38d866ca688d8c987327ccaf5765bf859e2078e68f69a732e5af8f7b5d7faa0282c3d9bfe7bd018522522852412e239ae533ec7efb123bf0ae7
@@ -4,6 +4,8 @@ require 'thread'
4
4
  require 'json'
5
5
 
6
6
  module ElmerFudd
7
+ DEFAULT_CONTENT_TYPE = Bunny::Channel::DEFAULT_CONTENT_TYPE
8
+
7
9
  require 'ElmerFudd/publisher'
8
10
  require 'ElmerFudd/json_publisher'
9
11
 
@@ -2,12 +2,15 @@ module ElmerFudd
2
2
  class DirectHandler
3
3
  include Filter
4
4
  attr_reader :route
5
+ attr_accessor :call_reply_content_type
5
6
 
6
7
  def initialize(route, callback, filters, options)
7
8
  @route = route
8
9
  @callback = callback
9
10
  @filters = filters
10
11
  @durable = options.fetch(:durable)
12
+ @call_reply_content_type = ElmerFudd::DEFAULT_CONTENT_TYPE
13
+ initialize_filters
11
14
  end
12
15
 
13
16
  def queue(env)
@@ -38,6 +41,11 @@ module ElmerFudd
38
41
 
39
42
  private
40
43
 
44
+ def initialize_filters
45
+ @filters.select { |filter| filter.respond_to?(:setup) }.
46
+ each { |filter| filter.setup(self) }
47
+ end
48
+
41
49
  def filters_names
42
50
  @filters.map { |f| f.respond_to?(:name) ? f.name : f.class.name }
43
51
  end
@@ -1,6 +1,11 @@
1
1
  module ElmerFudd
2
2
  class JsonFilter
3
3
  extend Filter
4
+
5
+ def self.setup(handler)
6
+ handler.call_reply_content_type = 'application/json'
7
+ end
8
+
4
9
  def self.call(env, message, filters)
5
10
  message.payload = JSON.parse(message.payload)
6
11
  {result: call_next(env, message, filters)}.to_json
@@ -1,15 +1,17 @@
1
1
  module ElmerFudd
2
2
  class JsonPublisher < Publisher
3
- def notify(topic_exchange, routing_key, payload)
4
- super(topic_exchange, routing_key, payload.to_json)
3
+ CONTENT_TYPE = 'application/json'
4
+
5
+ def notify(topic_exchange, routing_key, payload, content_type: CONTENT_TYPE)
6
+ super(topic_exchange, routing_key, payload.to_json, content_type: content_type)
5
7
  end
6
8
 
7
- def cast(queue_name, payload)
8
- super(queue_name, payload.to_json)
9
+ def cast(queue_name, payload, content_type: CONTENT_TYPE)
10
+ super(queue_name, payload.to_json, content_type: content_type)
9
11
  end
10
12
 
11
- def call(queue_name, payload, **kwargs)
12
- JSON.parse(super(queue_name, payload.to_json, **kwargs))
13
+ def call(queue_name, payload, content_type: CONTENT_TYPE, **kwargs)
14
+ JSON.parse(super(queue_name, payload.to_json, content_type: content_type, **kwargs))
13
15
  end
14
16
  end
15
17
  end
@@ -35,7 +35,7 @@ module ElmerFudd
35
35
  end
36
36
  end
37
37
 
38
- def notify(topic_exchange, routing_key, payload)
38
+ def notify(topic_exchange, routing_key, payload, content_type: ElmerFudd::DEFAULT_CONTENT_TYPE)
39
39
  @exchange.with do |exchange|
40
40
  @logger.debug "ElmerFudd: NOTIFY - topic_exchange: #{topic_exchange}, routing_key: #{routing_key}, payload: #{payload}"
41
41
  exchange.topic(topic_exchange).publish payload.to_s, routing_key: routing_key
@@ -43,7 +43,7 @@ module ElmerFudd
43
43
  nil
44
44
  end
45
45
 
46
- def cast(queue_name, payload)
46
+ def cast(queue_name, payload, content_type: ElmerFudd::DEFAULT_CONTENT_TYPE)
47
47
  @exchange.with do |exchange|
48
48
  @logger.debug "ElmerFudd: CAST - queue_name: #{queue_name}, payload: #{payload}"
49
49
  exchange.direct.publish(payload.to_s, routing_key: queue_name)
@@ -51,7 +51,7 @@ module ElmerFudd
51
51
  nil
52
52
  end
53
53
 
54
- def call(queue_name, payload, timeout: 10)
54
+ def call(queue_name, payload, timeout: 10, content_type: ElmerFudd::DEFAULT_CONTENT_TYPE)
55
55
  @exchange.with do |exchange|
56
56
  begin
57
57
  @logger.debug "ElmerFudd: CALL - queue_name: #{queue_name}, payload: #{payload}, timeout: #{timeout}"
@@ -69,7 +69,9 @@ module ElmerFudd
69
69
  end
70
70
  end
71
71
 
72
- exchange.direct.publish(payload.to_s, routing_key: queue_name, reply_to: exchange.rpc_reply_queue.name,
72
+ exchange.direct.publish(payload.to_s,
73
+ content_type: content_type,
74
+ routing_key: queue_name, reply_to: exchange.rpc_reply_queue.name,
73
75
  correlation_id: correlation_id)
74
76
 
75
77
  mutex.synchronize { resource.wait(mutex) unless response }
@@ -7,7 +7,9 @@ module ElmerFudd
7
7
  end
8
8
 
9
9
  def reply(env, original_message, response)
10
- exchange(env).publish(response.to_s, routing_key: original_message.properties.reply_to,
10
+ exchange(env).publish(response.to_s,
11
+ content_type: call_reply_content_type,
12
+ routing_key: original_message.properties.reply_to,
11
13
  correlation_id: original_message.properties.correlation_id)
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module ElmerFudd
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ElmerFudd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrzej Sliwa
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-08 00:00:00.000000000 Z
12
+ date: 2016-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny