Class ConsumerSpec
.consumers(c -> c
.concurrency(8)
.prefetch(100)
.handlerTime(Duration.ofMillis(2)))
handlerTime(Duration) is the part people leave out and then wonder why the results
do not resemble production. A consumer that does nothing measures the broker; a consumer that
sleeps two milliseconds measures the broker and what happens when the application is
the slow part — which is the situation almost every real system is in.
-
Method Summary
Modifier and TypeMethodDescriptionintconcurrency(int concurrency) doublefailureRate(double fraction) A fraction of messages the handler rejects.handlerTime(Duration handlerTime) Simulated work per message.booleannone()Runs with no consumers at all.pipeline()pipeline(List<PipelineStage> steps) pipeline(PipelineStage... steps) Consumes through the library's pipeline: one queue, one consumer group, per step.intprefetch()prefetch(int prefetch) How many unacknowledged messages a consumer will hold.org.acemq.amqp.api.RetryPolicyretry()retry(org.acemq.amqp.api.RetryPolicy policy) Retries a failed handler on the library's ladder instead of dead-lettering it at once.saga()Runs the library's saga for every consumed message.toString()
-
Method Details
-
concurrency
- Parameters:
concurrency- how many consumers to attach- Returns:
- this spec
-
prefetch
How many unacknowledged messages a consumer will hold.The most consequential number here, and the one most often left at a default that is wrong in both directions. Too low and the consumer waits on the network between messages; too high and one consumer takes the whole queue while its peers idle, and a restart redelivers all of it.
- Parameters:
prefetch- the limit, or 0 for unlimited- Returns:
- this spec
-
handlerTime
Simulated work per message.Implemented as a sleep, which models a handler waiting on a database or an HTTP call — the common case. It does not model a handler that is CPU-bound, because a sleeping thread does not compete for a core the way a busy one does.
- Parameters:
handlerTime- how long each message takes to process- Returns:
- this spec
-
failureRate
A fraction of messages the handler rejects.For exercising retry and dead-lettering under load, which is where those paths behave least like they do in a unit test.
- Parameters:
fraction- between 0 and 1- Returns:
- this spec
-
none
Runs with no consumers at all.A publish-only workload. Useful for measuring ingest and for filling a queue before a separate drain test — and note that end-to-end latency cannot be measured without a consumer, so the report will say so rather than showing zeroes.
- Returns:
- this spec
-
concurrency
public int concurrency() -
prefetch
public int prefetch() -
handlerTime
-
failureRate
public double failureRate() -
isEnabled
public boolean isEnabled() -
retry
Retries a failed handler on the library's ladder instead of dead-lettering it at once.With
failureRate(double)this is the retry ladder under load: each delivery fails with that probability, a failure goes round again after the policy's wait (in the consumer below its broker threshold, in a{queue}.retry.{delay}rung at or above it), and the last attempt's failure goes to{queue}.dlq. End-to-end latency is measured to the delivery that succeeded, so it includes every wait. A message counts as consumed once, when it succeeds or is dead-lettered.- Parameters:
policy- the schedule, for exampleRetryPolicy.fixed(3, Duration.ofMillis(200))- Returns:
- this spec
-
retry
public org.acemq.amqp.api.RetryPolicy retry()- Returns:
- the retry policy, or null when a failure is dead-lettered on its first attempt
-
saga
Runs the library's saga for every consumed message.End-to-end latency is measured once the saga has finished, compensations included, so it carries what a failed saga costs to undo. A message counts as consumed once, whatever the saga's outcome:
Saga.runreports a failure rather than throwing it.- Parameters:
load- the saga's shape- Returns:
- this spec
-
saga
- Returns:
- the saga each message runs, or null
-
pipeline
Consumes through the library's pipeline: one queue, one consumer group, per step.The pipeline is named after the topology's queue. That name is its exchange, and each step's queue is
{name}.{step}; the publishers send to the first step. A message counts as consumed once, where its run ends: at the last step, at a step that ended it early, or at the step that dead-lettered it.- Parameters:
steps- the steps, in order- Returns:
- this spec
-
pipeline
- Parameters:
steps- the steps, in order- Returns:
- this spec
- See Also:
-
pipeline
- Returns:
- the pipeline's steps, empty when there is no pipeline
-
toString
-