class PulsarSdk::Protocol::Message

Attributes

ack_handler[RW]
consumer_id[RW]
event_time[RW]
message_id[RW]
partition_key[RW]
payload[RW]
properties[RW]
publish_time[RW]
topic[RW]

Public Instance Methods

ack(type = Pulsar::Proto::CommandAck::AckType::Individual) click to toggle source
# 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?() click to toggle source

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

# File lib/pulsar_sdk/protocol/message.rb, line 37
def confirmed?
  !!@confirmed
end
nack() click to toggle source
# 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