carnivore-nsq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80215ccf0693d381ff5ce8c73930f2c5507e63f0
4
+ data.tar.gz: 1e4816402f4ca38fe8a61e83cee47379d06b2f13
5
+ SHA512:
6
+ metadata.gz: e943cb3e8bc959f31af6e379cde75b7ba3e05f787df92456f97186916c48067193cf1ccafee1be49bda08d6318219fe16a57a98dfb74e6e04bea6c5085ca774a
7
+ data.tar.gz: 4b0170286de5308f17cda80fd35f7316694591474f236a37018ca9539008d5fa11222e49c339099a68a4964024ddcfb4ca818d4a1fd71228f328e94fb4525a18
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## v0.1.0
2
+ * Initial release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/carnivore-rb/carnivore-nsq/pulls
16
+
17
+ Please base all pull requests of the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/carnivore-rb/carnivore-nsq/issues
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Carnivore NSQ
2
+
3
+ Provides NSQ `Carnivore::Source`
4
+
5
+ # Usage
6
+
7
+ ```ruby
8
+ require 'carnivore'
9
+ require 'carnivore-nsq'
10
+
11
+ Carnivore.configure do
12
+ source = Carnivore::Source.build(
13
+ :type => :nsq,
14
+ :args => {
15
+ }
16
+ )
17
+ end.start!
18
+ ```
19
+
20
+ # Info
21
+ * Carnivore: https://github.com/carnivore-rb/carnivore
22
+ * Repository: https://github.com/carnivore-rb/carnivore-nsq
23
+ * IRC: Freenode @ #carnivore
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'carnivore-nsq/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'carnivore-nsq'
5
+ s.version = Carnivore::Nsq::VERSION.version
6
+ s.summary = 'Message processing helper'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'chrisroberts.code@gmail.com'
9
+ s.homepage = 'https://github.com/carnivore-rb/carnivore-nsq'
10
+ s.description = 'Carnivore NSQ source'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_dependency 'carnivore', '>= 0.1.8'
14
+ s.add_dependency 'krakow'
15
+ s.files = Dir['lib/**/*'] + %w(carnivore-nsq.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
16
+ end
@@ -0,0 +1,95 @@
1
+ require 'krakow'
2
+ require 'multi_json'
3
+
4
+ module Carnivore
5
+ class Source
6
+ class Nsq < Source
7
+
8
+ DEFAULT_LOOKUPD_PATH = '/etc/carnivore/nsq.json'
9
+
10
+ attr_reader(
11
+ :lookupd, :http_transmit, :reader,
12
+ :writer, :topic, :channel, :reader_args,
13
+ :waiter, :producer_args, :args
14
+ )
15
+
16
+ def setup(args={})
17
+ @args = args.dup
18
+ @lookupd = (default_lookupds + [args[:lookupd]]).flatten.compact.uniq
19
+ @http_transmit = args[:http_transmit]
20
+ @producer_args = args[:producer]
21
+ @topic = args[:topic]
22
+ @channel = args[:channel] || 'default'
23
+ @reader_args = args[:reader_opts] || {}
24
+ @waiter = Celluloid::Condition.new
25
+ Krakow::Utils::Logging.level = (Carnivore::Config.get(:krakow, :logging, :level) || :info).to_sym
26
+ end
27
+
28
+ def connect
29
+ if(lookupd)
30
+ consumer_args = {
31
+ :nsqlookupd => lookupd,
32
+ :topic => topic,
33
+ :channel => channel,
34
+ :max_in_flight => 1,
35
+ :notifier => waiter
36
+ }.merge(reader_args)
37
+ @reader = Krakow::Consumer.new(consumer_args)
38
+ info "Reader connection for #{topic}:#{channel} established #{reader}"
39
+ end
40
+ if(producer_args)
41
+ @writer = Krakow::Producer.new(producer_args.merge(:topic => topic))
42
+ info "Producer TCP connection for #{topic} established #{writer}"
43
+ elsif(http_transmit)
44
+ @writer = Krakow::Producer::Http.new(
45
+ :endpoint => http_transmit,
46
+ :topic => topic
47
+ )
48
+ info "Producer HTTP connection for #{topic} established #{writer}"
49
+ end
50
+ end
51
+
52
+ def consumer
53
+ reader ||
54
+ abort('Consumer is not established. No setup information provided!')
55
+ end
56
+
57
+ def producer
58
+ writer ||
59
+ abort('Producer is not established. No setup information provided!')
60
+ end
61
+
62
+ def receive(n=1)
63
+ if(consumer.queue.empty?)
64
+ waiter.wait
65
+ end
66
+ msg = consumer.queue.pop
67
+ end
68
+
69
+ def transmit(payload, original=nil)
70
+ payload = MultiJson.dump(payload) unless payload.is_a?(String)
71
+ producer.write(payload)
72
+ end
73
+
74
+ def confirm(message)
75
+ consumer.confirm(message[:message])
76
+ end
77
+
78
+ private
79
+
80
+ def default_lookupds
81
+ json_path = args.fetch(:lookupd_file_path, DEFAULT_LOOKUPD_PATH)
82
+ lookupds = nil
83
+ if(File.exists?(json_path))
84
+ begin
85
+ lookupds = MultiJson.load(File.read(json_path), :symbolize_keys => true)[:lookupds]
86
+ rescue MultiJson::LoadError => e
87
+ error "Failed to load nsqlookupd file from system: #{e}"
88
+ end
89
+ end
90
+ lookupds || []
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,6 @@
1
+ module Carnivore
2
+ module Nsq
3
+ # current library version
4
+ VERSION = Gem::Version.new('0.1.0')
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ require 'carnivore-nsq/version'
2
+ require 'carnivore'
3
+
4
+ Carnivore::Source.provide(:nsq, 'carnivore-nsq/nsq')
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carnivore-nsq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carnivore
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: krakow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Carnivore NSQ source
42
+ email: chrisroberts.code@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CONTRIBUTING.md
49
+ - LICENSE
50
+ - README.md
51
+ - carnivore-nsq.gemspec
52
+ - lib/carnivore-nsq.rb
53
+ - lib/carnivore-nsq/nsq.rb
54
+ - lib/carnivore-nsq/version.rb
55
+ homepage: https://github.com/carnivore-rb/carnivore-nsq
56
+ licenses:
57
+ - Apache 2.0
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Message processing helper
79
+ test_files: []
80
+ has_rdoc: