PHPackages                             alexfn/nano-service - 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. alexfn/nano-service

ActiveLibrary

alexfn/nano-service
===================

This is my package nano-service

v1.7.4(2y ago)35.2k↓50%1[3 PRs](https://github.com/AlexFN/nano-service/pulls)MITPHPPHP ^8.1

Since Feb 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AlexFN/nano-service)[ Packagist](https://packagist.org/packages/alexfn/nano-service)[ Docs](https://github.com/alexfn/nano-service)[ GitHub Sponsors](https://github.com/AlexFN)[ RSS](/packages/alexfn-nano-service/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (46)Used By (0)

This is my package nano-service
===============================

[](#this-is-my-package-nano-service)

[![Latest Version on Packagist](https://camo.githubusercontent.com/97c700dd3c66933468f948ada71adaf45e29b8d1beab229ea523f4758526b329/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6578666e2f6e616e6f2d736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexfn/nano-service)[![Tests](https://camo.githubusercontent.com/22aecf3d794a2ceea37c8dba64ec99fe3d46c37170cf41c5e366f0f6e2e502e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c6578666e2f6e616e6f2d736572766963652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/alexfn/nano-service/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/d26b4666d6814b79cba3a6741d686a444dbeb341c2d790fbeb7f2d12b476fa46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6578666e2f6e616e6f2d736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexfn/nano-service)

This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/4e18589133bcfdfa3f3c6dac4b5a9a9e3f80992e14fbd5babfabfff821d41d9f/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6e616e6f2d736572766963652e6a70673f743d31)](https://spatie.be/github-ad-click/nano-service)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require alexfn/nano-service
```

Usage
-----

[](#usage)

1. Add environment variables

```
AMQP_PROJECT="project-name"

AMQP_HOST="rabbitmq-host"
AMQP_PORT="5672"
AMQP_USER="rmuser"
AMQP_PASS="rmpassword"
AMQP_VHOST="/"

# Required for the consumer
AMQP_MICROSERVICE_NAME="microservice-name"

# For publisher encryption
AMQP_PRIVATE_KEY="private-key"

# For message getters
AMQP_PUBLIC_KEY="public-key"
```

2. Create message

```
$message = new NanoServiceMessage(
    // Body data
    [
        'key' => 'Value',
    ],
    // Message property (Optional)
    [
        'content_type' => 'text/json',
        'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
    ]
);

$message->addPayload([
    'key1' => 'Value 1',
    'key2' => 'Value 2',
]);
```

3. Publish message

```
$message = (new NanoServiceMessage())
    ->addPayload([
        'key' => 'Value',
    ]);

(new NanoPublisher())
    ->setMessage($message)
    ->publish('event-name');
```

4. Consume messages

```
$consumer = new NanoConsumer();
$consumer
    ->events('event-one', 'event-two')
    ->consume(function (NanoServiceMessage $message) {
        $payload = $message->getPayload();// array
    });
```

Additional message methods
--------------------------

[](#additional-message-methods)

```
$message = (new NanoServiceMessage())
    ->addPayload([
        'key' => 'Value',
    ]);
```

```
$message = (new NanoServiceMessage())
    ->addMeta([
        'key' => 'Value',
    ]);
```

```
$message->getPayload();
$message->getPayloadAttribute('key');
$message->getPayloadAttribute('key', 'default_value');
$message->addPayload([]);
$message->getPayloadAttribute('attribute', []);

$message->getMeta();
$message->getMetaAttribute('key');
$message->getMetaAttribute('key', 'default_value');
$message->addMeta([]);
$message->getMetaAttribute('attribute', []);

$message->getStatusCode(); // Default 'unknown'
$message->setStatusCode('success');
$message->getStatusData(); // Default []
$message->setStatusData([]);
```

Encrypting data using private/public keys
-----------------------------------------

[](#encrypting-data-using-privatepublic-keys)

```
// Encrypting a message with a private key
$message = (new NanoServiceMessage())
    ->setEncryptedAttribute('attribute', 'My secret data');
```

```
// Decrypting with the public key
$message->getEncryptedAttribute('attribute'); // My secret data
```

### Replace attributes

[](#replace-attributes)

```
$message = (new NanoServiceMessage())
    ->addPayload([
        'key1' => 'Value 1',
        'key2' => 'Value 2',
    ])
    ->addPayload([
        'key1' => 'New value 1',
        'key3' => 'New value 3',
    ]);

// Result: {"key1":"Value 1","key2":"Value 2","key3":"New value 3"}
```

```
$message = (new NanoServiceMessage())
    ->addPayload([
        'key1' => 'Value 1',
        'key2' => 'Value 2',
    ])
    ->addPayload(
        [
            'key1' => 'New value 1',
            'key3' => 'New value 3',
        ],
        true
    );

// Result: {"key1":"New value 1","key2":"Value 2","key3":"New value 3"}
```

```
$message = (new NanoServiceMessage())
    ->setStatusData([
        'key1' => 'Value 1',
        'key2' => 'Value 2',
    ])
    ->setStatusData(
        [
            'key1' => 'New value 1',
            'key3' => 'New value 3',
        ],
        true
    );

// Result: {"key1":"New value 1","key3":"New value 3"}
```

Debug mode
----------

[](#debug-mode)

```
$message->setDebug();

(new NanoPublisher())
    ->setMessage($message)
    ->publish('event-name');

```

```
$consumer
    ->events('event-name')
    ->consume($callback, function (NanoServiceMessage $message) {
        // debugCallback (Optional)
    });

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Alexander O.](https://github.com/AlexFN)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 98.2% 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 ~11 days

Recently: every ~27 days

Total

43

Last Release

742d ago

PHP version history (3 changes)v1.0.0PHP ^7.2 || ^8.1

v1.6.3PHP ^7.4 || ^8.1

v1.6.12PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc22541a34e0c80a9836a16b13ed7945b5a39cf7e93aa6bfe2219d9712d7b30f?d=identicon)[AlexFN](/maintainers/AlexFN)

---

Top Contributors

[![falkon](https://avatars.githubusercontent.com/u/576750?v=4)](https://github.com/falkon "falkon (56 commits)")[![AlexFN](https://avatars.githubusercontent.com/u/49072623?v=4)](https://github.com/AlexFN "AlexFN (1 commits)")

---

Tags

AlexFNnano-service

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alexfn-nano-service/health.svg)

```
[![Health](https://phpackages.com/badges/alexfn-nano-service/health.svg)](https://phpackages.com/packages/alexfn-nano-service)
```

###  Alternatives

[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

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

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)[oxid-esales/graphql-base

OXID eSales GraphQL base module

24101.0k10](/packages/oxid-esales-graphql-base)

PHPackages © 2026

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