gorg_message_sender 1.1.2 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gorg_message_sender/version.rb +1 -1
- data/lib/gorg_message_sender.rb +40 -2
- 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: a8353673e4b9c8f52c2e60b1aff90367d4e52f35
|
4
|
+
data.tar.gz: 6fd99d523fe6ad543caa3fa6b6c4864e9daf4509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95dff2993e37c41af28688b3e9b121fb1518e65ebff3c40ffa81eda474918f01b8a8ad8ac5ebbc88c19c672386e3195b797963ade8c35017c2cc8adb8ce3402
|
7
|
+
data.tar.gz: 37fd64ee31872ffb73a6da3572501980ec87d45eda9f9a604344772dfb78fb30c18c7b772b30d834ef5622a3da429a16af110fa18b800ad453f51c357f0cb450
|
data/lib/gorg_message_sender.rb
CHANGED
@@ -24,7 +24,7 @@ class GorgMessageSender
|
|
24
24
|
@r_durable=durable_exchange
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def to_message(data,routing_key, opts={})
|
28
28
|
json_msg={
|
29
29
|
"event_uuid" => opts[:event_uuid]||SecureRandom.uuid,
|
30
30
|
"event_name" => routing_key,
|
@@ -40,7 +40,7 @@ class GorgMessageSender
|
|
40
40
|
self.start(verbose: opts[:verbose])
|
41
41
|
p_opts={}
|
42
42
|
p_opts[:routing_key]= routing_key if routing_key
|
43
|
-
msg=
|
43
|
+
msg=self.to_message(data,routing_key,opts)
|
44
44
|
@x.publish(msg, p_opts)
|
45
45
|
puts " [#] Message sent to exchange '#{@r_exchange}' (#{@r_durable ? "" : "not "}durable) with routing key '#{routing_key}'" if opts[:verbose]
|
46
46
|
msg
|
@@ -55,6 +55,44 @@ class GorgMessageSender
|
|
55
55
|
msg
|
56
56
|
end
|
57
57
|
|
58
|
+
def send_batch_raw(msgs,opts={})
|
59
|
+
p_opts={}
|
60
|
+
|
61
|
+
send_batch_raw_with_threads(msgs,opts={})
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def send_batch_raw_with_threads(msgs,opts={})
|
67
|
+
require 'thread'
|
68
|
+
nb_of_threads=4
|
69
|
+
batch_size=(msgs.count/nb_of_threads.to_f).ceil.to_i
|
70
|
+
|
71
|
+
work_q = Queue.new
|
72
|
+
|
73
|
+
msgs.each_slice(batch_size) do |msg_batch|
|
74
|
+
work_q.push msg_batch
|
75
|
+
end
|
76
|
+
|
77
|
+
workers=[]
|
78
|
+
(1..nb_of_threads).each do |worker_id|
|
79
|
+
workers << Thread.new do
|
80
|
+
while (msg_pool = work_q.pop(true) rescue nil)
|
81
|
+
x=conn.create_channel.topic(@r_exchange, :durable => @r_durable)
|
82
|
+
msg_pool.each{|msg| x.publish(msg[:content], :routing_key => msg[:routing_key])}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end;
|
86
|
+
workers.map(&:join); "ok"
|
87
|
+
end
|
88
|
+
|
89
|
+
def send_batch_raw_without_threads(msgs,opts={})
|
90
|
+
x=conn.create_channel.topic(@r_exchange, :durable => @r_durable)
|
91
|
+
msgs.each do |msg|
|
92
|
+
x.publish(msg[:content], :routing_key => msg[:routing_key])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
58
96
|
protected
|
59
97
|
|
60
98
|
def conn
|