smart-que 0.2.0 → 0.2.3
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/Gemfile +5 -1
- data/Gemfile.lock +26 -24
- data/README.md +36 -2
- data/lib/smart_que.rb +20 -6
- data/lib/smart_que/config.rb +1 -1
- data/lib/smart_que/publisher.rb +35 -9
- data/lib/smart_que/publishers/base.rb +42 -6
- data/lib/smart_que/version.rb +1 -1
- data/smart_que.gemspec +5 -4
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1836ac2d48717aee44d47c1c5025cc69c34ac58d
|
4
|
+
data.tar.gz: 3ba9f72b6b3185eeb72d75bc84250f98ad4983f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 138dfac1cba953b04d0f252e78fc3dee607aea276b960af1d5809f65b31fa19bcb34d54e154859fd5be828682b311a6cec5a9afe7173240069c4f283d990dc2f
|
7
|
+
data.tar.gz: 39554d1078fe45df50dc11c97e2204fa308aa5392dfa9e937074f46b8e10580f479a82a5849d696d0cc3bc24151f393736d938cd0b86c44abe11891ab9fb3e52
|
data/Gemfile
CHANGED
@@ -6,7 +6,11 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
# Add required gems
|
9
|
-
gem "bunny"
|
9
|
+
gem "bunny", '~> 2.11.0'
|
10
|
+
|
11
|
+
# Channel Connections
|
12
|
+
gem "connection_pool", '~> 2.2.1'
|
13
|
+
|
10
14
|
gem "pry"
|
11
15
|
gem 'guard'
|
12
16
|
gem 'guard-minitest'
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart-que (0.
|
4
|
+
smart-que (0.2.2)
|
5
|
+
bunny (~> 2.11)
|
6
|
+
connection_pool (~> 2.2)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
8
10
|
specs:
|
9
|
-
amq-protocol (2.
|
10
|
-
bunny (2.
|
11
|
-
amq-protocol (
|
12
|
-
coderay (1.1.
|
13
|
-
|
11
|
+
amq-protocol (2.3.0)
|
12
|
+
bunny (2.11.0)
|
13
|
+
amq-protocol (~> 2.3.0)
|
14
|
+
coderay (1.1.2)
|
15
|
+
connection_pool (2.2.2)
|
16
|
+
ffi (1.9.25)
|
14
17
|
formatador (0.2.5)
|
15
|
-
guard (2.14.
|
18
|
+
guard (2.14.2)
|
16
19
|
formatador (>= 0.2.4)
|
17
20
|
listen (>= 2.7, < 4.0)
|
18
|
-
lumberjack (
|
21
|
+
lumberjack (>= 1.0.12, < 2.0)
|
19
22
|
nenv (~> 0.1)
|
20
23
|
notiffany (~> 0.0)
|
21
24
|
pry (>= 0.9.12)
|
@@ -29,42 +32,41 @@ GEM
|
|
29
32
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
30
33
|
rb-inotify (~> 0.9, >= 0.9.7)
|
31
34
|
ruby_dep (~> 1.2)
|
32
|
-
lumberjack (1.0.
|
35
|
+
lumberjack (1.0.13)
|
33
36
|
metaclass (0.0.4)
|
34
|
-
method_source (0.
|
35
|
-
minitest (5.
|
36
|
-
mocha (1.
|
37
|
+
method_source (0.9.0)
|
38
|
+
minitest (5.11.3)
|
39
|
+
mocha (1.5.0)
|
37
40
|
metaclass (~> 0.0.1)
|
38
41
|
nenv (0.3.0)
|
39
42
|
notiffany (0.1.1)
|
40
43
|
nenv (~> 0.1)
|
41
44
|
shellany (~> 0.0)
|
42
|
-
pry (0.
|
45
|
+
pry (0.11.3)
|
43
46
|
coderay (~> 1.1.0)
|
44
|
-
method_source (~> 0.
|
45
|
-
|
46
|
-
|
47
|
-
rb-fsevent (0.10.2)
|
47
|
+
method_source (~> 0.9.0)
|
48
|
+
rake (12.3.1)
|
49
|
+
rb-fsevent (0.10.3)
|
48
50
|
rb-inotify (0.9.10)
|
49
51
|
ffi (>= 0.5.0, < 2)
|
50
52
|
ruby_dep (1.5.0)
|
51
53
|
shellany (0.0.1)
|
52
|
-
|
53
|
-
thor (0.19.4)
|
54
|
+
thor (0.20.0)
|
54
55
|
|
55
56
|
PLATFORMS
|
56
57
|
ruby
|
57
58
|
|
58
59
|
DEPENDENCIES
|
59
|
-
bundler (~> 1.
|
60
|
-
bunny
|
60
|
+
bundler (~> 1.16)
|
61
|
+
bunny (~> 2.11.0)
|
62
|
+
connection_pool (~> 2.2.1)
|
61
63
|
guard
|
62
64
|
guard-minitest
|
63
|
-
minitest (~> 5.
|
65
|
+
minitest (~> 5.11)
|
64
66
|
mocha
|
65
67
|
pry
|
66
|
-
rake (~>
|
68
|
+
rake (~> 12.3)
|
67
69
|
smart-que!
|
68
70
|
|
69
71
|
BUNDLED WITH
|
70
|
-
1.
|
72
|
+
1.16.2
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ to publish and consume messages with defined queues.
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'smart-que'
|
11
|
+
gem 'smart-que', '~> 0.2.0'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -17,7 +17,7 @@ And then execute:
|
|
17
17
|
|
18
18
|
Or install it yourself as:
|
19
19
|
|
20
|
-
$ gem install smart-que
|
20
|
+
$ gem install smart-que -v 0.2.0
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
@@ -38,6 +38,7 @@ RabbitMq server details and queue lists can be configured as follows
|
|
38
38
|
SmartQue.configure do |f|
|
39
39
|
f.host = ENV[:rabbit_mq][:host']
|
40
40
|
f.port = ENV[:rabbit_mq][:port']
|
41
|
+
f.vhost = ENV[:rabbit_mq][:vhost']
|
41
42
|
f.username = ENV[:rabbit_mq][:username']
|
42
43
|
f.password = ENV[:rabbit_mq][:password']
|
43
44
|
f.logger = Rails.logger
|
@@ -63,6 +64,39 @@ to publish messages to the RabbitMq server.
|
|
63
64
|
$publisher.publish('sms_otp', { number: '+919898123123', message: 'Test Message' })
|
64
65
|
```
|
65
66
|
|
67
|
+
|
68
|
+
## SmartQue unicast
|
69
|
+
|
70
|
+
```
|
71
|
+
$publisher.unicast(queue_name, payload)
|
72
|
+
```
|
73
|
+
|
74
|
+
The `unicast` method will provide an option to publish message to any queue which are
|
75
|
+
not predefined with initialization configuration. The `queue_name` parameter can be any queue
|
76
|
+
name, which will be created and bind to direct exchange instantly if doesn't exist.
|
77
|
+
|
78
|
+
```
|
79
|
+
$publisher.unicast('sms_alert', { number: '+919898123123', message: 'Test Message' })
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
## SmartQue multicast
|
85
|
+
|
86
|
+
```
|
87
|
+
$publisher.multicast(topic_name, payload)
|
88
|
+
```
|
89
|
+
|
90
|
+
The `multicast` method will provide an option to multicast message to queues which are
|
91
|
+
not predefined with initialization configuration. The `topic_name` parameter can be any
|
92
|
+
topic name and message will be consumable by any queues which subscribe to this topic
|
93
|
+
name.
|
94
|
+
|
95
|
+
```
|
96
|
+
$publisher.multicast('weather', { message: 'Test Message' })
|
97
|
+
```
|
98
|
+
|
99
|
+
|
66
100
|
## SmartQue Consumer
|
67
101
|
|
68
102
|
The consumer class should be inherited from SmartQue::Consumer, and each consumer will be
|
data/lib/smart_que.rb
CHANGED
@@ -22,17 +22,31 @@ module SmartQue
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Establish bunny connection
|
25
|
-
def self.establish_connection
|
26
|
-
|
25
|
+
def self.establish_connection(options = {})
|
26
|
+
unless @conn_pool
|
27
|
+
@conn_pool = ConnectionPool.new do
|
28
|
+
create_connection(options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
@conn_pool.with do |conn|
|
33
|
+
conn
|
34
|
+
end
|
35
|
+
end
|
27
36
|
|
28
|
-
|
37
|
+
def self.create_connection(options = {})
|
38
|
+
conn = Bunny.new(
|
29
39
|
host: config.host,
|
30
40
|
port: config.port,
|
41
|
+
vhost: fetch_parameters('vhost'),
|
31
42
|
username: config.username,
|
32
|
-
password: config.password
|
43
|
+
password: config.password
|
44
|
+
)
|
45
|
+
conn.start
|
46
|
+
end
|
33
47
|
|
34
|
-
|
35
|
-
|
48
|
+
def self.fetch_parameters(parameter, options = {})
|
49
|
+
(options[parameter] || config.send(parameter))
|
36
50
|
end
|
37
51
|
|
38
52
|
# Logger
|
data/lib/smart_que/config.rb
CHANGED
@@ -2,7 +2,7 @@ module SmartQue
|
|
2
2
|
class Config
|
3
3
|
# Configurations
|
4
4
|
# allowed configurations
|
5
|
-
CONFIGURATION = %w(host port queues env username password logfile logger)
|
5
|
+
CONFIGURATION = %w(host vhost port queues env username password logfile logger)
|
6
6
|
|
7
7
|
# Initialize
|
8
8
|
def initialize
|
data/lib/smart_que/publisher.rb
CHANGED
@@ -6,30 +6,56 @@ module SmartQue
|
|
6
6
|
# Initialize
|
7
7
|
def initialize
|
8
8
|
queue_list.each do |q_name|
|
9
|
-
|
10
|
-
q.bind(x_direct, routing_key: q.name)
|
9
|
+
find_or_initialize_queue(q_name)
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
# Instance methods
|
15
14
|
|
16
15
|
# Publish message to the respective queue
|
17
|
-
def publish(queue,
|
16
|
+
def publish(queue, payload = {})
|
18
17
|
# Check queue name includes in the configured list
|
19
18
|
# Return if queue doesn't exist
|
20
19
|
if queue_list.include? queue
|
21
20
|
# Publish sms to queue
|
22
21
|
x_direct.publish(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
log_message("Publish status: success, Queue : #{queue}, Content : #{
|
22
|
+
payload.to_json,
|
23
|
+
mandatory: true,
|
24
|
+
routing_key: get_queue(queue).name
|
25
|
+
)
|
26
|
+
log_message("Publish status: success, Queue : #{queue}, Content : #{payload}")
|
28
27
|
else
|
29
28
|
log_message("Publish status: failed, Queue(#{queue}) doesn't exist.")
|
30
|
-
log_message("Content : #{
|
29
|
+
log_message("Content : #{payload}")
|
31
30
|
raise QueueNotFoundError
|
32
31
|
end
|
33
32
|
end
|
33
|
+
|
34
|
+
# unicast message to queues
|
35
|
+
def unicast(q_name, payload = {})
|
36
|
+
x_default.publish(
|
37
|
+
payload.to_json,
|
38
|
+
routing_key: dot_formatted(q_name)
|
39
|
+
)
|
40
|
+
log_message("unicast status: success, Queue : #{q_name}, Content : #{payload}")
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# multicast message to queues based on topic subscription
|
45
|
+
def multicast(topic, payload = {})
|
46
|
+
x_topic.publish(
|
47
|
+
payload.to_json,
|
48
|
+
routing_key: dot_formatted(topic)
|
49
|
+
)
|
50
|
+
log_message("multicast status: success, Topic : #{topic}, Content : #{payload}")
|
51
|
+
end
|
52
|
+
|
53
|
+
# broadcast message to queues based on topic subscription
|
54
|
+
def broadcast(payload = {})
|
55
|
+
x_fanout.publish(
|
56
|
+
payload.to_json
|
57
|
+
)
|
58
|
+
log_message("broadcast status: success, Content : #{payload}")
|
59
|
+
end
|
34
60
|
end
|
35
61
|
end
|
@@ -1,19 +1,43 @@
|
|
1
|
+
require 'connection_pool'
|
2
|
+
|
1
3
|
module SmartQue
|
2
4
|
module Publishers
|
3
5
|
class Base
|
4
6
|
# List Queues from configuration
|
5
7
|
def queue_list
|
6
|
-
|
8
|
+
::SmartQue.config.queues
|
7
9
|
end
|
8
10
|
|
9
11
|
# Methods related to bunny exchange, channels, queues
|
12
|
+
def channel_pool
|
13
|
+
@channel_pool ||= ConnectionPool.new do
|
14
|
+
connection.create_channel
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
def channel
|
11
|
-
|
19
|
+
channel_pool.with do |channel|
|
20
|
+
channel
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
# Direct exchange
|
15
25
|
def x_direct
|
16
|
-
|
26
|
+
channel.direct("amq.direct")
|
27
|
+
end
|
28
|
+
|
29
|
+
def x_default
|
30
|
+
channel.default_exchange
|
31
|
+
end
|
32
|
+
|
33
|
+
# Topic exchange
|
34
|
+
def x_topic
|
35
|
+
channel.topic("amq.topic")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Fanout exchange
|
39
|
+
def x_fanout
|
40
|
+
channel.fanout("amq.fanout")
|
17
41
|
end
|
18
42
|
|
19
43
|
# Connection Object
|
@@ -21,10 +45,18 @@ module SmartQue
|
|
21
45
|
::SmartQue.establish_connection
|
22
46
|
end
|
23
47
|
|
48
|
+
def find_or_initialize_queue(q_name)
|
49
|
+
q = get_queue(q_name)
|
50
|
+
q.bind(x_direct, routing_key: q.name)
|
51
|
+
end
|
52
|
+
|
24
53
|
# Get/Set queue with name
|
25
54
|
# name : sms_otp
|
26
|
-
def get_queue(q_name)
|
27
|
-
|
55
|
+
def get_queue(q_name, options = {})
|
56
|
+
unless options[:dot_format] == false
|
57
|
+
q_name = modified_q_name(q_name)
|
58
|
+
end
|
59
|
+
channel.queue(q_name)
|
28
60
|
end
|
29
61
|
|
30
62
|
# Logging
|
@@ -39,7 +71,11 @@ module SmartQue
|
|
39
71
|
private
|
40
72
|
|
41
73
|
def modified_q_name(q_name)
|
42
|
-
q_name
|
74
|
+
dot_formatted(q_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
def dot_formatted(name_string)
|
78
|
+
name_string.downcase.gsub(/[\/|\_]/,".")
|
43
79
|
end
|
44
80
|
end
|
45
81
|
end
|
data/lib/smart_que/version.rb
CHANGED
data/smart_que.gemspec
CHANGED
@@ -31,10 +31,11 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
33
|
# Run time dependencies
|
34
|
-
spec.add_runtime_dependency "bunny", "~> 2.
|
34
|
+
spec.add_runtime_dependency "bunny", "~> 2.11"
|
35
|
+
spec.add_runtime_dependency "connection_pool", "~> 2.2"
|
35
36
|
|
36
37
|
# Development Dependencies
|
37
|
-
spec.add_development_dependency "bundler", "~> 1.
|
38
|
-
spec.add_development_dependency "rake", "~>
|
39
|
-
spec.add_development_dependency "minitest", "~> 5.
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
39
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
40
|
+
spec.add_development_dependency "minitest", "~> 5.11"
|
40
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart-que
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashik Salman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,56 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: '2.11'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: connection_pool
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
47
|
+
version: '1.16'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
54
|
+
version: '1.16'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '12.3'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '12.3'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: minitest
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '5.
|
75
|
+
version: '5.11'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '5.
|
82
|
+
version: '5.11'
|
69
83
|
description: Publish messages to RabbitMq broker and Consume with independent workers.
|
70
84
|
email:
|
71
85
|
- ashiksp@gmail.com
|