Class: Pulsar::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/pulsar/message.rb

Overview

Immutable message value returned by consumers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload:, message_id:, properties: {}, key: nil, topic: nil, publish_time: nil, event_time: nil) ⇒ Message

Returns a new instance of Message.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pulsar/message.rb', line 8

def initialize(payload:, message_id:, properties: {}, key: nil, topic: nil, publish_time: nil, event_time: nil)
  raise ArgumentError, 'message_id must be a Pulsar::MessageId' unless message_id.is_a?(MessageId)

  @payload = String(payload).b.freeze
  @message_id = message_id
  @properties = properties.transform_keys(&:to_s).transform_values(&:to_s).freeze
  @key = key
  @topic = topic
  @publish_time = publish_time
  @event_time = event_time
  freeze
end

Instance Attribute Details

#event_timeObject (readonly)

Returns the value of attribute event_time.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def event_time
  @event_time
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def key
  @key
end

#message_idObject (readonly)

Returns the value of attribute message_id.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def message_id
  @message_id
end

#payloadObject (readonly)

Returns the value of attribute payload.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def payload
  @payload
end

#propertiesObject (readonly)

Returns the value of attribute properties.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def properties
  @properties
end

#publish_timeObject (readonly)

Returns the value of attribute publish_time.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def publish_time
  @publish_time
end

#topicObject (readonly)

Returns the value of attribute topic.



6
7
8
# File 'lib/pulsar/message.rb', line 6

def topic
  @topic
end