carnivore-rabbitmq 0.2.0 → 0.2.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: 93bd64853af5442ac5ce62b73e1547c5690d630e
4
- data.tar.gz: 3d10ed4dec1940e1f7ff2fa8afb74ba3a669be8d
3
+ metadata.gz: fde297db3cabbe62377e3277ac644df69c218b48
4
+ data.tar.gz: 5dfaa10d669f69b1958ea7244c6b8ab771a5ae95
5
5
  SHA512:
6
- metadata.gz: b4ec13bef9a0ddf7bd965edb3a89d9db47131f0fcb5f9baaa49a70669fffb9d89b3ba76c0bb026811f5934bcbf492d13d1da2e41902b616d4582e47400c08b6d
7
- data.tar.gz: 66072c609c57ab533696ff69a86ba857938cf3515dbc1e4f1b3a2cb41dba92ac191619bd153ac03d722a9311a0dcbd37161cd0afaa5bf7a8608ee8fe63072956
6
+ metadata.gz: 16514a62fc24f878951914bbdd245425271fd5638b65ca931feea8ebdd40c74f1c0bfa7ca94e154dff737d9ac295afbcf70cc4b614a53236d36e86888fd87f31
7
+ data.tar.gz: 1196c52b20fff49f4284fcd380151a86074e5b63125fbdfa9ba7b001c3bd47307b5e1cbbc075250608aada1c29abc1820f29f3fc5490c1bb2971b48c2836429a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.2.2
2
+ * Transfer messages via internal signal
3
+ * Properly cleanup on termination
4
+ * Cache signals on source
5
+
1
6
  # v0.2.0
2
7
  * Update for latest carnivore
3
8
 
@@ -12,22 +12,28 @@ module Carnivore
12
12
 
13
13
  # @return [Bunny::Queue, MarchHare::Queue] remote queue
14
14
  attr_reader :queue
15
- # @return [Queue] local message bucket
16
- attr_reader :message_queue
17
15
  # @return [Celluloid::Actor] actor to notify
18
16
  attr_reader :notify
19
17
 
20
18
  # Create new instance
21
19
  #
22
20
  # @param queue [Bunny::Queue, MarchHare::Queue] remote queue
23
- # @param message_queue [Queue] local message bucket
24
- # @param notify [Celluloid::Actor] actor to notify
25
- def initialize(queue, message_queue, notify)
21
+ # @param notify [Zoidberg::Shell] actor to notify
22
+ def initialize(queue, notify)
26
23
  @queue = queue
27
- @message_queue = message_queue
28
24
  @notify = notify
29
25
  end
30
26
 
27
+ # Start message collection when restarted
28
+ def restarted
29
+ start!
30
+ end
31
+
32
+ # Start the collector
33
+ def start!
34
+ current_self.async.collect_messages
35
+ end
36
+
31
37
  # Collect messages from remote queue
32
38
  #
33
39
  # @return [TrueClass]
@@ -40,20 +46,20 @@ module Carnivore
40
46
  begin
41
47
  payload = MultiJson.load(payload).to_smash
42
48
  rescue MultiJson::ParseError
43
- warn 'Received payload not in JSON format. Failed to parse!'
49
+ debug 'Received payload not in JSON format. Failed to parse!'
44
50
  end
45
51
  debug "Message received: #{payload.inspect}"
46
52
  debug "Message info: #{info.inspect}"
47
53
  debug "Message metadata: #{metadata.inspect}"
48
- message_queue << Smash.new(
54
+ new_message = Smash.new(
49
55
  :raw => Smash.new(
50
56
  :info => info,
51
57
  :metadata => metadata
52
58
  ),
53
59
  :content => payload
54
60
  )
55
- debug "Sending new messages signal to: #{notify} (current queue size: #{message_queue.size})"
56
- notify.signal(:new_messages)
61
+ debug "Sending new message signal to: #{notify}"
62
+ notify.signal(:new_messages, new_message)
57
63
  end
58
64
  true
59
65
  end
@@ -6,6 +6,8 @@ module Carnivore
6
6
  # RabbitMQ based carnivore source
7
7
  class Rabbitmq < Source
8
8
 
9
+ option :cache_signals
10
+
9
11
  autoload :MessageCollector, 'carnivore-rabbitmq/message_collector'
10
12
 
11
13
  # @return [Smash] initialization arguments
@@ -20,8 +22,6 @@ module Carnivore
20
22
  attr_reader :queue
21
23
  # @return [String] routing key
22
24
  attr_reader :routing_key
23
- # @return [Queue] message queue
24
- attr_reader :message_queue
25
25
  # @return [Carnviore::Source::Rabbitmq::MessageCollector] message collector
26
26
  attr_reader :message_collector
27
27
 
@@ -33,9 +33,7 @@ module Carnivore
33
33
  # @option init_args [Hash] :connection configuration hash for connection
34
34
  # @option init_args [String, Symbol] :force_library :bunny or :march_hare
35
35
  def setup(init_args={})
36
- require 'carnivore-rabbitmq/message_collector'
37
36
  @args = args.dup
38
- @message_queue = Queue.new
39
37
  @queue_name = args[:queue]
40
38
  @exchange_name = args[:exchange]
41
39
  debug "Creating Rabbitmq source instance <#{name}>"
@@ -49,27 +47,15 @@ module Carnivore
49
47
  # Start the message collection
50
48
  def start_collector
51
49
  unless(@collecting)
52
- @collecting = true
53
- @message_collector = MessageCollector.new(queue, message_queue, current_actor)
54
- message_collector.async.collect_messages
55
- end
56
- end
57
-
58
- # Restart collector if unexpectedly failed
59
- #
60
- # @param object [Actor] crashed actor
61
- # @param reason [Exception, NilClass]
62
- def collector_failure(object, reason)
63
- if(reason && object == message_collector)
64
- error "Message collector unexpectedly failed: #{reason} (restarting)"
65
- start_collector
50
+ @message_collector = MessageCollector.new(queue, current_actor)
51
+ message_collector.start!
66
52
  end
67
53
  end
68
54
 
69
55
  # Destroy message collector
70
56
  #
71
57
  # @return [TrueClass]
72
- def collector_teardown
58
+ def terminate
73
59
  connection.close if connection
74
60
  if(message_collector && message_collector.alive?)
75
61
  message_collector.terminate
@@ -109,10 +95,7 @@ module Carnivore
109
95
  # @return [Hash] payload
110
96
  def receive(*_)
111
97
  start_collector
112
- while(message_queue.empty?)
113
- wait(:new_messages)
114
- end
115
- message_queue.pop
98
+ wait(:new_messages)
116
99
  end
117
100
 
118
101
  # Transmit payload to connection
@@ -1,6 +1,6 @@
1
1
  module Carnivore
2
2
  module Rabbitmq
3
3
  # Current version of library
4
- VERSION = Gem::Version.new('0.2.0')
4
+ VERSION = Gem::Version.new('0.2.2')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carnivore-rabbitmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny