manageiq-messaging 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 8859fa0a68ffe54c38283145348077bcbc78e004636e38960cc0d2ff70923f7a
4
- data.tar.gz: '088f6d9d2dc80e753b16a0bbdce58dc789aec1d5eada50c0aa3b74fd78109006'
3
+ metadata.gz: 78b0fa6b782a5bb3e21552abd1c0b54f473bdc460c722f896a7fecc7389259b3
4
+ data.tar.gz: f0ff3e82e5108b2241cebcfb2cbf9dde8208c3cf21e61b355d1cec9292562a64
5
5
  SHA512:
6
- metadata.gz: 457f22d4a96c0ec19a05cb2a0ebe3a9f665f62583d7337ede95ddf786e899b78dcd86173c219988d34ef8d4deafc188d8bcd184728e8362e4b66c772875370f5
7
- data.tar.gz: b496df16b18b87754bf22107fe0d7f30a2dee767f6673cdd51330880ea290539967397b32f629cb4ff24fb24e428390ba9478cc0c2bbc359c404e0a5cd358976
6
+ metadata.gz: 331823865454b700433699cb00f8938311ba91cf0ad87a807ffbc955be6e2d7060e5fc3fabbe91fea5f52b72eaf74a49d0909e94a63a665ccb2f44f9e56f76a0
7
+ data.tar.gz: a3e6c91fc5ba3a476908d26baf2f5cb3d1d4c768d63e69d3e318442b35f4bf71a3cf501d9dc12bbd53cdba66121f19d2c87ec14dd7eabc19a8aa4aefa40dc302
data/CHANGES CHANGED
@@ -7,3 +7,7 @@
7
7
 
8
8
  = 0.1.2 - 11-Dec-2018
9
9
  * Allow to set max_bytes to each_batch when subscribe to a Kafka topic.
10
+
11
+ = 0.1.4 - 3-Apr-2019
12
+ * Add an #ack method to a ReceivedMessage to simplify manual acknowledgements
13
+ * Allow caller to provide a session_timeout to kafka consumers, default of 30sec
data/README.md CHANGED
@@ -83,7 +83,7 @@ This is the one-to-one publish/subscribe pattern. Multiple subscribers can subsc
83
83
  client.subscribe_messages(:service => 'ems_operation', :affinity => 'ems_amazon1', :auto_ack => false) do |messages|
84
84
  messages.each do |msg|
85
85
  # do stuff with msg.message and msg.payload
86
- client.ack(msg.ack_ref)
86
+ msg.ack
87
87
  end
88
88
  end
89
89
 
@@ -26,7 +26,7 @@ class ProducerConsumer < Common
26
26
  client.subscribe_messages(:service => 'ems_operation', :affinity => 'ems_amazon1', :auto_ack => false) do |messages|
27
27
  messages.each do |msg|
28
28
  do_stuff(msg)
29
- client.ack(msg.ack_ref)
29
+ msg.ack
30
30
  end
31
31
  end
32
32
  sleep(5)
@@ -106,9 +106,9 @@ module ManageIQ
106
106
  # msg.sender
107
107
  # msg.message
108
108
  # msg.payload
109
- # msg.ack_ref #used to ack the message
109
+ # msg.ack_ref
110
110
  #
111
- # client.ack(msg.ack_ref) # needed only when options[:auto_ack] is false
111
+ # msg.ack # needed only when options[:auto_ack] is false
112
112
  # # process the message
113
113
  # end
114
114
  # end
@@ -122,7 +122,7 @@ module ManageIQ
122
122
  # message is proccessed. Any un-acked message will be redelivered to next subscriber
123
123
  # AFTER the current subscriber disconnects normally or abnormally (e.g. crashed).
124
124
  #
125
- # To ack a message call +ack+(+msg.ack_ref+)
125
+ # To ack a message call +msg.ack+
126
126
  def subscribe_messages(options, &block)
127
127
  raise "A block is required" unless block_given?
128
128
  assert_options(options, [:service])
@@ -189,9 +189,9 @@ module ManageIQ
189
189
  # msg.sender
