Class: NulogyMessageBusConsumer::Message
- Inherits:
-
Object
- Object
- NulogyMessageBusConsumer::Message
- Defined in:
- lib/nulogy_message_bus_consumer/message.rb
Instance Attribute Summary collapse
-
#company_uuid ⇒ Object
readonly
Returns the value of attribute company_uuid.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#event_data ⇒ Object
readonly
Returns the value of attribute event_data.
-
#event_data_unparsed ⇒ Object
readonly
Returns the value of attribute event_data_unparsed.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#partition ⇒ Object
readonly
Returns the value of attribute partition.
-
#subscription_id ⇒ Object
readonly
Returns the value of attribute subscription_id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Message
constructor
A new instance of Message.
- #to_h ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Message
Returns a new instance of Message.
15 16 17 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 15 def initialize(attrs = {}) attrs.each { |key, value| instance_variable_set("@#{key}", value) } end |
Instance Attribute Details
#company_uuid ⇒ Object (readonly)
Returns the value of attribute company_uuid.
10 11 12 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 10 def company_uuid @company_uuid end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
13 14 15 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 13 def created_at @created_at end |
#event_data ⇒ Object (readonly)
Returns the value of attribute event_data.
3 4 5 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 3 def event_data @event_data end |
#event_data_unparsed ⇒ Object (readonly)
Returns the value of attribute event_data_unparsed.
4 5 6 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 4 def event_data_unparsed @event_data_unparsed end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 5 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 6 def key @key end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
7 8 9 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 7 def offset @offset end |
#partition ⇒ Object (readonly)
Returns the value of attribute partition.
8 9 10 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 8 def partition @partition end |
#subscription_id ⇒ Object (readonly)
Returns the value of attribute subscription_id.
9 10 11 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 9 def subscription_id @subscription_id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
11 12 13 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 11 def @timestamp end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
12 13 14 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 12 def topic @topic end |
Class Method Details
.from_kafka(kafka_message) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 19 def self.from_kafka() envelope_data = JSON.parse(.payload, symbolize_names: true) event_data = begin JSON.parse(envelope_data[:event_json], symbolize_names: true) rescue {} end new( event_data: event_data, event_data_unparsed: envelope_data[:event_json], id: envelope_data[:id], key: .key, offset: .offset, partition: .partition, subscription_id: envelope_data[:subscription_id] || envelope_data[:public_subscription_id], company_uuid: envelope_data[:company_uuid] || envelope_data[:tenant_id], timestamp: ., topic: .topic, created_at: envelope_data[:created_at] ) end |
Instance Method Details
#to_h ⇒ Object
43 44 45 46 47 48 |
# File 'lib/nulogy_message_bus_consumer/message.rb', line 43 def to_h instance_variables.each_with_object({}) do |instance_variable, hash| attribute_name = instance_variable.to_s.delete("@") hash[attribute_name.to_sym] = public_send(attribute_name) end end |