# RabbitMQ load test, driven by the `loadr-plugin-rabbitmq` native protocol
# plugin.
#
# RabbitMQ support is NOT built into loadr core — it is a runtime-loadable
# plugin that ships the pure-Rust `lapin` AMQP 0.9.1 client on its own. The
# plugin declares the `amqp://` / `amqps://` (and `rabbitmq://`) URL schemes, so
# once it is installed a request to one of those URLs routes straight to it; no
# explicit `protocol:` is needed.
#
# Each request runs one operation (publish/get) from its `plugin:` block. loadr
# records the operation latency in `rabbitmq_req_duration`, the count of
# messages published/consumed in `rabbitmq_msgs`, and any broker error fails the
# request (status 1 = ok, status 0 = AMQP/transport error).
#
# Build + install the plugin, then run:
#   cargo build -p loadr-plugin-rabbitmq --release
#   mkdir -p dist && cp plugins/loadr-plugin-rabbitmq/plugin.toml dist/ \
#     && cp target/release/libloadr_plugin_rabbitmq.so dist/
#   loadr plugin install dist
#   loadr run examples/32-rabbitmq.yaml
#
# Or point the plan's `plugins:` entry at the built artifact directly (below).
name: rabbitmq
description: publish + get against RabbitMQ via loadr-plugin-rabbitmq

plugins:
  # Resolve `rabbitmq` by name from the plugins dir (after `loadr plugin install`).
  # To run straight from a build tree instead, set:
  #   path: target/release/libloadr_plugin_rabbitmq.so
  - name: rabbitmq

scenarios:
  # Producers push work onto the `loadr.work` queue (the harness declares it;
  # `declare_queue: true` makes the example self-contained against any broker).
  publish:
    executor: constant-vus
    vus: 5
    duration: 15s
    flow:
      - request:
          name: publish job
          url: amqp://loadr:loadr@broker.example.com:5672/%2f
          plugin:
            operation: publish
            routing_key: loadr.work        # default exchange routes by queue name
            queue: loadr.work
            declare_queue: true
            body: '{"vu": ${vu}, "iteration": ${iteration}}'
          assert:
            - { type: status, equals: 1 }   # 1 = ok, 0 = broker error

  # Consumers drain the queue at a steady rate.
  consume:
    executor: constant-arrival-rate
    rate: 60
    duration: 15s
    pre_allocated_vus: 10
    max_vus: 40
    flow:
      - request:
          name: get job
          url: amqp://loadr:loadr@broker.example.com:5672/%2f
          plugin:
            operation: get
            queue: loadr.work
            ack: true
          checks:
            - { type: status, equals: 1 }
            - { type: duration, name: get is fast, max: 250ms }

thresholds:
  checks: [ "rate>0.99" ]
  rabbitmq_req_duration: [ "p(95)<300ms" ]
  rabbitmq_reqs: [ "count>0" ]