190
190
  # msg.message
191
191
  # msg.payload
192
- # msg.ack_ref #used to ack the message
192
+ # msg.ack_ref
193
193
  #
194
- # client.ack(msg.ack_ref) # needed only when options[:auto_ack] is false
194
+ # msg.ack # needed only when options[:auto_ack] is false
195
195
  # # process the message
196
196
  # end
197
197
  #
@@ -204,7 +204,7 @@ module ManageIQ
204
204
  # message is proccessed. Any un-acked message will be redelivered to next subscriber
205
205
  # AFTER the current subscriber disconnects normally or abnormally (e.g. crashed).
206
206
  #
207
- # To ack a message call +ack+(+msg.ack_ref+)
207
+ # To ack a message call +msg.ack+
208
208
  def subscribe_topic(options, &block)
209
209
  raise "A block is required" unless block_given?
210
210
  assert_options(options, [:service])
@@ -26,9 +26,11 @@ module ManageIQ
26
26
  #
27
27
  # Kafka specific +subscribe_topic+ options:
28
28
  # * :persist_ref (Used as Kafka group_id)
29
+ # * :session_timeout (Max time in seconds allowed to process a message, default is 30)
29
30
  #
30
31
  # Kafka specific +subscribe_messages+ options:
31
32
  # * :max_bytes (Max batch size to read, default is 10Mb)
33
+ # * :session_timeout (Max time in seconds allowed to process a message, default is 30)
32
34
  #
33
35
  # Without +:persist_ref+ every topic subscriber receives a copy of each message
34
36
  # only when they are active. If multiple topic subscribers join with the same
@@ -13,19 +13,27 @@ module ManageIQ
13
13
  @producer ||= kafka_client.producer
14
14
  end
15
15
 
16
- def topic_consumer(persist_ref)
16
+ def topic_consumer(persist_ref, session_timeout = nil)
17
17
  # persist_ref enables consumer to receive messages sent when consumer is temporarily offline
18
18
  # it also enables consumers to do load balancing when multiple consumers join the with the same ref.
19
19
  @topic_consumer.try(:stop) unless @persist_ref == persist_ref
20
20
  @persist_ref = persist_ref
21
- @topic_consumer ||= kafka_client.consumer(:group_id => persist_ref)
21
+
22
+ consumer_opts = {:group_id => persist_ref}
23
+ consumer_opts[:session_timeout] = session_timeout if session_timeout.present?
24
+
25
+ @topic_consumer ||= kafka_client.consumer(consumer_opts)
22
26
  end
23
27
 
24
- def queue_consumer(topic)
28
+ def queue_consumer(topic, session_timeout = nil)
25
29
  # all queue consumers join the same group so that each message can be processed by one and only one consumer
26
30
  @queue_consumer.try(:stop) unless @queue_topic == topic
27
31
  @queue_topic = topic
28
- @queue_consumer ||= kafka_client.consumer(:group_id => GROUP_FOR_QUEUE_MESSAGES + topic)
32
+
33
+ consumer_opts = {:group_id => GROUP_FOR_QUEUE_MESSAGES + topic}
34
+ consumer_opts[:session_timeout] = session_timeout if session_timeout.present?
35
+
36
+ @queue_consumer ||= kafka_client.consumer(consumer_opts)
29
37
  end
30
38
 
31
39
  trap("TERM") do
@@ -86,7 +94,7 @@ module ManageIQ
86
94
  payload = decode_body(message.headers, message.value)
87
95
  sender, event_type = parse_event_headers(message.headers)
88
96
  logger.info("Event received: topic(#{topic}), event(#{payload_log(payload)}), sender(#{sender}), type(#{event_type})")
89
- yield ManageIQ::Messaging::ReceivedMessage.new(sender, event_type, payload, message)
97
+ yield ManageIQ::Messaging::ReceivedMessage.new(sender, event_type, payload, message, self)
90
98
  logger.info("Event processed")
91
99
  rescue StandardError => e
92
100
  logger.error("Event processing error: #{e.message}")
@@ -16,19 +16,20 @@ module ManageIQ
16
16
 
