freddy 0.4.3 → 0.4.4

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: f1b843578b576679503e114c5e6bda050cd980eb
4
- data.tar.gz: af256b6384fca7e9ee13fd4d9a5f8b3301a96d0d
3
+ metadata.gz: 2ecb2f4ec6c6f60c98794bf27eb96435bf6ff6c5
4
+ data.tar.gz: c9e9d05eb2b43589c85d38610778b861498c6446
5
5
  SHA512:
6
- metadata.gz: 3b3768d47cf8a14f2743ca9e391458cba6968165e6fc29e8f1112f6bd093dff34bb933e76155baa95711fcbc8da4a6b734cf982a094fe63ba50566a06683d196
7
- data.tar.gz: 225aca279255a4f0d9643100f48ecc32b817f55b43fb16a120cf7fdf2b32c8b5bd0f649c9c333e0e38c1815de1c7d01b6159588413ce10099a224cf1c9289c9c
6
+ metadata.gz: bf8de81be9694937033dc1fba0013319093c96fc09a07792f6185b9164a5ebcb6bd399d82eb031efdcdd949015fa8e14735e1ac96e161e3cc2fb4edd8d67a53b
7
+ data.tar.gz: 6547d13beb561b67f21967299a4d6c9f9a67768cccf1f1b15da13a5d042933f171c8ab043df17dc846785229816ebadb45dab0f0b8162ebf18933cd15de970b3
data/README.md CHANGED
@@ -12,6 +12,12 @@ logger = Logger.new(STDOUT)
12
12
  freddy = Freddy.build(logger, host: 'localhost', port: 5672, user: 'guest', pass: 'guest')
13
13
  ```
14
14
 
15
+ ## Supported message queues
16
+
17
+ These message queues have been tested and are working with Freddy. Other queues can be added easily:
18
+
19
+ * [RabbitMQ](https://www.rabbitmq.com/)
20
+
15
21
  ## Delivering messages
16
22
 
17
23
  ### Simple delivery
data/freddy.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  else
9
9
  spec.name = "freddy"
10
10
  end
11
- spec.version = '0.4.3'
11
+ spec.version = '0.4.4'
12
12
  spec.authors = ["Urmas Talimaa"]
13
13
  spec.email = ["urmas.talimaa@gmail.com"]
14
14
  spec.description = %q{Messaging API}
@@ -25,11 +25,12 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  if RUBY_PLATFORM == 'java'
27
27
  spec.add_dependency 'march_hare', '~> 2.12.0'
28
+ spec.add_dependency 'symbolizer'
28
29
  else
29
30
  spec.add_dependency "bunny", "2.2.0"
31
+ spec.add_dependency "oj", "~> 2.13"
30
32
  end
31
33
 
32
- spec.add_dependency "symbolizer"
33
34
  spec.add_dependency "hamster", "~> 1.0.1.pre.rc3"
34
35
  spec.add_dependency "thread", "~> 0.2"
35
36
  end
@@ -33,7 +33,7 @@ class Freddy
33
33
  queue = create_queue('', exclusive: true).bind(@topic_exchange, routing_key: pattern)
34
34
  consumer = queue.subscribe do |payload, delivery|
35
35
  @consume_thread_pool.process do
36
- block.call parse_payload(payload), delivery.routing_key
36
+ block.call Payload.parse(payload), delivery.routing_key
37
37
  end
38
38
  end
39
39
  @logger.debug "Tapping into messages that match #{pattern}"
@@ -45,7 +45,7 @@ class Freddy
45
45
  def consume_using_pool(queue, options, pool, &block)
46
46
  consumer = queue.subscribe do |payload, delivery|
47
47
  pool.process do
48
- parsed_payload = parse_payload(payload)
48
+ parsed_payload = Payload.parse(payload)
49
49
  log_receive_event(queue.name, parsed_payload, delivery.correlation_id)
50
50
  block.call parsed_payload, delivery
51
51
  end
@@ -54,14 +54,6 @@ class Freddy
54
54
  ResponderHandler.new consumer, @channel
55
55
  end
56
56
 
57
- def parse_payload(payload)
58
- if payload == 'null'
59
- {}
60
- else
61
- Symbolizer.symbolize(JSON(payload))
62
- end
63
- end
64
-
65
57
  def create_queue(destination, options={})
66
58
  AdaptiveQueue.new(@channel.queue(destination, options))
67
59
  end
@@ -0,0 +1,46 @@
1
+ begin
2
+ require 'oj'
3
+ rescue LoadError
4
+ require 'symbolizer'
5
+ require 'json'
6
+ end
7
+
8
+ class Freddy
9
+ class Payload
10
+ def self.parse(payload)
11
+ return {} if payload == 'null'
12
+
13
+ json_handler.parse(payload)
14
+ end
15
+
16
+ def self.dump(payload)
17
+ json_handler.dump(payload)
18
+ end
19
+
20
+ def self.json_handler
21
+ @_json_handler ||= defined?(Oj) ? OjAdapter : JsonAdapter
22
+ end
23
+
24
+ class OjAdapter
25
+ def self.parse(payload)
26
+ Oj.load(payload, symbol_keys: true)
27
+ end
28
+
29
+ def self.dump(payload)
30
+ Oj.dump(payload, mode: :compat)
31
+ end
32
+ end
33
+
34
+ class JsonAdapter
35
+ def self.parse(payload)
36
+ # MRI has :symbolize_keys, but JRuby does not. Not adding it at the
37
+ # moment.
38
+ Symbolizer.symbolize(JSON.parse(payload))
39
+ end
40
+
41
+ def self.dump(payload)
42
+ JSON.dump(payload)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -17,7 +17,7 @@ class Freddy
17
17
  @logger.debug "Producing message #{payload.inspect} to #{destination}"
18
18
 
19
19
  properties = properties.merge(routing_key: destination, content_type: CONTENT_TYPE)
20
- json_payload = payload.to_json
20
+ json_payload = Payload.dump(payload)
21
21
 
22
22
  @topic_exchange.publish json_payload, properties.dup
23
23
  @exchange.publish json_payload, properties.dup
data/lib/freddy.rb CHANGED
@@ -5,13 +5,13 @@ else
5
5
  end
6
6
 
7
7
  require 'json'
8
- require 'symbolizer'
9
8
  require 'thread/pool'
10
9
 
11
10
  require_relative 'freddy/adaptive_queue'
12
11
  require_relative 'freddy/consumer'
13
12
  require_relative 'freddy/producer'
14
13
  require_relative 'freddy/request'
14
+ require_relative 'freddy/payload'
15
15
 
16
16
  class Freddy
17
17
  class ErrorResponse < StandardError
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urmas Talimaa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.2.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: symbolizer
56
+ name: oj
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.13'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '2.13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hamster
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +118,7 @@ files:
118
118
  - lib/freddy/delivery.rb
119
119
  - lib/freddy/message_handler.rb
120
120
  - lib/freddy/message_handlers.rb
121
+ - lib/freddy/payload.rb
121
122
  - lib/freddy/producer.rb
122
123
  - lib/freddy/request.rb
123
124
  - lib/freddy/request_manager.rb