PHPackages                             tetthys/pie-minimal-batcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. tetthys/pie-minimal-batcher

ActiveLibrary[Queues &amp; Workers](/categories/queues)

tetthys/pie-minimal-batcher
===========================

Ultra-minimal, bank-agnostic sharded batcher with RabbitMQ 4.1 and per-identity cooldown.

0.0.1(7mo ago)03MITPHPPHP ^8.2

Since Sep 19Pushed 7mo agoCompare

[ Source](https://github.com/tetthys/pie-minimal-batcher)[ Packagist](https://packagist.org/packages/tetthys/pie-minimal-batcher)[ RSS](/packages/tetthys-pie-minimal-batcher/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

pie-minimal-batcher
===================

[](#pie-minimal-batcher)

A **minimal PHP batching system** built on RabbitMQ. It shards messages across workers, applies per-identity cooldowns, and flushes batches on fixed-time windows.

Ideal for payout / withdrawal pipelines or any workload that benefits from **sharded batch processing with cooldown logic**.

---

✨ Features
----------

[](#-features)

- **RabbitMQ publisher &amp; consumer**

    - Direct exchange: `payout.direct`
    - Shard queues: `payout.shard.{id}`
    - Publisher confirms enabled (guaranteed delivery)
    - Optional quorum queues for durability
- **Worker**

    - Processes 1 shard at a time
    - Drains up to 256 msgs per tick
    - Filters by cooldown (per identity)
    - Flushes only on **fixed window rotation**
    - Custom sinks via `BatchSinkInterface`
- **Cooldown Registry**

    - Backed by SQLite (`pdo_sqlite`)
    - Expired entries auto-cleaned
- **Laravel Integration**

    - `PieServiceProvider` + `Pie` facade
    - `publish()`, `setCooldown()`, `tick()` exposed
    - Uses `storage/app/pie` for state &amp; output
- **Dockerized**

    - Comes with `docker-compose.yaml`
    - Scripts for RabbitMQ setup, worker launch, demo publishing

---

🚀 Quickstart (Docker)
---------------------

[](#-quickstart-docker)

1. **Start services &amp; install deps**

    ```
    bash run/up.sh
    ```
2. **Initialize RabbitMQ**

    ```
    bash run/init-rabbit.sh
    ```

    Creates `/pie` vhost and `pie_user/pie_pass` with limited rights.
3. **Start 10 shard workers**

    ```
    bash run/workers.sh
    ```
4. **Publish demo messages**

    ```
    bash run/publish-demo.sh        # 50 messages
    bash run/publish-demo.sh 200    # 200 messages
    ```
5. **Check outputs**Look in `var/out_shard_*.ndjson` for summaries like:

    ```
    {"shard":3,"window_start":1700000000,"window_sec":3600,"count":42}
    ```

---

📦 Usage in Your Own Code
------------------------

[](#-usage-in-your-own-code)

### Publisher

[](#publisher)

```
$conn = new RabbitConnection($host, $port, $user, $pass, $vhost);
$pub  = new RabbitPublisher($conn, 'payout.direct');

$identity = 'ACC-12345';
$shard = abs(crc32($identity)) % 10;

$pub->publish([
  'identity' => $identity,
  'payload'  => ['amount_minor' => 12500],
  'uuid'     => bin2hex(random_bytes(8)),
], "shard-$shard");
```

### Worker

[](#worker)

```
$consumer = new RabbitConsumer($conn, 'payout.direct', "payout.shard.$id", "shard-$id", 100, false);
$sink     = new FileLogSink(__DIR__."/var/out_shard_{$id}.ndjson");
$cool     = new SqliteCooldownRegistry(__DIR__.'/var/cooldowns.sqlite');
$worker   = new ShardedBatchWorker($id, $consumer, $sink, $cool, new SystemClock(), 3600);

while (true) {
    $worker->tick();
    usleep(100 * 1000); // adjust polling interval
}
```

---

🕊 Laravel Integration
---------------------

[](#-laravel-integration)

1. Register the provider:

    ```
    // config/app.php
    'providers' => [
        Tetthys\Pie\Laravel\PieServiceProvider::class,
    ],
    ```
2. Use the facade:

    ```
    use Tetthys\Pie\Laravel\Facades\Pie;

    // publish a message
    Pie::publish([
      'identity' => 'ACC-12345',
      'payload'  => ['amount_minor' => 12500],
      'uuid'     => bin2hex(random_bytes(8)),
    ], 'shard-3');

    // set a cooldown (1h)
    Pie::setCooldown('ACC-12345', time() + 3600);

    // tick a shard worker
    Pie::tick(3);
    ```
3. Long-running workers Wrap `Pie::tick($shardId)` in an Artisan command loop and run it under Supervisor/systemd.

---

⚠ Notes &amp; Caveats
---------------------

[](#-notes--caveats)

- **Prefetch setting**: current consumer uses `basic_get` (polling). Prefetch has **no effect** unless converted to `basic_consume`.
- **Cooldown storage**:

    - Standalone: `var/cooldowns.sqlite`
    - Laravel: `storage/app/pie/cooldowns.sqlite`
- **Polling delay**: workers use `usleep(100–200ms)`. Adjust to balance throughput vs latency.
- **Message size**: publisher enforces **64KB limit**. Store large payloads externally.
- **Sharding**: always hash by `identity` so cooldown guarantees are shard-local.

---

✅ Best Practice Flow
--------------------

[](#-best-practice-flow)

1. **Publish** messages with identity-based shard routing.
2. **Worker** batches per shard, flushes on window boundary.
3. **Sink** executes the real action (e.g., payout API call).
4. **Cooldown** is set per identity to avoid duplicate handling.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance62

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

235d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/858f92afec0ff81e6888c9ae6f363b56ebf82e45a32d9e1b37341569c5d1b267?d=identicon)[tetthys](/maintainers/tetthys)

---

Top Contributors

[![tetthys](https://avatars.githubusercontent.com/u/115064626?v=4)](https://github.com/tetthys "tetthys (7 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/tetthys-pie-minimal-batcher/health.svg)

```
[![Health](https://phpackages.com/badges/tetthys-pie-minimal-batcher/health.svg)](https://phpackages.com/packages/tetthys-pie-minimal-batcher)
```

###  Alternatives

[vladimir-yuldashev/laravel-queue-rabbitmq

RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.

2.1k9.8M30](/packages/vladimir-yuldashev-laravel-queue-rabbitmq)[php-amqplib/rabbitmq-bundle

Integrates php-amqplib with Symfony &amp; RabbitMq. Formerly emag-tech-labs/rabbitmq-bundle, oldsound/rabbitmq-bundle.

1.3k20.1M65](/packages/php-amqplib-rabbitmq-bundle)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[enqueue/amqp-lib

Message Queue Amqp Transport

1078.5M61](/packages/enqueue-amqp-lib)[jwage/phpamqplib-messenger

Symfony messenger transport for the php-amqplib/php-amqplib library.

84149.7k1](/packages/jwage-phpamqplib-messenger)[mikemadisonweb/yii2-rabbitmq

Wrapper based on php-amqplib to incorporate messaging in your Yii2 application via RabbitMQ. Inspired by RabbitMqBundle for Symfony 2, really awesome package.

74262.1k1](/packages/mikemadisonweb-yii2-rabbitmq)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
