Class: KubeMQ::Queues::QueueMessageReceived
- Inherits:
-
Object
- Object
- KubeMQ::Queues::QueueMessageReceived
- Defined in:
- lib/kubemq/queues/queue_message_received.rb
Overview
A message received from a queue via KubeMQ::QueuesClient#poll or KubeMQ::QueuesClient#receive_queue_messages.
When received through the stream API (KubeMQ::QueuesClient#poll), transactional methods #ack, #reject, and #requeue are available for per-message acknowledgement within the poll transaction.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#body ⇒ String
readonly
Message payload (binary).
-
#channel ⇒ String
readonly
Source queue channel name.
-
#id ⇒ String
readonly
Message identifier.
-
#metadata ⇒ String
readonly
Message metadata.
-
#tags ⇒ Hash{String => String}
readonly
User-defined key-value tags.
Instance Method Summary collapse
-
#ack ⇒ void
Acknowledges this message within the poll transaction.
-
#initialize(id:, channel:, metadata:, body:, tags:, attributes: nil, action_proc: nil, sequence: 0) ⇒ QueueMessageReceived
constructor
private
A new instance of QueueMessageReceived.
-
#reject ⇒ void
Rejects (negative-acknowledges) this message.
-
#requeue(channel:) ⇒ void
Requeues this message to a different channel.
Constructor Details
#initialize(id:, channel:, metadata:, body:, tags:, attributes: nil, action_proc: nil, sequence: 0) ⇒ QueueMessageReceived
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of QueueMessageReceived.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 103 def initialize(id:, channel:, metadata:, body:, tags:, attributes: nil, action_proc: nil, sequence: 0) @id = id @channel = channel @metadata = @body = body @tags = || {} @attributes = attributes @action_proc = action_proc @sequence = sequence end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
92 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 92 attr_reader :id, :channel, :metadata, :body, :tags, :attributes |
#body ⇒ String (readonly)
Returns message payload (binary).
92 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 92 attr_reader :id, :channel, :metadata, :body, :tags, :attributes |
#channel ⇒ String (readonly)
Returns source queue channel name.
92 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 92 attr_reader :id, :channel, :metadata, :body, :tags, :attributes |
#id ⇒ String (readonly)
Returns message identifier.
92 93 94 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 92 def id @id end |
#metadata ⇒ String (readonly)
Returns message metadata.
92 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 92 attr_reader :id, :channel, :metadata, :body, :tags, :attributes |
#tags ⇒ Hash{String => String} (readonly)
Returns user-defined key-value tags.
92 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 92 attr_reader :id, :channel, :metadata, :body, :tags, :attributes |
Instance Method Details
#ack ⇒ void
This method returns an undefined value.
Acknowledges this message within the poll transaction.
119 120 121 122 123 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 119 def ack raise TransactionError, 'No downstream receiver bound' unless @action_proc @action_proc.call(:AckRange, sequence_range: [@sequence]) end |
#reject ⇒ void
This method returns an undefined value.
Rejects (negative-acknowledges) this message. The broker may redeliver it to another consumer or move it to a dead-letter queue.
130 131 132 133 134 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 130 def reject raise TransactionError, 'No downstream receiver bound' unless @action_proc @action_proc.call(:NAckRange, sequence_range: [@sequence]) end |
#requeue(channel:) ⇒ void
This method returns an undefined value.
Requeues this message to a different channel.
141 142 143 144 145 |
# File 'lib/kubemq/queues/queue_message_received.rb', line 141 def requeue(channel:) raise TransactionError, 'No downstream receiver bound' unless @action_proc @action_proc.call(:ReQueueRange, channel: channel, sequence_range: [@sequence]) end |