17
17
  def subscribe_messages_impl(options)
18
18
  topic = address(options)
19
+ session_timeout = options[:session_timeout]
19
20
 
20
21
  batch_options = {}
21
22
  batch_options[:automatically_mark_as_processed] = auto_ack?(options)
22
23
  batch_options[:max_bytes] = options[:max_bytes] if options.key?(:max_bytes)
23
24
 
24
- consumer = queue_consumer(topic)
25
+ consumer = queue_consumer(topic, session_timeout)
25
26
  consumer.subscribe(topic)
26
27
  consumer.each_batch(batch_options) do |batch|
27
28
  logger.info("Batch message received: queue(#{topic})")
28
29
  begin
29
30
  messages = batch.messages.collect do |message|
30
31
  sender, message_type, _class_name, payload = process_queue_message(topic, message)
31
- ManageIQ::Messaging::ReceivedMessage.new(sender, message_type, payload, message)
32
+ ManageIQ::Messaging::ReceivedMessage.new(sender, message_type, payload, message, self)
32
33
  end
33
34
 
34
35
  yield messages
@@ -10,10 +10,11 @@ module ManageIQ
10
10
 
11
11
  def subscribe_topic_impl(options, &block)
12
12
  topic = address(options)
13
- persist_ref = options[:persist_ref]
13
+ persist_ref = options[:persist_ref]
14
+ session_timeout = options[:session_timeout]
14
15
 
15
16
  if persist_ref
16
- consumer = topic_consumer(persist_ref)
17
+ consumer = topic_consumer(persist_ref, session_timeout)
17
18
  consumer.subscribe(topic, :start_from_beginning => false)
18
19
  consumer.each_message(:automatically_mark_as_processed => auto_ack?(options)) do |message|
19
20
  process_topic_message(topic, message, &block)
@@ -1,10 +1,14 @@
1
1
  module ManageIQ
2
2
  module Messaging
3
3
  class ReceivedMessage
4
- attr_accessor :sender, :message, :payload, :ack_ref
4
+ attr_accessor :sender, :message, :payload, :ack_ref, :client
5
5
 
6
- def initialize(sender, message, payload, ack_ref)
7
- @sender, @message, @payload, @ack_ref = sender, message, payload, ack_ref
6
+ def initialize(sender, message, payload, ack_ref, client)
7
+ @sender, @message, @payload, @ack_ref, @client = sender, message, payload, ack_ref, client
8
+ end
9
+
10
+ def ack
11
+ client.ack(ack_ref)
8
12
  end
9
13
  end
10
14
  end
@@ -35,7 +35,7 @@ module ManageIQ
35
35
  message_body = decode_body(msg.headers, msg.body)
36
36
  logger.info("Message received: queue(#{queue_name}), msg(#{payload_log(message_body)}), headers(#{msg.headers})")
37
37
 
38
- result = yield [ManageIQ::Messaging::ReceivedMessage.new(sender, message_type, message_body, msg)]
38
+ result = yield [ManageIQ::Messaging::ReceivedMessage.new(sender, message_type, message_body, msg, self)]
39
39
  logger.info("Message processed")
40
40
 
41
41
  correlation_ref = msg.headers['correlation_id']
@@ -23,7 +23,7 @@ module ManageIQ
23
23
  event_type = event.headers['event_type']
24
24
  event_body = decode_body(event.headers, event.body)
25
25
  logger.info("Event received: queue(#{queue_name}), event(#{event_body}), headers(#{event.headers})")
26
- yield ManageIQ::Messaging::ReceivedMessage.new(sender, event_type, event_body, event)
26
+ yield ManageIQ::Messaging::ReceivedMessage.new(sender, event_type, event_body, event, self)
27
27
  logger.info("Event processed")
28
28
  rescue => e
29
29
  logger.error("Event processing error: #{e.message}")
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module Messaging
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  requirements: []
204
204
  rubyforge_project:
205
- rubygems_version: 2.7.6
205
+ rubygems_version: 2.7.6.2
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: Client library for ManageIQ components to exchange messages through its internal