Package org.acemq.amqp.core
Class StreamReader<T>
java.lang.Object
org.acemq.amqp.core.StreamReader<T>
- Type Parameters:
T- payload type
Says where to start reading a stream, and then starts.
mq.stream("orders.log", OrderPlaced.class)
.fromFirst()
.prefetch(200)
.consume(message -> projection.apply(message.payload()));
mq.stream("orders.log", OrderPlaced.class)
.fromLast(Duration.ofHours(1))
.consume(message -> dashboard.show(message.payload()));
mq.stream("orders.log", OrderPlaced.class)
.fromOffset(resumeFrom)
.consume(message -> ledger.post(message.payload()));
Nothing happens until consume(org.acemq.amqp.api.MessageHandler<T>). Every other method returns a new reader, so a
half-built one can be passed around, kept as a field, or reused for two consumers reading the
same stream from different places.
-
Method Summary
Modifier and TypeMethodDescriptionconsume(MessageHandler<T> handler) Starts reading.from(StreamOffset offset) fromLast()fromNext()fromOffset(long offset) prefetch(int prefetch) Carries on past a message whose handler failed, counting it.toString()
-
Method Details
-
fromFirst
- Returns:
- a reader starting at the oldest message the stream still holds. On a stream with a year of history this reads the year, which is sometimes exactly right
-
fromLast
- Returns:
- a reader starting at the last chunk the stream holds, and everything after it
-
fromNext
- Returns:
- a reader taking only messages written after it attaches; the default
-
fromOffset
- Parameters:
offset- the exact position, normally one past the last offset recorded as handled- Returns:
- a reader resuming there
-
from
- Parameters:
timestamp- the moment to start from- Returns:
- a reader starting at the first message written at or after it
-
fromLast
- Parameters:
age- how far back to begin- Returns:
- a reader replaying that period and then continuing live
-
from
- Parameters:
offset- where to start- Returns:
- a reader starting there
-
prefetch
- Parameters:
prefetch- how many unacknowledged messages the broker may keep in flight- Returns:
- a reader with that prefetch
-
skipFailures
Carries on past a message whose handler failed, counting it.The alternative to stopping, and the one to think about. Nothing else will report the gap;
StreamConsumer.skipped()is the only record that it happened.- Returns:
- a reader that skips failures
-
as
- Parameters:
codec- the format to read with, for formats whose bytes describe nothing- Returns:
- a reader using that codec
-
consume
Starts reading.- Parameters:
handler- called for each message in offset order; returning normally advances the position, throwing applies the failure policy- Returns:
- the running consumer, closed automatically when the connection closes
-
toString
-