PHPackages                             bowphp/microservice - 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. [API Development](/categories/api)
4. /
5. bowphp/microservice

ActiveLibrary[API Development](/categories/api)

bowphp/microservice
===================

NestJS-style multi-transport microservice layer for BowPHP (TCP, Redis, RabbitMQ, Kafka, gRPC).

1.1.0(2mo ago)1397↓81.5%MITPHPPHP &gt;=8.1

Since May 21Pushed 1w agoCompare

[ Source](https://github.com/bowphp/microservice)[ Packagist](https://packagist.org/packages/bowphp/microservice)[ RSS](/packages/bowphp-microservice/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (6)Versions (4)Used By (0)

bowphp/microservice
===================

[](#bowphpmicroservice)

A NestJS-style, multi-transport microservice layer for **BowPHP**. One handler API, five transports: **TCP**, **Redis** (pub/sub), **RabbitMQ** (AMQP), **Kafka**, and **gRPC** (client only).

The design mirrors NestJS: you write *controllers* whose methods carry `#[MessagePattern]` (request/response) or `#[EventPattern]` (fire-and-forget) attributes, then run a consumer that listens on a transport. Callers use a `ClientProxy` with `send()` / `emit()`. The transport only moves bytes — your handlers never change when you switch protocols.

> 📖 Full user guide: [docs/en.md](docs/en.md) — French version: [docs/fr.md](docs/fr.md)

Architecture
------------

[](#architecture)

The package is a **framework-agnostic core** with a thin BowPHP adapter:

```
Contracts/         ServerTransport, ClientTransport, Serializer  (the seams)
Message/           Packet, ResponsePacket, JsonSerializer        (wire format)
Consumer/          MicroserviceServer, HandlerRegistry,
                   MessagePattern, EventPattern, MicroserviceFactory
Client/            ClientProxy, ClientFactory
Transport/         {Tcp,Redis,RabbitMq,Kafka}{Server,Client}Transport
                   GrpcClientTransport + Grpc/ (envelope, stub, codec)
Bow/               MicroserviceConfiguration  (the ONLY Bow-coupled file)

```

Every transport implements the same two contracts, so adding a sixth (NATS, MQTT, etc.) means writing one server + one client class — nothing else moves.

### The envelope

[](#the-envelope)

All transports share one packet shape (like Nest's `{ pattern, data, id }`):

- **RPC**: request `Packet` → handler return value → `ResponsePacket`, matched back to the caller by `id`.
- **Event**: `Packet` with no reply.

How each transport correlates replies:

TransportRPC reply mechanismTCPsame socket, 4-byte length-prefixed JSON framesRedisPUBLISH on `pattern` → RPUSH on `bow:reply:`RabbitMQ`reply_to` queue + `correlation_id`Kafkareply topic + `kafka_correlationId` headergRPCunary `MessageService.Send` returns MessageEnvelopeInstall
-------

[](#install)

```
composer require bowphp/microservice
```

Then install the extension/library for the transport(s) you use:

- TCP → `ext-sockets` (built in on most PHP)
- Redis → `ext-redis` (phpredis)
- RabbitMQ → `composer require php-amqplib/php-amqplib`
- Kafka → `ext-rdkafka`
- gRPC (client) → `pecl install grpc && composer require grpc/grpc google/protobuf`

Define handlers
---------------

[](#define-handlers)

```
use Bow\Microservice\Consumer\MessagePattern;
use Bow\Microservice\Consumer\EventPattern;
use Bow\Microservice\Message\Packet;

final class UserController
{
    #[MessagePattern('user.find')]
    public function find(mixed $data, Packet $packet): array
    {
        return ['id' => $data['id'], 'name' => "User #{$data['id']}"];
    }

    #[EventPattern('user.created')]
    public function onCreated(mixed $data): void
    {
        // send welcome email, etc.
    }
}
```

Run the consumer
----------------

[](#run-the-consumer)

Two equivalent entrypoints — the BowPHP-integrated console command (recommended) and a standalone script:

```
# BowPHP console command — registered automatically by MicroserviceConfiguration
php bow microservice:listen --transport=redis    --patterns=user.find,user.created
php bow microservice:listen --transport=tcp      --host=0.0.0.0 --port=3000
php bow microservice:listen --transport=rabbitmq --queue=bow_microservice
php bow microservice:listen --transport=kafka    --topics=user_events --group=users

# Standalone script — no Bow integration required
php examples/microservice.php --transport=redis --patterns=user.find
```

Both honour `config/microservice.php`; CLI flags override config. They install SIGTERM/SIGINT handlers (when `ext-pcntl` is available) so supervisord / systemd / Kubernetes can drain a worker cleanly. Run N copies for concurrency.

Call from another service
-------------------------

[](#call-from-another-service)

```
use Bow\Microservice\Client\ClientFactory;

$proxy = ClientFactory::create('redis', ['host' => '127.0.0.1']);
$proxy->connect();

$user = $proxy->send('user.find', ['id' => 42]); // RPC, blocks for reply
$proxy->emit('user.created', ['id' => 99]);       // fire-and-forget

// gRPC client to a non-PHP server implementing proto/microservice.proto
$grpc = ClientFactory::create('grpc', ['host' => '127.0.0.1', 'port' => 50051]);
$grpc->connect();
$grpc->send('user.find', ['id' => 42]);
```

BowPHP integration
------------------

[](#bowphp-integration)

Register the configuration provider in your Kernel so a connected `ClientProxy`is bound in the container:

```
// app/Kernel.php
public function configurations(): array
{
    return [
        \Bow\Microservice\Bow\MicroserviceConfiguration::class,
    ];
}
```

Add `config/microservice.php` to your app (see this repo's [`config/microservice.php`](config/microservice.php) for the template). The provider binds both `ClientProxy::class` and the `microservice.client` alias.

Both consumer entrypoints (`php bow microservice:listen` and `php examples/microservice.php`) boot the kernel and instantiate controllers through Bow's container — so your consumers can use constructor DI just like HTTP controllers. List them in `config('microservice.controllers')` or pass `--controllers=A,B` on the CLI. The standalone script also accepts `--kernel=` (or `MICROSERVICE_KERNEL`) to point at a custom Kernel class.

Notes &amp; limits
------------------

[](#notes--limits)

- The TCP server handles one connection at a time per process — run multiple workers behind a balancer, or swap in an event-loop driver later (the framing is unchanged).
- Kafka has no native RPC; the reply-topic approach matches NestJS. For pure event streaming, use `emit()` only.
- The default serializer is JSON. Implement `Serializer` for msgpack/protobuf.
- Handler exceptions become an error `ResponsePacket`; the client re-throws them as `RpcException`. Events swallow-and-log errors (no caller to notify).
- **gRPC is client-only.** The `grpc` PHP extension provides no server API and a production-grade PHP gRPC server requires RoadRunner or Swoole, neither of which fits the single-process consumer model here. Implement the server side in any language with a real gRPC server following [proto/microservice.proto](proto/microservice.proto) — PHP services call it through `GrpcClientTransport`.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance93

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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

Every ~1 days

Total

3

Last Release

62d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/96099e66c63e31445f3f76a12e94104030f504eeb18f007216bb4ebdcdeadf7f?d=identicon)[papac](/maintainers/papac)

---

Top Contributors

[![papac](https://avatars.githubusercontent.com/u/9353811?v=4)](https://github.com/papac "papac (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bowphp-microservice/health.svg)

```
[![Health](https://phpackages.com/badges/bowphp-microservice/health.svg)](https://phpackages.com/packages/bowphp-microservice)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M162](/packages/algolia-algoliasearch-client-php)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)[keboola/storage-api-client

Keboola Storage API PHP Client

10405.9k40](/packages/keboola-storage-api-client)

PHPackages © 2026

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