Download the PHP package smskin/laravel-service-bus without Composer
On this page you can find all versions of the php package smskin/laravel-service-bus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smskin/laravel-service-bus
More information about smskin/laravel-service-bus
Files in smskin/laravel-service-bus
Package laravel-service-bus
Short Description Service bus for laravel
License MIT
Homepage https://github.com/smskin/laravel-service-bus
Informations about the package laravel-service-bus
Laravel service bus
This library provides communication between multiple services. Supports sync and async communications.
This library uses:
- https://github.com/needle-project/laravel-rabbitmq - Library for supports AMPQ. Some class was overrides for support current library logic.
- https://github.com/laravel/horizon - code base of supervisor part
Base logic
Base logic builds on package structure. This structure very similar to .Net MassTransit packages. Package contains:
- package meta
- message type
- message
Algorithm:
- Sender creates package with message
- Sender submit package to consumer
- Consumer defines requested package by message type and deserialize package
- Consumer executes logic with received package
Synchronous communications
- Sender creates package with message
- Sender submit package to consumer with synchronous method
- Library serialized package to json
- Library submits http request to consumer host
- Consumer process some logic with received package
- Consumer returns new package with response
- Sender receives response package from consumer
Asynchronous communications
Asynchronous communication provides by RabbitMQ
- Sender creates package with message
- Sender submit package to consumer with asynchronous method
- Library serialized package to json
- Library submits package to the RabbitMQ exchange
- RabbitMQ submits received package to queue
- Consumer listens RabbitMQ queue
- Consumer receives package from queue
- Consumer process some logic with received package
Installation
composer require smskin/laravel-service-bus
php artisan vendor:publish --provider="SMSkin\ServiceBus\Providers\ServiceProvider"
- Configure RabbitMQ connection in
service-bus.php
config file - Run
php artisan service-bus:setup
from initialize RabbitMQ exchanges and queues - Add service bus consumer command to the supervisor conf
Supervisor config to provides service bus consumer
Artisan commands
service-bus:setup
- command for initialize RabbitMQ exchanges and queuesservice-bus:supervisor
- service bus supervisor. Start processes for consume packages from RabbitMQ queuesservice-bus:delete-all
- command deletes exchanges and queues from RabbitMQservice-bus:list
- command lists exchanges and queuesservice-bus:publish
- command for submit test message to RabbitMQ exchange (for tests)service-bus:consume
- consumer command for receive packages from RabbitMQ queue (uses by supervisor command)
Service bus supervisor
Supervisor command run consumer process for each registered consumer (Config file service-bus.php
, section supervisor
)
Overriding default enums
You can create new enum and override calling it in service-bus.php
config file. It provides extend the default
consumers and exchanges.
For example
- Create Exchanges enum
- Extends it from base SMSkin\ServiceBus\Enums\Exchanges
- Change the
items
method for provide new exchanges - Replace default enum in
service-bus.php
config file (line 14)
Classes
- Package - base exchange data package
- Message - package payload (DTO)
- Processor - class, that running on receive incoming package. Can return new Package in synchronous exchange mode.
Exchanges
Register exchanges in Exchanges enum (SMSkin\ServiceBus\Enums\Exchanges - can be overrides)
- id - internal id
- connection - id of connection (SMSkin\ServiceBus\Enums\Connections)
- rabbitMqName - RabbitMQ name of exchange
- attributes - RabbitMQ exchange attributes
- exchangeType (exchange_type)
- passive
- durable
- autoDelete (auto_delete)
- internal
- nowait
- throwExceptionOnRedeclare (throw_exception_on_redeclare)
- throwExceptionOnBindFail (throw_exception_on_bind_fail)
Queues
Register queues in Queues enum (SMSkin\ServiceBus\Enums\Queues - can be overrides)
- id - internal id
- connection - id of connection (SMSkin\ServiceBus\Enums\Connections)
- rabbitMqName - RabbitMQ name of queue
- attributes
- passive
- durable
- autoDelete (auto_delete)
- internal
- nowait
- exclusive
- bind - array of binds
- exchange - id of exchange (SMSkin\ServiceBus\Enums\Exchanges)
- routing_key
- arguments
- x-max-priority - maximal message priority
Publishers
Register publishers in Publishers enum (SMSkin\ServiceBus\Enums\Publishers - can be overrides)
- id - internal id
- exchange - id of exchange (SMSkin\ServiceBus\Enums\Exchanges)
Consumers
Register consumers in Consumers enum (SMSkin\ServiceBus\Enums\Consumers - can be overrides)
- id - internal id
- queue - id of queue (SMSkin\ServiceBus\Enums\Queues)
- prefetchCount
Hosts
Register hosts in Hosts enum (SMSkin\ServiceBus\Enums\Hosts - can be overrides)
- id - internal id
- host - url of consumer host (for provide synchronous service bus)
Exchange package
Package must provide links to processor and message classes. Package register in Packages enum ( SMSkin\ServiceBus\Enums\Packages - can be overrides). Exchange packages has very simple structure, that support reproduce this logic in any languages.
Example of serialized package:
Example of package:
Example of processor class:
Example of message class:
Example of registration package in Packages enum
Submitting
Example of submitting synchronous command
Example of submitting asynchronous command
- priority - priority of the message
All versions of laravel-service-bus with dependencies
laravel/framework Version ^8 || ^9 || ^10
guzzlehttp/guzzle Version ^7.0
smskin/laravel-support Version ^2.0
needle-project/laravel-rabbitmq Version dev-add-php8
ext-sockets Version *
ext-pcntl Version *