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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eaef6e47dd658ce854d60bab31f1743b4525de07
4
- data.tar.gz: 9ebee4ee5100c3d7b1a5be110f98dd8b46eee111
3
+ metadata.gz: a8353673e4b9c8f52c2e60b1aff90367d4e52f35
4
+ data.tar.gz: 6fd99d523fe6ad543caa3fa6b6c4864e9daf4509
5
5
  SHA512:
6
- metadata.gz: 7db993e800556ea1e04f9ee6372d8fdbe119f65cfc8e5ddfa459f29c431b2f545adf29c5bf914aa2a60eba9513ffe4f9b88a27c2c1e424f44fb8ba2879f16b7e
7
- data.tar.gz: 8a7e95547c67e61a0b625a19d25bcf480a398e2938dd1c0ad717d4d330209c5605da2557da0743c36b7fc4d348dd574cb0845e308a035b87c5f2460f3121941a
6
+ metadata.gz: c95dff2993e37c41af28688b3e9b121fb1518e65ebff3c40ffa81eda474918f01b8a8ad8ac5ebbc88c19c672386e3195b797963ade8c35017c2cc8adb8ce3402
7
+ data.tar.gz: 37fd64ee31872ffb73a6da3572501980ec87d45eda9f9a604344772dfb78fb30c18c7b772b30d834ef5622a3da429a16af110fa18b800ad453f51c357f0cb450
@@ -1,3 +1,3 @@
1
1
  class GorgMessageSender
2
- VERSION = "1.1.2"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -24,7 +24,7 @@ class GorgMessageSender
24
24
  @r_durable=durable_exchange
25
25
  end
26
26
 
27
- def message(data,routing_key, opts={})
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=message(data,routing_key,opts)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gorg_message_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Narbonne