Class: JetstreamBridge::MessageContext

Inherits:
Struct
  • Object
show all
Defined in:
lib/jetstream_bridge/consumer/message_processor.rb

Overview

Immutable per-message metadata.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#consumerObject

Returns the value of attribute consumer



12
13
14
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 12

def consumer
  @consumer
end

#deliveriesObject

Returns the value of attribute deliveries



12
13
14
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 12

def deliveries
  @deliveries
end

#event_idObject

Returns the value of attribute event_id



12
13
14
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 12

def event_id
  @event_id
end

#seqObject

Returns the value of attribute seq



12
13
14
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 12

def seq
  @seq
end

#streamObject

Returns the value of attribute stream



12
13
14
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 12

def stream
  @stream
end

#subjectObject

Returns the value of attribute subject



12
13
14
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 12

def subject
  @subject
end

Class Method Details

.build(msg) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/jetstream_bridge/consumer/message_processor.rb', line 16

def self.build(msg)
  new(
    event_id: msg.header&.[]('nats-msg-id') || SecureRandom.uuid,
    deliveries: msg.&.num_delivered.to_i,
    subject: msg.subject,
    seq: msg.&.sequence,
    consumer: msg.&.consumer,
    stream: msg.&.stream
  )
end