Class: AceMQ::AMQP::Patterns::StreamOffset

Inherits:
Object
  • Object
show all
Defined in:
lib/acemq/amqp/patterns/streams.rb

Overview

Where a stream consumer starts reading.

A value object rather than a bare string because two of the five are not strings — an exact offset is a number and a timestamp is a time — and a caller passing the wrong one gets an error from the broker that does not mention streams.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, value = nil) ⇒ StreamOffset

Returns a new instance of StreamOffset.



37
38
39
40
41
# File 'lib/acemq/amqp/patterns/streams.rb', line 37

def initialize(kind, value = nil)
  @kind = kind
  @value = value
  freeze
end

Instance Attribute Details

#kind ⇒ Object (readonly)

Returns the value of attribute kind.



35
36
37
# File 'lib/acemq/amqp/patterns/streams.rb', line 35

def kind
  @kind
end

#value ⇒ Object (readonly)

Returns the value of attribute value.



35
36
37
# File 'lib/acemq/amqp/patterns/streams.rb', line 35

def value
  @value
end

Class Method Details

.at(offset) ⇒ Object

An exact position, which is what a consumer that records its own progress uses to carry on where it left off.



60
# File 'lib/acemq/amqp/patterns/streams.rb', line 60

def self.at(offset) = new("offset", offset)

.first ⇒ Object

The oldest message the stream still holds.

For building a projection from scratch, or a new consumer that needs the history. "Still holds" matters: a stream has a retention policy, and its oldest message is not necessarily the first one ever written.



48
# File 'lib/acemq/amqp/patterns/streams.rb', line 48

def self.first = new("first")

.last ⇒ Object

The last chunk the stream holds, which is roughly "the recent past" rather than an exact number of messages.



56
# File 'lib/acemq/amqp/patterns/streams.rb', line 56

def self.last = new("last")

.next ⇒ Object

The next message published, ignoring everything already there. The default, and what most consumers want.



52
# File 'lib/acemq/amqp/patterns/streams.rb', line 52

def self.next = new("next")

.since(time) ⇒ Object

The first message published at or after a time.



63
# File 'lib/acemq/amqp/patterns/streams.rb', line 63

def self.since(time) = new("timestamp", time)

Instance Method Details

#to_argument ⇒ Object

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.

What the broker is told.



68
# File 'lib/acemq/amqp/patterns/streams.rb', line 68

def to_argument = @value.nil? ? @kind : @value

#to_s ⇒ Object



70
# File 'lib/acemq/amqp/patterns/streams.rb', line 70

def to_s = @value.nil? ? @kind : "#{@kind}(#{@value})"