Giter Club home page Giter Club logo

service-bus's Introduction

Prooph Service Bus

PHP 7.1+ lightweight message bus supporting CQRS and Micro Services

Build Status Coverage Status Gitter

Important

This library will receive support until December 31, 2019 and will then be deprecated.

For further information see the official announcement here: https://www.sasaprolic.com/2018/08/the-future-of-prooph-components.html

Messaging API

prooph/service-bus is a lightweight messaging facade. It allows you to define the API of your model with the help of messages.

  1. Command messages describe actions your model can handle.
  2. Event messages describe things that happened while your model handled a command.
  3. Query messages describe available information that can be fetched from your (read) model.

prooph/service-bus shields your model. Data input and output ports become irrelevant and no longer influence business logic. We're looking at you Hexagonal Architecture.

prooph/service-bus decouples your model from any framework. You can use a web framework like Zend, Symfony, Laravel and co. to handle http requests and pass them via prooph/service-bus to your model but you can also receive the same messages via CLI or from a messaging system like RabbitMQ or Beanstalkd.

It is also a perfect fit for microservices architecture as it provides an abstraction layer for message-based inter-service communication.

prooph_architecture

Installation

You can install prooph/service-bus via composer by running composer require prooph/service-bus, which will install the latest version as requirement to your composer.json.

Quick Start

<?php

use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\Example\Command\EchoText;
use Prooph\ServiceBus\Plugin\Router\CommandRouter;

$commandBus = new CommandBus();

$router = new CommandRouter();

//Register a callback as CommandHandler for the EchoText command
$router->route('Prooph\ServiceBus\Example\Command\EchoText')
    ->to(function (EchoText $aCommand): void {
        echo $aCommand->getText();
    });

//Expand command bus with the router plugin
$router->attachToMessageBus($commandBus);

//We create a new Command
$echoText = new EchoText('It works');

//... and dispatch it
$commandBus->dispatch($echoText);

//Output should be: It works

Live Coding Introduction

Prooph Service Bus v6

Documentation

Documentation is in the docs tree, and can be compiled using bookdown.

$ php ./vendor/bin/bookdown docs/bookdown.json
$ php -S 0.0.0.0:8080 -t docs/html/

Then browse to http://localhost:8080/

Support

Contribute

Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and may adapt the documentation.

License

Released under the New BSD License.

service-bus's People

Contributors

basz avatar camuthig avatar christickner avatar codeliner avatar dannyvdsluijs avatar enumag avatar fabiocarneiro avatar fritz-gerneth avatar gquemener avatar iainmckay avatar jpkleemans avatar lunetics avatar mablae avatar makasim avatar oqq avatar prolic avatar robertlemke avatar sandrokeil avatar sasezaki avatar ufomelkor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

service-bus's Issues

Provide FactoryPluginManagers

Commands-, Events- and MessagesFactories should also be derived from PluginManagers by passing the FQCNs to them. So you can register different factories for different types of commands, events, messages.

Implement EventReceiver

We need an EventReceiver that receives events from a queue and publish them to local listeners.

DispatchException captures wrong process phase

When an exception is thrown during message dispatch the CommandDispatchException or EventDispatchException should use the current event name of the Dispatch to give a hint in which phase the exception was thrown, but the phase is always finalize cause finalize is always triggered whether the dispatch was successful or not.

Add a query bus

  • QueryDispatch
  • QueryRouter
  • QueryBus returning a promise
  • Align invoke strategies
  • Add a MessageDispatcher\RemoteQueryDispatcher interface

Publish events to many EventHandlers

Other than a CommandReceiver, an EventReceiver should publish an Event to many EventHandlers.

Change event_map structure to allow an array of EventHandlers for a specific Event.
Let EventReceiver check if one handler or a collection of handlers is configrued.
Let EventReceiver publish event to all configured handlers.

Add MessageFactory

Define an interface with two methods: fromCommand and fromEvent.
Implement a MessageFactory.
Let CommandBus use the MessageFactory by default and make it possible, that MessageFactory can be exchanged. like the CommandFactory in a CommandReceiver

Remove config root

The config root comes in play when ServiceBus is integrated in ZF2 but this should be manged by the integration module.

