sevak 0.3.0 → 0.4.0
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.lock +1 -1
- data/README.md +43 -19
- data/lib/sevak/publisher.rb +19 -2
- data/lib/sevak/version.rb +1 -1
- data/{chillr_sevak.gemspec → sevak.gemspec} +0 -0
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ba1b1f19dfedbf1f09684c3f20bf0961b43ab8e
|
4
|
+
data.tar.gz: 6e009c195d675174db7bea30d5d9545e431c3a66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8110cea597ffa6e22441f222a6e793599047a5707dc4b2c71993d8e3cad37a369eb7269ec31ccbdec2432fe58b64d8c3f0ed537c3ea3ab16ab5402443583dd0b
|
7
|
+
data.tar.gz: 901110f1a5d8700e8cbf3a32d9a04985dcca4b0339f6b51ad8abb11cde0f668bebd7f3f6a538ab62b0783ca5ef954f9b3d72a18119ce8b33cc5dead1fc9c369c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,47 +1,71 @@
|
|
1
|
-
Sevak gem
|
2
|
-
|
1
|
+
Sevak gem makes it easy to send and receive messages from rabbitmq queues. It is built on top of the bunny gem.
|
2
|
+
It also supports delayed queuing using [rabbitmq delayed exchange plugin](https://github.com/rabbitmq/rabbitmq-delayed-message-exchange)
|
3
3
|
|
4
4
|
Usage:
|
5
5
|
|
6
|
+
Dependencies
|
7
|
+
|
8
|
+
* [rabbitmq delayed exchange plugin](https://github.com/rabbitmq/rabbitmq-delayed-message-exchange)
|
9
|
+
To install this plugin:
|
10
|
+
1. Download the latest build for the plugin from [here](http://www.rabbitmq.com/community-plugins.html)
|
11
|
+
2. Enable the plugin using command:
|
12
|
+
|
13
|
+
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
|
14
|
+
|
6
15
|
Install
|
7
16
|
|
8
17
|
gem install sevak
|
9
18
|
|
10
|
-
|
19
|
+
Configuration
|
20
|
+
Create a file under `config/initializers` and add following lines to that file:
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
Sevak.configure do |f|
|
23
|
+
f.host = 'localhost'
|
24
|
+
f.port = '5672'
|
25
|
+
f.user = 'username'
|
26
|
+
f.password = 'password'
|
27
|
+
f.prefetch_count = 10
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
Usage
|
19
32
|
|
20
|
-
|
33
|
+
### Publishing to a queue
|
21
34
|
|
35
|
+
To publish any message to a queue use the following syntax:
|
22
36
|
|
23
|
-
Sevak::Publisher.publish(
|
37
|
+
Sevak::Publisher.publish(*queue_name*, *message*)
|
24
38
|
|
25
39
|
If the queue is not present already it will be created automatically.
|
26
40
|
|
41
|
+
Example usage:
|
27
42
|
|
28
|
-
|
43
|
+
Sevak::Publisher.delayed_publish('sms', message = { name: 'Deepak', msisdn: '9078657543' })
|
29
44
|
|
45
|
+
### Publishing to a queue with a delay
|
46
|
+
|
47
|
+
To publish any message to a queue with some delay use the following syntax:
|
48
|
+
|
49
|
+
Sevak::Publisher.publish(*queue_name*, *message*, *delay in milliseconds*)
|
50
|
+
|
51
|
+
Exaple usage:
|
52
|
+
|
53
|
+
Sevak::Publisher.delayed_publish('sms', message = { name: 'Deepak', msisdn: '9078657543' }, 10000)
|
54
|
+
|
55
|
+
This will publish the message to an exchange which will route the message to the specified queue with a delay of 10 seconds.
|
56
|
+
|
57
|
+
### Receiving messages from ths queues
|
58
|
+
To receive message from this queue and process the message create a consumer file inside your project under `app/controllers`.
|
30
59
|
|
31
60
|
class SmsConsumer < Sevak::Consumer
|
32
61
|
|
33
62
|
queue_name 'sms'
|
34
63
|
|
35
64
|
def run(message)
|
36
|
-
|
37
|
-
status
|
65
|
+
*process the message*
|
38
66
|
end
|
39
67
|
|
40
68
|
..
|
41
69
|
end
|
42
70
|
|
43
71
|
The return status can have three values :ok, :error, :retry.
|
44
|
-
|
45
|
-
Publishing to the queue
|
46
|
-
|
47
|
-
Publisher.publish('in.chillr.email', { name: 'Deepak Kumar', message: 'welcome', email: 'deepak@chillr.in' })
|
data/lib/sevak/publisher.rb
CHANGED
@@ -6,11 +6,28 @@ module Sevak
|
|
6
6
|
include Singleton
|
7
7
|
|
8
8
|
def self.publish(queue_name, message)
|
9
|
-
instance.
|
9
|
+
instance.queue(queue_name).publish(message.to_json)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.delayed_publish(queue_name, message, delay = 0)
|
13
|
+
instance.publish_exchange(queue_name, message, delay)
|
10
14
|
end
|
11
15
|
|
12
16
|
def channel
|
13
17
|
@channel ||= connection.create_channel
|
14
18
|
end
|
19
|
+
|
20
|
+
def queue(queue_name)
|
21
|
+
@queue ||= channel.queue(queue_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def exchange(queue_name)
|
25
|
+
@exchange ||= channel.exchange("#{queue_name}_exchange", type: "x-delayed-message", arguments: { "x-delayed-type" => "direct" })
|
26
|
+
end
|
27
|
+
|
28
|
+
def publish_exchange(queue_name, message, delay)
|
29
|
+
queue(queue_name).bind(exchange(queue_name))
|
30
|
+
exchange(queue_name).publish(message.to_json, headers: { "x-delay" => delay })
|
31
|
+
end
|
15
32
|
end
|
16
|
-
end
|
33
|
+
end
|
data/lib/sevak/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak Kumar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -42,12 +42,12 @@ files:
|
|
42
42
|
- Rakefile
|
43
43
|
- bin/console
|
44
44
|
- bin/setup
|
45
|
-
- chillr_sevak.gemspec
|
46
45
|
- lib/sevak.rb
|
47
46
|
- lib/sevak/consumer.rb
|
48
47
|
- lib/sevak/core.rb
|
49
48
|
- lib/sevak/publisher.rb
|
50
49
|
- lib/sevak/version.rb
|
50
|
+
- sevak.gemspec
|
51
51
|
- tasks/.keep
|
52
52
|
homepage: ''
|
53
53
|
licenses:
|
@@ -69,9 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.6.
|
72
|
+
rubygems_version: 2.6.10
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Consumers for chillr api
|
76
76
|
test_files: []
|
77
|
-
has_rdoc:
|