PHPackages                             gdbots/pbjx - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. gdbots/pbjx

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gdbots/pbjx
===========

Messaging tools for pbj.

v4.2.0(2y ago)027.9k↓50%14Apache-2.0PHPPHP &gt;=8.1

Since Apr 19Pushed 2y ago5 watchersCompare

[ Source](https://github.com/gdbots/pbjx-php)[ Packagist](https://packagist.org/packages/gdbots/pbjx)[ RSS](/packages/gdbots-pbjx/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (47)Used By (4)

pbjx-php
========

[](#pbjx-php)

This library provides the messaging tools for [Pbj](https://github.com/gdbots/pbj-php).

> **Pbj** stands for "Private Business Json". **Pbjc** stands for "Private Business Json Compiler", a tool that creates php classes from a schema configuration. **Pbjx** stands for "Private Business Json Exchanger", a tool that exchanges pbj through various transports and storage engines.

Using this library assumes that you've already created and compiled your own pbj classes using the [Pbjc](https://github.com/gdbots/pbjc-php).

Pbjx Primary Methods
====================

[](#pbjx-primary-methods)

- **send:** asynchronous message delivery to a single recipient with no return payload.
- **publish:** asynchronous message broadcast which can be subscribed to.
- **request:** synchronous message delivery to a single recipient with an expected return payload.

If you have configured the *scheduler* then these methods will also work:

- **sendAt:** schedules a command to send at a later time.
- **cancelJobs:** cancels previously scheduled commands by their job ids.

The strategy behind this library is similar to [GRPC](http://www.grpc.io/) and [CQRS](https://martinfowler.com/bliki/CQRS.html).

> If your project is using Symfony use the [gdbots/pbjx-bundle-php](https://github.com/gdbots/pbjx-bundle-php) to simplify the integration .

Transports
==========

[](#transports)

When pbj (aka messages) are exchanged a transport is used to perform that action. Your application/domain logic should never deal directly with the transports.

**Available transports:**

- AWS Firehose
- AWS Kinesis
- In Memory

Routers
-------

[](#routers)

Some transports require a router to determine the delivery channel (stream name, gearman channel, etc.) to route the message through. The router implementation can be fixed per type of message (command, event, request) or content specific as the pbj message itself is provided to the router.

For example:

```
interface Router
{
    public function forCommand(Message $command): string;

    ...
}
```

Pbjx::send
==========

[](#pbjxsend)

Processes a command (asynchronously if transport supports it).

When using the send method it implies that there is a single handler for that command, stated another way... if a "PublishArticle" command exists, there **MUST** be a service that handles that command.

> In the **gdbots/pbjx-bundle-php** the `SchemaCurie` is used to derive the service id.

All command handlers MUST implement `Gdbots\Pbjx\CommandHandler`.

**Example handler for a "PublishArticle" command:**

```
