totoro 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/totoro +24 -0
- data/lib/totoro.rb +4 -0
- data/lib/totoro/config.rb +27 -0
- data/lib/totoro/queue.rb +31 -0
- data/totoro-0.0.8.gem +0 -0
- data/totoro.gemspec +17 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1b553012febde0452556b37f9d34c9213e7e482913b424164dbfeaba9d2f86cf
|
4
|
+
data.tar.gz: 45b37fb46a19d763c256b57c90137b684f0a893b9c5b7ca747e52107660ae960
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29bd002e9f11ace735895ae09ca461d15517756e0a221e4e48ccc6b7e79793263b1abb8e5d5c611c2789dbc1c57e33d0f1e937b821cdd22467a6da71b6068cee
|
7
|
+
data.tar.gz: 2aca3e038690907aa3ab432834fdbe26e33f39a10b95eac8760197eecf2dfd15c35035ce45b0eee58fd08be71b3f2d4c2824967fe781e5021d21163520a474cb
|
data/bin/totoro
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'totoro'
|
3
|
+
# You might want to change this
|
4
|
+
ENV['RAILS_ENV'] ||= 'development'
|
5
|
+
|
6
|
+
root = Dir.pwd
|
7
|
+
root = File.dirname(root) until File.exist?(File.join(root, 'config'))
|
8
|
+
Dir.chdir(root)
|
9
|
+
|
10
|
+
require File.join(root, 'config', 'environment')
|
11
|
+
Rails.logger = logger = Logger.new STDOUT
|
12
|
+
logger.level = Logger.const_get(Rails.configuration.log_level.to_s.upcase)
|
13
|
+
|
14
|
+
worker_class = ARGV[0]
|
15
|
+
logger.info 'Start to subscribe to Rabbitmq'
|
16
|
+
worker = Totoro::Config.get_worker worker_class
|
17
|
+
Totoro::Queue.subscribe(worker_class) do |delivery_info, metadata, payload|
|
18
|
+
logger.info "#{worker_class} Received: #{payload}"
|
19
|
+
payload_hash = JSON.parse(payload).with_indifferent_access
|
20
|
+
worker.process payload_hash, metadata, delivery_info
|
21
|
+
end
|
22
|
+
|
23
|
+
logger.info 'Listening to the Rabbitmq'
|
24
|
+
Totoro::Queue.channel.work_pool.join
|
data/lib/totoro.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Totoro
|
2
|
+
class Config
|
3
|
+
class <<self
|
4
|
+
def data
|
5
|
+
@data ||= Rails.application.config_for(:amqp).with_indifferent_access
|
6
|
+
end
|
7
|
+
|
8
|
+
def reset_data
|
9
|
+
@data = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def connect
|
13
|
+
data[:connect]
|
14
|
+
end
|
15
|
+
|
16
|
+
def queue(id)
|
17
|
+
name = data[:queue][id][:name]
|
18
|
+
settings = { durable: data[:queue][id][:durable] }
|
19
|
+
[name, settings]
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_worker(worker_class)
|
23
|
+
::Worker.const_get(worker_class.to_s.camelize).new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/totoro/queue.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Totoro
|
2
|
+
class Queue
|
3
|
+
class <<self
|
4
|
+
def connection
|
5
|
+
@connection ||= Bunny.new(Totoro::Config.connect).tap(&:start)
|
6
|
+
end
|
7
|
+
|
8
|
+
def channel
|
9
|
+
@channel ||= connection.create_channel
|
10
|
+
end
|
11
|
+
|
12
|
+
def exchange
|
13
|
+
@exchanges ||= channel.default_exchange
|
14
|
+
end
|
15
|
+
|
16
|
+
# enqueue = publish to direct exchange
|
17
|
+
def enqueue(id, payload)
|
18
|
+
queue = channel.queue(*Totoro::Config.queue(id))
|
19
|
+
payload = JSON.dump payload
|
20
|
+
exchange.publish(payload, routing_key: queue.name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def subscribe(id)
|
24
|
+
queue = channel.queue(*Totoro::Config.queue(id))
|
25
|
+
queue.subscribe do |delivery_info, metadata, payload|
|
26
|
+
yield(delivery_info, metadata, payload)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/totoro-0.0.8.gem
ADDED
Binary file
|
data/totoro.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{totoro}
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.authors = ["Shu hui"]
|
5
|
+
s.email = %q{shu.hui@blockchaintech.net.au}
|
6
|
+
s.homepage = "https://github.com/blockchaintech-au/totoro"
|
7
|
+
s.summary = %q{tool for rabbitmq}
|
8
|
+
s.description = %q{Enpower rabbitmq to make it configrable}
|
9
|
+
|
10
|
+
s.files = Dir['**/*'].keep_if { |file| File.file?(file) }
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
s.executables = ["totoro"]
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.add_runtime_dependency('rails', '>= 5.0.0')
|
16
|
+
s.add_runtime_dependency('bunny', '>= 2.9.0')
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: totoro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shu hui
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bunny
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.9.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.9.0
|
41
|
+
description: Enpower rabbitmq to make it configrable
|
42
|
+
email: shu.hui@blockchaintech.net.au
|
43
|
+
executables:
|
44
|
+
- totoro
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/totoro
|
49
|
+
- lib/totoro.rb
|
50
|
+
- lib/totoro/config.rb
|
51
|
+
- lib/totoro/queue.rb
|
52
|
+
- totoro-0.0.8.gem
|
53
|
+
- totoro.gemspec
|
54
|
+
homepage: https://github.com/blockchaintech-au/totoro
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.7.3
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: tool for rabbitmq
|
78
|
+
test_files: []
|