ElmerFudd 0.1.0 → 0.1.2
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 +4 -4
- data/lib/ElmerFudd.rb +2 -0
- data/lib/ElmerFudd/direct_handler.rb +8 -0
- data/lib/ElmerFudd/json_filter.rb +5 -0
- data/lib/ElmerFudd/json_publisher.rb +8 -6
- data/lib/ElmerFudd/publisher.rb +6 -4
- data/lib/ElmerFudd/rpc_handler.rb +3 -1
- data/lib/ElmerFudd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c77507d5550d32879e421a33c9c667eceed1bb5
|
4
|
+
data.tar.gz: 7016a77b2fd57fd16f022fd27867e2d68543f93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e12979ea5778ac402d96698f5d5b73b116fabfc6c840a6ada53efdd2bfd8fed60283abd24a2de0d6c48b2516c897e1d360f93bf581c53cc05dea2a762298a2
|
7
|
+
data.tar.gz: 7cfede537d36e38d866ca688d8c987327ccaf5765bf859e2078e68f69a732e5af8f7b5d7faa0282c3d9bfe7bd018522522852412e239ae533ec7efb123bf0ae7
|
data/lib/ElmerFudd.rb
CHANGED
@@ -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
|
-
|
4
|
-
|
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
|
data/lib/ElmerFudd/publisher.rb
CHANGED
@@ -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,
|
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,
|
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
|
data/lib/ElmerFudd/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bunny
|