<commit_before># Message Bus

[![Build Status](https://travis-ci.org/PHPMessageBus/messagebus.svg?branch=master)](https://travis-ci.org/PHPMessageBus/messagebus) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPMessageBus/messagebus/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPMessageBus/messagebus/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/04e1a12f-e916-4ae6-875f-5e694fb71b6a/mini.png?)](https://insight.sensiolabs.com/projects/04e1a12f-e916-4ae6-875f-5e694fb71b6a) [![Latest Stable Version](https://poser.pugx.org/nilportugues/messagebus/v/stable?)](https://packagist.org/packages/nilportugues/messagebus) [![Total Downloads](https://poser.pugx.org/nilportugues/messagebus/downloads?)](https://packagist.org/packages/nilportugues/messagebus) [![License](https://poser.pugx.org/nilportugues/messagebus/license?)](https://packagist.org/packages/nilportugues/messagebus)
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/nilportugues)

Implementation for the CommandBus, the QueryBus and the EventBus in PHP 7.

---

 - [Message Bus](#message-bus)
 - [Installation](#installation)
 - [Introduction](#introduction)
 - [What is a Message Bus?](#what-is-a-message-bus)
 - [What are its benefits?](#what-are-its-benefits)
 - [1. CommandBus](#1-commandbus)
    - [1.1 - Usage](#11-usage)
        - [1.1.1 - Create a Command](#111-create-a-command)
        - [1.1.2 - Create a CommandHandler](#112-create-a-commandhandler)
        - [1.1.3 - Register the CommandHandler](#113-register-the-commandhandler)
        - [1.1.4 - Setting up the CommandBus](#114-setting-up-the-commandbus)
        - [1.1.5 - Registering the remaining CommandBus classes](#115-registering-the-remaining-commandbus-classes)
        - [1.1.6 - Running the CommandBus](#116-running-the-commandbus)
    - [ 1.2 - Predefined Middlewares](#12-predefined-middlewares)
    - [ 1.3 - Custom Middlewares](#13-custom-middlewares)
 - [2. QueryBus](#2-querybus)
    - [2.1 - Usage](#21-usage)
        - [2.1.1 - Create a Query](#211-create-a-query)
        - [2.1.2 - Create a QueryHandler](#212-create-a-queryhandler)
        - [2.1.3 - Create a QueryResponse](#213-create-a-queryresponse)
        - [2.1.4 - Register the QueryHandler](#214-register-the-queryhandler)
        - [2.1.5 - Setting up the QueryBusMiddleware](#215-setting-up-the-querybusmiddleware)
        - [2.1.5 - Registering the remaining QueryBus classes](#215-registering-the-remaining-querybus-classes)
        - [2.1.6 - Running the QueryBus](#216-running-the-querybus)
    - [ 2.2 - Predefined Middlewares](#22-predefined-middlewares)
    - [ 2.3 - Custom Middlewares](#23-custom-middlewares)
 - [3. EventBus](#3-eventbus)
    - [3.1 - Usage](#31-usage)
        - [3.1.1 - Create an Event](#311-create-an-event)
        - [3.1.2 - Create an EventHandler](#312-create-an-eventhandler)
        - [3.1.3 - (Optional) Set the EventHandler's Priority](#313-optional-set-the-eventhandlers-priority)
        - [3.1.4 - Register the EventHandler](#314-register-the-eventhandler)
        - [3.1.5 - Setting up the EventBusMiddleware](#315-setting-up-the-eventbusmiddleware)
        - [3.1.6 - Registering the remaining EventBus classes](#316-registering-the-remaining-eventbus-classes)
        - [3.1.7 - Running the EventBus](#317-running-the-eventbus)
        - [3.1.8 - (Optional) Running the EventBus as a Queue](#318-optional-running-the-eventbus-as-a-queue)
    - [3.2 - Predefined Middlewares](#32-predefined-middlewares)
    - [3.3 - Custom Middlewares](#33-custom-middlewares)
 - [4 - Serializers](#4-serializers)
     - [4.1 - NilPortugues\MessageBus\Serializer\NativeSerializer](#41-nilportuguesmessagebusserializernativeserializer)
    - [4.2 - NilPortugues\MessageBus\Serializer\JsonSerializer](#42-nilportuguesmessagebusserializerjsonserializer)
    - [4.3 - NilPortugues\MessageBus\Serializer\JsonObjectSerializer](#43-nilportuguesmessagebusserializerjsonobjectserializer)
 - [Contribute](#contribute)
 - [Support](#support)
 - [Authors](#authors)
 - [License](#license)

## Installation

Use [Composer](https://getcomposer.org) to install the package:

```
$ composer require nilportugues/messagebus
```

## Introduction

The idea of a message bus is that you create message objects that represent what you want your application to do. Then, you toss it into the bus and the bus makes sure that the message object gets to where it needs to go. 

Easy right? Keep reading!

### What is a Message Bus?

A Message Bus is a pipe of Messages. This implementation takes care of 3 types of messages, Commands, Queries and Events. While all look similar at first, their intent is different.<commit_msg>README index<commit_after># Message Bus

[![Build Status](https://travis-ci.org/PHPMessageBus/messagebus.svg?branch=master)](https://travis-ci.org/PHPMessageBus/messagebus) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPMessageBus/messagebus/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPMessageBus/messagebus/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/04e1a12f-e916-4ae6-875f-5e694fb71b6a/mini.png?)](https://insight.sensiolabs.com/projects/04e1a12f-e916-4ae6-875f-5e694fb71b6a) [![Latest Stable Version](https://poser.pugx.org/nilportugues/messagebus/v/stable?)](https://packagist.org/packages/nilportugues/messagebus) [![Total Downloads](https://poser.pugx.org/nilportugues/messagebus/downloads?)](https://packagist.org/packages/nilportugues/messagebus) [![License](https://poser.pugx.org/nilportugues/messagebus/license?)](https://packagist.org/packages/nilportugues/messagebus)
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/nilportugues)

Implementation for the CommandBus, the QueryBus and the EventBus in PHP 7.

---

 - [Message Bus](#message-bus)
 - [Installation](#installation)
 - [Introduction](#introduction)
 - [What is a Message Bus?](#what-is-a-message-bus)
 - [What are its benefits?](#what-are-its-benefits)
 - [1. CommandBus](#1---commandbus)
    - [1.1 - Usage](#11---usage)
        - [1.1.1 - Create a Command](#111---create-a-command)
        - [1.1.2 - Create a CommandHandler](#112---create-a-commandhandler)
        - [1.1.3 - Register the CommandHandler](#113---register-the-commandhandler)
        - [1.1.4 - Setting up the CommandBus](#114---setting-up-the-commandbus)
        - [1.1.5 - Registering the remaining CommandBus classes](#115---registering-the-remaining-commandbus-classes)
        - [1.1.6 - Running the CommandBus](#116---running-the-commandbus)
    - [ 1.2 - Predefined Middlewares](#12---predefined-middlewares)
    - [ 1.3 - Custom Middlewares](#13---custom-middlewares)
 - [2. QueryBus](#2---querybus)
    - [2.1 - Usage](#21-usage)
        - [2.1.1 - Create a Query](#211---create-a-query)
        - [2.1.2 - Create a QueryHandler](#212---create-a-queryhandler)
        - [2.1.3 - Create a QueryResponse](#213---create-a-queryresponse)
        - [2.1.4 - Register the QueryHandler](#214---register-the-queryhandler)
        - [2.1.5 - Setting up the QueryBusMiddleware](#215---setting-up-the-querybusmiddleware)
        - [2.1.6 - Registering the remaining QueryBus classes](#216---registering-the-remaining-querybus-classes)
        - [2.1.7 - Running the QueryBus](#216---running-the-querybus)
    - [ 2.2 - Predefined Middlewares](#22---predefined-middlewares)
    - [ 2.3 - Custom Middlewares](#23---custom-middlewares)
 - [3. EventBus](#3---eventbus)
    - [3.1 - Usage](#31---usage)
        - [3.1.1 - Create an Event](#311---create-an-event)
        - [3.1.2 - Create an EventHandler](#312---create-an-eventhandler)
        - [3.1.3 - (Optional) Set the EventHandler's Priority](#313---optional-set-the-eventhandlers-priority)
        - [3.1.4 - Register the EventHandler](#314---register-the-eventhandler)
        - [3.1.5 - Setting up the EventBusMiddleware](#315---setting-up-the-eventbusmiddleware)
        - [3.1.6 - Registering the remaining EventBus classes](#316---registering-the-remaining-eventbus-classes)
        - [3.1.7 - Running the EventBus](#317---running-the-eventbus)
        - [3.1.8 - (Optional) Running the EventBus as a Queue](#318---optional-running-the-eventbus-as-a-queue)
    - [3.2 - Predefined Middlewares](#32---predefined-middlewares)
    - [3.3 - Custom Middlewares](#33---custom-middlewares)
 - [4 - Serializers](#4---serializers)
     - [4.1 - NilPortugues\MessageBus\Serializer\NativeSerializer](#41---nilportuguesmessagebusserializernativeserializer)
    - [4.2 - NilPortugues\MessageBus\Serializer\JsonSerializer](#42---nilportuguesmessagebusserializerjsonserializer)
    - [4.3 - NilPortugues\MessageBus\Serializer\JsonObjectSerializer](#43---nilportuguesmessagebusserializerjsonobjectserializer)
 - [Contribute](#contribute)
 - [Support](#support)
 - [Authors](#authors)
 - [License](#license)

## Installation

Use [Composer](https://getcomposer.org) to install the package:

```
$ composer require nilportugues/messagebus
```

## Introduction

The idea of a message bus is that you create message objects that represent what you want your application to do. Then, you toss it into the bus and the bus makes sure that the message object gets to where it needs to go. 

Easy right? Keep reading!

### What is a Message Bus?

A Message Bus is a pipe of Messages. This implementation takes care of 3 types of messages, Commands, Queries and Events. While all look similar at first, their intent is different.
{'fraction_non_alphanumeric': 0.1602342851166196, 'fraction_numerical': 0.04685702332392009, 'mean_word_length': 3.682664054848188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 30, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6732397', 'n_tokens_mistral': 3446, 'n_tokens_neox': 3149, 'n_words': 554}