PHPackages                             butschster/lumen-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. [Queues &amp; Workers](/categories/queues)
4. /
5. butschster/lumen-microservice

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

butschster/lumen-microservice
=============================

This Package will help you to use Lumen framework as a microservice with AMQP and JMS Serializer without extra knowledge.

1.22.1(5y ago)57662MITPHPPHP ^7.4

Since Oct 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/butschster/LumenMicroservice)[ Packagist](https://packagist.org/packages/butschster/lumen-microservice)[ RSS](/packages/butschster-lumen-microservice/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (19)Versions (14)Used By (0)

Lumen Microservice
==================

[](#lumen-microservice)

[![Build Status](https://camo.githubusercontent.com/555acc2c2e2d3781715d7a7e4c84a19d198b2bf1c01f70c216ba49ed6793b9f9/68747470733a2f2f7472617669732d63692e6f72672f627574736368737465722f4c756d656e4d6963726f736572766963652e737667)](https://travis-ci.org/butschster/LumenMicroservice) [![Latest Stable Version](https://camo.githubusercontent.com/d31418cf54df1bbecd57c8846b77764a79f180be6558ac7097fd0bfc11b6e8a9/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6c756d656e2d6d6963726f736572766963652f762f737461626c65)](https://packagist.org/packages/butschster/lumen-microservice) [![Total Downloads](https://camo.githubusercontent.com/a7ea9ca1dde7ee64526d75b3ed9e2bb26c78a98eefdb5e831173e255c2219b47/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6c756d656e2d6d6963726f736572766963652f646f776e6c6f616473)](https://packagist.org/packages/butschster/lumen-microservice) [![License](https://camo.githubusercontent.com/ed39f3700d29465fd740a2c18b9bdb17b0da97688e4acb9d535741e238270650/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6c756d656e2d6d6963726f736572766963652f6c6963656e7365)](https://packagist.org/packages/butschster/lumen-microservice)[![heading](https://user-images.githubusercontent.com/773481/96422465-b6bbe800-1200-11eb-914a-8c2c150d80eb.jpg)](https://user-images.githubusercontent.com/773481/96422465-b6bbe800-1200-11eb-914a-8c2c150d80eb.jpg)

This Package can help you to use Lumen framework or Laravel as a microservice without extra knowledge. Just install package, create Exchange Point class and start exchanging information between services through MQ.

This package uses [JMS\\Serializer](https://github.com/schmittjoh/serializer) for message serialization.

*P.S. You can use this service for testing . They have a free plan.*

Features
--------

[](#features)

- Easy to use out of the box
- Easy to configure
- jms serializer
- Uses MQ out of the box
- Well tested

Requirements
------------

[](#requirements)

- Lumen or Laravel 7.x to 8.x
- PHP 7.4 and above

Installation and Configuration
------------------------------

[](#installation-and-configuration)

From the command line run

`composer require butschster/lumen-microservice`

#### Register Service provider

[](#register-service-provider)

```
// bootstrap.php
$app->register(Butschster\Exchanger\Providers\ExchangeServiceProvider::class);
```

#### Copy config files from package `config` directory to your Lumen app and register them.

[](#copy-config-files-from-package-config-directory-to-your-lumen-app-and-register-them)

```
$app->configure('amqp');
$app->configure('microservice');
$app->configure('serializer');
```

#### Add variables to your .env file

[](#add-variables-to-your-env-file)

```
MICROSERVICE_NAME=...
MICROSERVICE_VERSION=1.0.0
RABBITMQ_HOST=...
RABBITMQ_USERNAME=...
RABBITMQ_PASSWORD=...
RABBITMQ_VHOST=...
JWT_SECRET=...

```

#### Create exchange point in your app

[](#create-exchange-point-in-your-app)

This point will use for receiving request from other services and for sending responses.

```
namespace App\Exchange\Point;

use Butschster\Exchanger\Contracts\Exchange\Point as PointContract;
use Psr\Log\LoggerInterface;
use Butschster\Exchanger\Contracts\Exchange\IncomingRequest;

class Point implements PointContract
{
    public function getName(): string
    {
        return 'com.test';
    }

    /**
     * @subject com.test.action.test
     */
    public function testSubject(IncomingRequest $request, LoggerInterface $logger)
    {
        $logger->info(
            sprintf('info [%s]:', $request->getSubject()),
            [$request->getBody()]
        );

        // Response
        $payload = new ...;
        $request->sendResponse($payload);

        // or
        $request->sendEmptyResponse();

        // or
        $request->acknowledge();
    }

    /**
     * @subject com.test.action.test1
     */
    public function anotherTestSubject(IncomingRequest $request, LoggerInterface $logger)
    {
        $payload = new ...;
        $request->sendResponse($payload);
    }
}
```

Then register this point

```
use App\Exchange\Point;
use Illuminate\Support\ServiceProvider;
use Butschster\Exchanger\Contracts\Exchange\Point as PointContract;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(PointContract::class, Point::class);
    }
}
```

#### Register console command

[](#register-console-command)

```
use Butschster\Exchanger\Console\Commands\RunMicroservice;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        RunMicroservice::class
    ];
}
```

#### Sending requests

[](#sending-requests)

For requesting information from another service you should use `ExchangeManager`

```
use Butschster\Exchanger\Contracts\ExchangeManager;

class UserController {

    public function getUser(ExchangeManager $manager, int $userId)
    {
        $requestPayload = new GetUserByIdPayload($userId);

        $request = $manager->request('com.test.action.test', $requestPayload);
        $user = $request->send(UserPayload::class);

        // You can set delivery mode to persistent
        $user = $request->send(UserPayload::class, true);
    }
}

// User Request Payload

use JMS\Serializer\Annotation\Type;

class GetUserByIdPayload implements \Butschster\Exchanger\Contracts\Exchange\Payload
{
    /** @Type("string") */
    public string $userId;
    public function __construct(string $userId)
    {
        $this->userId = $userId;
    }
}

// User Payload

use JMS\Serializer\Annotation\Type;

class UserPayload implements \Butschster\Exchanger\Contracts\Exchange\Payload
{
    /** @Type("string") */
    public string $id;

    /** @Type("string") */
    public string $username;

    /** @Type("string") */
    public string $email;

    /** @Type("Carbon\Carbon") */
    public \Carbon\Carbon $createdAt;
}
```

#### Broadcasting

[](#broadcasting)

If you want to send an event you should use `ExchangeManager` method `broadcast`

```
use Illuminate\Http\Request;
use Butschster\Exchanger\Contracts\ExchangeManager;

class UserController {

    public function update(ExchangeManager $manager, Request $request, User $user)
    {
        $payload = new UserPayload();
        $data = $request->validate(...);
        $user->update($data);

        $payload->id = $user->id;
        $payload->username = $user->username;
        ...

        $manager->broadcast('com.user.event.updated', $payload);

        // You can set delivery mode to persistent
        $manager->broadcast('com.user.event.updated', $payload, true);
    }
}
```

#### Entity mapping

[](#entity-mapping)

You can configure entity mapping in `serializer.php` config.

```
// serializer.php
return [
    'mapping' => [
        Domain\User\Entities\User::class => [
            'to' => Payloads\User::class,
            'attributes' => [
                'id' => ['type' => 'string'],
                'username' => ['type' => 'string'],
                'email' => ['type' => 'string'],
                'balance' => ['type' => Domain\Billing\Money\Token::class],
                'createdAt' => ['type' => \Carbon\Carbon::class],
            ]
        ],
        Domain\Billing\Money\Token::class => [
            'to' => Payloads\Billing\Token::class,
            'attributes' => [
                'amount' => ['type' => \Brick\Math\BigDecimal::class],
            ]
        ],
    ],
    // ...
];
```

And then you can easily convert entities to payloads

```
use Butschster\Exchanger\Contracts\Serializer\ObjectsMapper;

class UserController {

    public function update(ObjectsMapper $mapper, ExchangeManager $manager, Request $request, Domain\User\Entities\User $user)
    {
        $data = $request->validate(...);
        $user->update($data);

        $payload = $mapper->toPayload($user);

        $manager->broadcast('com.user.event.updated', $payload);
    }
}
```

#### Custom types

[](#custom-types)

If you want to use custom JMS Serializer types you should use handlers. They can be added in `serializer.php` config.

```
// serializer.php
return [
    'handlers' => [
        Butschster\Exchanger\Jms\Handlers\CarbonHandler::class,
        Infrastructure\Microservice\Jms\Handlers\BigDecimalHandler::class
    ],
    // ..
];

// BigDecimalHandler.php

namespace Infrastructure\Microservice\Jms\Handlers;

use Brick\Math\BigDecimal;
use Butschster\Exchanger\Contracts\Serializer;
use Butschster\Exchanger\Contracts\Serializer\Handler;
use JMS\Serializer\GraphNavigatorInterface;
use JMS\Serializer\Handler\HandlerRegistryInterface;

class BigDecimalHandler implements Handler
{
    public function serialize(Serializer $serializer, HandlerRegistryInterface $registry): void
    {
        $registry->registerHandler(
            GraphNavigatorInterface::DIRECTION_SERIALIZATION,
            BigDecimal::class,
            'json',
            function ($visitor, BigDecimal $value, array $type) {
                return $value->toInt();
            }
        );
    }

    public function deserialize(Serializer $serializer, HandlerRegistryInterface $registry): void
    {
        $registry->registerHandler(
            GraphNavigatorInterface::DIRECTION_DESERIALIZATION,
            BigDecimal::class,
            'json',
            function ($visitor, $value, array $type) {
                return BigDecimal::of($value);
            }
        );
    }
}
```

#### Service running

[](#service-running)

This single command will run your microservice and start listening to commands registered in your exchange point.

`php artisan service:run`

Supervisor is a process monitor for the Linux operating system, and will automatically restart your horizon process if it fails. To install Supervisor on Ubuntu, you may use the following command:

`sudo apt-get install supervisor`

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a microservice.conf file that starts and monitors a process:

```
[program:microservice]
process_name=%(program_name)s
command=php /var/www/app.com/artisan service:run
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/www/app.com/storage/logs/microservice.log
stopwaitsecs=3600

```

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

```
sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start microservice

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~9 days

Total

11

Last Release

1935d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/773481?v=4)[Pavel Buchnev](/maintainers/butschster)[@butschster](https://github.com/butschster)

---

Top Contributors

[![butschster](https://avatars.githubusercontent.com/u/773481?v=4)](https://github.com/butschster "butschster (37 commits)")

---

Tags

amqpjms-serializerlaravellaravel8lumenlumen-frameworkmicroservicemqphprabbitmqevent-looplumenrabbitmqAMQPjms-serializerMicroservicelumen-framework

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M368](/packages/laravel-zero-framework)[propaganistas/laravel-disposable-email

Disposable email validator

5762.6M6](/packages/propaganistas-laravel-disposable-email)[vinelab/bowler

A Rabbitmq wrapper for Laravel

4659.7k1](/packages/vinelab-bowler)

PHPackages © 2026

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