smart-que 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -3
- data/lib/smart_que/publisher.rb +34 -16
- data/lib/smart_que/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbcbe208404fb52eac11166bed6c4474a164c6ad
|
4
|
+
data.tar.gz: 060e6dcb5170fb96db495d9d9f22c730c1866e53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1a8e5a3b43f1a0ac2173ce437338dd711557053e51269b27171beab808652eab951b745cbc2e81cb07aa8c9c54448445e7487afb4023921d82577e66d259bc3
|
7
|
+
data.tar.gz: c31e06758cea569338d844396ead80e006a27cd4710357112206fd2d75941d2f235e9f8e131dab75a57e5bacca7af24753120f4553e7e6e71ab60d1b7956e362
|
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', '~> 0.2.
|
11
|
+
gem 'smart-que', '~> 0.2.6'
|
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 -v 0.2.
|
20
|
+
$ gem install smart-que -v 0.2.6
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
@@ -34,6 +34,7 @@ RabbitMq server details and queue lists can be configured as follows
|
|
34
34
|
|
35
35
|
```
|
36
36
|
# File: config/initializers/smart_que.rb
|
37
|
+
require 'smart_que'
|
37
38
|
|
38
39
|
SmartQue.configure do |f|
|
39
40
|
f.host = ENV[:rabbit_mq][:host']
|
@@ -73,7 +74,7 @@ $publisher.unicast(queue_name, payload)
|
|
73
74
|
|
74
75
|
The `unicast` method will provide an option to publish message to any queue which are
|
75
76
|
not predefined with initialization configuration. The `queue_name` parameter can be any queue
|
76
|
-
name, which will be created and
|
77
|
+
name, which will be created and bound to direct exchange instantly if doesn't exist.
|
77
78
|
|
78
79
|
```
|
79
80
|
$publisher.unicast('sms_alert', { number: '+919898123123', message: 'Test Message' })
|
@@ -96,6 +97,20 @@ name.
|
|
96
97
|
$publisher.multicast('weather', { message: 'Test Message' })
|
97
98
|
```
|
98
99
|
|
100
|
+
## SmartQue broadcast
|
101
|
+
|
102
|
+
```
|
103
|
+
$publisher.broadcast(payload)
|
104
|
+
```
|
105
|
+
|
106
|
+
The `broadcast` method will provide an option to broadcast message to queues which are
|
107
|
+
not predefined with initialization configuration. The broadcst message will be consumable by
|
108
|
+
all queues which are bound to rabbitmq fanout exchange.
|
109
|
+
|
110
|
+
```
|
111
|
+
$publisher.broadcast({ message: 'Broadcast Test Message' })
|
112
|
+
```
|
113
|
+
|
99
114
|
|
100
115
|
## SmartQue Consumer
|
101
116
|
|
@@ -143,6 +158,12 @@ end
|
|
143
158
|
RAILS_ENV=staging bundle exec rake rabbitmq:send_otp_sms
|
144
159
|
```
|
145
160
|
|
161
|
+
## SmartQue Exceptions
|
162
|
+
|
163
|
+
SmartQue will not retry automatic connection recovery after rabbitmq connection failure. It raises
|
164
|
+
`SmartQue::ConnectionError` when tcp connection failure happens. You can catch this exception to
|
165
|
+
identify connection failures and can perform necessary actions upon it.
|
166
|
+
|
146
167
|
## RabbitMq Web Interface
|
147
168
|
|
148
169
|
You can enable rabbitmq_management plugin so that rabbitmq server informations
|
data/lib/smart_que/publisher.rb
CHANGED
@@ -18,12 +18,18 @@ module SmartQue
|
|
18
18
|
# Return if queue doesn't exist
|
19
19
|
if queue_list.include? queue
|
20
20
|
# Publish sms to queue
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
begin
|
22
|
+
x_direct.publish(
|
23
|
+
payload.to_json,
|
24
|
+
mandatory: true,
|
25
|
+
routing_key: get_queue(queue).name
|
26
|
+
)
|
27
|
+
log_message("Publish status: success, Queue : #{queue}, Content : #{payload}")
|
28
|
+
:success
|
29
|
+
rescue => ex
|
30
|
+
log_message("Publish error:#{ex.message}")
|
31
|
+
:error
|
32
|
+
end
|
27
33
|
else
|
28
34
|
log_message("Publish status: failed, Queue(#{queue}) doesn't exist.")
|
29
35
|
log_message("Content : #{payload}")
|
@@ -33,11 +39,17 @@ module SmartQue
|
|
33
39
|
|
34
40
|
# unicast message to queues
|
35
41
|
def unicast(q_name, payload = {})
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
begin
|
43
|
+
x_default.publish(
|
44
|
+
payload.to_json,
|
45
|
+
routing_key: dot_formatted(q_name)
|
46
|
+
)
|
47
|
+
log_message("unicast status: success, Queue : #{q_name}, Content : #{payload}")
|
48
|
+
:success
|
49
|
+
rescue => ex
|
50
|
+
log_message("Unicast error:#{ex.message}")
|
51
|
+
:error
|
52
|
+
end
|
41
53
|
end
|
42
54
|
|
43
55
|
|
@@ -51,17 +63,23 @@ module SmartQue
|
|
51
63
|
log_message("multicast status: success, Topic : #{topic}, Content : #{payload}")
|
52
64
|
:success
|
53
65
|
rescue => ex
|
54
|
-
|
66
|
+
log_message("Multicast error:#{ex.message}")
|
55
67
|
:error
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
59
71
|
# broadcast message to queues based on topic subscription
|
60
72
|
def broadcast(payload = {})
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
73
|
+
begin
|
74
|
+
x_fanout.publish(
|
75
|
+
payload.to_json
|
76
|
+
)
|
77
|
+
log_message("broadcast status: success, Content : #{payload}")
|
78
|
+
:success
|
79
|
+
rescue => ex
|
80
|
+
log_message("Broadcast error:#{ex.message}")
|
81
|
+
:error
|
82
|
+
end
|
65
83
|
end
|
66
84
|
end
|
67
85
|
end
|
data/lib/smart_que/version.rb
CHANGED