Class: PulsarSdk::Protocol::Message

Inherits:
Object
  • Object
show all
Includes:
Tweaks::AssignAttributes, Tweaks::CleanInspect
Defined in:
lib/pulsar_sdk/protocol/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tweaks::AssignAttributes

#assign_attributes, #initialize

Methods included from Tweaks::CleanInspect

#inspect

Instance Attribute Details

#ack_handlerObject

Returns the value of attribute ack_handler.



10
11
12
# File 'lib/pulsar_sdk/protocol/message.rb', line 10

def ack_handler
  @ack_handler
end

#consumer_idObject

Returns the value of attribute consumer_id.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def consumer_id
  @consumer_id
end

#event_timeObject

Returns the value of attribute event_time.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def event_time
  @event_time
end

#message_idObject

Returns the value of attribute message_id.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def message_id
  @message_id
end

#partition_keyObject

Returns the value of attribute partition_key.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def partition_key
  @partition_key
end

#payloadObject

Returns the value of attribute payload.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def payload
  @payload
end

#propertiesObject

Returns the value of attribute properties.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def properties
  @properties
end

#publish_timeObject

Returns the value of attribute publish_time.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def publish_time
  @publish_time
end

#topicObject

Returns the value of attribute topic.



7
8
9
# File 'lib/pulsar_sdk/protocol/message.rb', line 7

def topic
  @topic
end

Instance Method Details

#ack(type = Pulsar::Proto::CommandAck::AckType::Individual) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pulsar_sdk/protocol/message.rb', line 22

def ack(type = Pulsar::Proto::CommandAck::AckType::Individual)
  base_cmd = Pulsar::Proto::BaseCommand.new(
    type: Pulsar::Proto::BaseCommand::Type::ACK,
    ack: Pulsar::Proto::CommandAck.new(
      consumer_id: self.consumer_id,
      message_id: [self.message_id],
      ack_type: type
    )
  )

  ack_handler.call(base_cmd)
  @confirmed = true
end

#confirmed?Boolean

检查是否有确认,无论是ack还是nack都算是确认

Returns:

  • (Boolean)


37
38
39
# File 'lib/pulsar_sdk/protocol/message.rb', line 37

def confirmed?
  !!@confirmed
end

#nackObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pulsar_sdk/protocol/message.rb', line 41

def nack
  base_cmd = Pulsar::Proto::BaseCommand.new(
    type: Pulsar::Proto::BaseCommand::Type::REDELIVER_UNACKNOWLEDGED_MESSAGES,
    redeliverUnacknowledgedMessages: Pulsar::Proto::CommandRedeliverUnacknowledgedMessages.new(
      consumer_id: self.consumer_id,
      message_ids: [self.message_id]
    )
  )

  ack_handler.call(base_cmd)
  @confirmed = true
end