Class: JetstreamBridge::Models::Event
- Inherits:
-
Object
- Object
- JetstreamBridge::Models::Event
- Defined in:
- lib/jetstream_bridge/models/event.rb
Overview
Structured event object provided to consumers
Defined Under Namespace
Classes: Metadata, PayloadAccessor
Instance Attribute Summary collapse
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#occurred_at ⇒ Object
readonly
Returns the value of attribute occurred_at.
-
#payload ⇒ Object
readonly
Access payload with method-style syntax.
-
#producer ⇒ Object
readonly
Returns the value of attribute producer.
-
#resource_id ⇒ Object
readonly
Returns the value of attribute resource_id.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#schema_version ⇒ Object
readonly
Returns the value of attribute schema_version.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Support hash-like access for backwards compatibility.
-
#deliveries ⇒ Integer
Number of times this message has been delivered.
-
#initialize(envelope, metadata: {}) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
-
#sequence ⇒ Integer?
Message sequence number in the stream.
-
#stream ⇒ String?
Stream this message came from.
-
#subject ⇒ String
Subject this message was received on.
-
#to_envelope ⇒ Hash
Get raw envelope hash.
-
#to_h ⇒ Hash
(also: #to_hash)
Get hash representation.
Constructor Details
#initialize(envelope, metadata: {}) ⇒ Event
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/jetstream_bridge/models/event.rb', line 77 def initialize(envelope, metadata: {}) envelope = envelope.transform_keys(&:to_s) if envelope.respond_to?(:transform_keys) @event_id = envelope['event_id'] @type = envelope['event_type'] @resource_type = envelope['resource_type'] @resource_id = envelope['resource_id'] @producer = envelope['producer'] @schema_version = envelope['schema_version'] || 1 @trace_id = envelope['trace_id'] @occurred_at = parse_time(envelope['occurred_at']) @payload = PayloadAccessor.new(envelope['payload'] || {}) = () @raw_envelope = envelope freeze end |
Instance Attribute Details
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def event_id @event_id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def end |
#occurred_at ⇒ Object (readonly)
Returns the value of attribute occurred_at.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def occurred_at @occurred_at end |
#payload ⇒ Object (readonly)
Access payload with method-style syntax
101 102 103 |
# File 'lib/jetstream_bridge/models/event.rb', line 101 def payload @payload end |
#producer ⇒ Object (readonly)
Returns the value of attribute producer.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def producer @producer end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def resource_id @resource_id end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def resource_type @resource_type end |
#schema_version ⇒ Object (readonly)
Returns the value of attribute schema_version.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def schema_version @schema_version end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def trace_id @trace_id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
71 72 73 |
# File 'lib/jetstream_bridge/models/event.rb', line 71 def type @type end |
Instance Method Details
#[](key) ⇒ Object
Support hash-like access for backwards compatibility
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/jetstream_bridge/models/event.rb', line 163 def [](key) case key.to_s when 'event_id' then @event_id when 'event_type' then @type when 'resource_type' then @resource_type when 'resource_id' then @resource_id when 'producer' then @producer when 'occurred_at' then @occurred_at&.iso8601 when 'trace_id' then @trace_id when 'schema_version' then @schema_version when 'payload' then @payload.to_h else @raw_envelope[key.to_s] end end |
#deliveries ⇒ Integer
Number of times this message has been delivered
133 134 135 |
# File 'lib/jetstream_bridge/models/event.rb', line 133 def deliveries .deliveries || 1 end |
#inspect ⇒ Object
158 159 160 |
# File 'lib/jetstream_bridge/models/event.rb', line 158 def inspect "#<#{self.class.name} id=#{@event_id} type=#{@type} deliveries=#{deliveries}>" end |
#sequence ⇒ Integer?
Message sequence number in the stream
154 155 156 |
# File 'lib/jetstream_bridge/models/event.rb', line 154 def sequence .sequence end |
#stream ⇒ String?
Stream this message came from
147 148 149 |
# File 'lib/jetstream_bridge/models/event.rb', line 147 def stream .stream end |
#subject ⇒ String
Subject this message was received on
140 141 142 |
# File 'lib/jetstream_bridge/models/event.rb', line 140 def subject .subject end |
#to_envelope ⇒ Hash
Get raw envelope hash
106 107 108 |
# File 'lib/jetstream_bridge/models/event.rb', line 106 def to_envelope @raw_envelope end |
#to_h ⇒ Hash Also known as: to_hash
Get hash representation
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/jetstream_bridge/models/event.rb', line 113 def to_h { event_id: @event_id, type: @type, resource_type: @resource_type, resource_id: @resource_id, producer: @producer, occurred_at: @occurred_at&.iso8601, trace_id: @trace_id, schema_version: @schema_version, payload: @payload.to_h, metadata: .to_h } end |