Implement default setup of ServiceBus

By default the ServiceBus should be configured with a CommandBus, CommandReceiver, EventBus, EventReceiver, local Queue and InMemoryMessageDispatcher in place.

Enable direct attach of CommandHandlers and EventListeners to ease the setup for a new client. It should be possible to explore the system iterative.

Implement RESTfulMessageDispatcher as ZF2 Module

The RESTfulMessageDispatcher can be used to publish commands and events as resources and to receive them from a client. The RESTfulMessageDispatcher should be provided as ZF2 Module, cause we need REST controllers and a Database. To much dependencies to include it in the core service bus.

Update docs for v4.0

Docs need to be aligned due to upgrade to prooph/common v3.x and remove of ZF2\Events.

Add error handling of handling errors

When the ServiceBus invokes a command or event on a handler, exceptions should be catched and an error event should be triggered containing a raiseException flag which defaults to true but can be changed by a listener if error is handled in another way, f.e. delivery of the message is retried.

Add optional message tracking mechanism

Design a consistent status API that can be added via initializer and listen to the various message dispatcher, receiver and routing events to track status of published messages.
Look at the resque example for inspiration.

Depends On

  • #30 tracking of errors should be possible, too

Add apigility integration

Provide a generic messagebox endpoint to receive commands from the client. Each command type should have an own messagebox, so that you can document the different commands like you would document resources.

A messagebox should answer with a HTTP Status code and with a hypermedia link to an endpoint where client can check the status of the command: pending, succeeded, failed, ....

Provide helper to add hal links to resources pointing to available commands for the resource.

Also provide an event-stream endpoint, so that a client can query for published events.

Implement LocalQueueSetup ListenerAggregate

The LocalQueueSetup should register itself to the ServiceBusInitializationEvent.
During the Event it should activate the InMemoryMessageDispatcher and add the CommandRceiverManager to the localQueue mapping of the InMemoryMessageDispatcher.

Add EventManager to all components

Each component should provide an own EventManager and trigger pre and post events in all public methods.
The ServiceBusManager should addionally trigger an ServiceBusInitializationEvent.

Introduce direct message routing

The LocalSynchronousInitiliazer is no good default. Most times you will use the ServiceBus for simple synchronous command/event dispatching. The complete message translation via bus, message dispatcher and receiver is just overhead for this use case.

A simpler solution is required. The idea is that the ServiceBus#route method looks for direct_command_map and direct_event_map configuration. These maps are simple dictionaries where the key is the message name and the value is the handler alias of the services configuration of the ServiceBus. So the ServiceBus can directly detect the appropriate handler an invoke it with the help of an InvokeStrategy.

The LocalSynchronousInitiliazer is no longer required and can be removed.

Depends On

Sub-Tasks

Use services key for configuring the ServiceBusLocator

Currently you have to define ServiceLocator configuration for the ServiceBus under the root config key. This is confusing and should be changed. The ServiceLocator config can be organized under the key "service_bus_manager".

Improve event system

Design specific events for all actions and let listener change the arguments, f.e. switch queue in a MessageDispatcher, etc.

Improve bus initialization logic

The default command/event bus factories do not check if they can create the requested bus. It would be better, if they check the configuration in the canCreateService method and not in the createServiceWithName method. So the ServiceBusManager can fall back to direct routing if requested bus is not available but ServiceBusManager has a mapping for the message.

With this change in mind you can know send a message on a non existing topic bus and if you later decide to route this topic to a asynchronous message dispatcher, you can do so by simply add a configuration for the topic bus.

Add type to message header

The header of a message should provide information of the original type of the message (command or event).

Change InMemoryMessageDispatcher to check the type and use the correct *Receiver

Change Definition of ServiceBusManager aliases

At the moment the aliases defined in Definition are used in the ServiceBusManager to point to the default implementations. The aliases are defined like they are used within a ZF2 ServiceManager (without underscores, etc.). The spelling do not answer to configuration keys, so the notation should be adapted and usage in ServiceBusManager, too.

Remove queue component

Queues are not really necessary. The original intention was to use them for topic based routing but it is enough to use the command bus name for this kind of purpose.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.