Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/event-band/band-symfony-bundle
Symfony2 Bundle for EventBand
https://github.com/event-band/band-symfony-bundle
async asynchronous bundle consumer dispatch event event-band events listener rabbit-mq rabbitmq rabbitmq-client rabbitmq-consumer symfony symfony2-bundle symfony3
Last synced: 3 months ago
JSON representation
Symfony2 Bundle for EventBand
- Host: GitHub
- URL: https://github.com/event-band/band-symfony-bundle
- Owner: event-band
- License: mit
- Created: 2015-08-10T10:56:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T22:25:27.000Z (almost 7 years ago)
- Last Synced: 2024-09-30T16:03:09.509Z (3 months ago)
- Topics: async, asynchronous, bundle, consumer, dispatch, event, event-band, events, listener, rabbit-mq, rabbitmq, rabbitmq-client, rabbitmq-consumer, symfony, symfony2-bundle, symfony3
- Language: PHP
- Size: 149 KB
- Stars: 8
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
EventBandSymfonyBundle
======================Symfony2 Bundle for EventBand framework [![Build Status](https://travis-ci.org/event-band/band-symfony-bundle.svg?branch=1.0.x)](https://travis-ci.org/event-band/band-symfony-bundle)
# Quick start
## Adding event-band to a symfony2 project
Run the following commands:
``` bash
$ composer require "event-band/symfony-bundle:~1.0"
$ composer require "event-band/amqplib-transport:~1.0"
```## Simple configuration
### Creating an event
Create an event, extending the EventBand\Adapter\Symfony\SerializableSymfonyEvent
``` php
message = $message;
}public funciton getMessage()
{
return $this->message;
}
protected function toSerializableArray()
{
$array = parent::toSerializableArray();
$array['message'] = $this->message;return $array;
}
protected function fromUnserializedArray(array $data)
{
parent::fromUnserializedArray($data);
$this->message = $data['message'];
}
}
```
### Creating a listener
Then create a listener
```php
getMessage();
echo "\n";
}
}
```
And register listener in services.xml
```xml
```
### Configuring bands
Add the following lines to your config.yml
```yml
event_band:
publishers:
acme.echo.event.publisher:
events: ["event.echo"]
transport:
amqp:
exchange: acme.echo.event.exchange
consumers:
acme.echo.event: ~
```
### Adding band information to listener to make it asynchronous
Add parameter `band` with name of consumer to event listener tag to show which consumer it belongs to.
```xml
```
### Creating AMQP config
This step is not required, but it's very useful to have this config.
Under the `event_band` space add the following lines to your config.yml
```yml
transports:
amqp:
driver: amqplib
connections:
default:
exchanges:
acme.echo.event.exchange: ~
queues:
acme.echo.event:
bind:
acme.echo.event.exchange: ['event.echo']
```
Now you can call `app/console event-band:setup amqp:default` command and all the exchanges, queues and bindings will be
automatically created/altered.
### Using asynchronous event
Somewhere in your code use event dispatcher to dispatch the EchoEvent as you usually do.
```php
$dispatcher = $this->getContainer()->get('event_dispatcher');
$dispatcher->dispatch('event.echo', new EchoEvent('Hi, guys!'));
```
When you run this code, event will be pushed to the acme.echo.event queue.
Now run console command `event-band:dispatch` with the name of your consumer - `acme.echo.event`.
```bash
sh$ app/cosole event-band:dispatch acme.echo.event
Hi, guys!
```
...
Profit.## Using JMSSerializer
### Adding dependencies
Run `composer require "event-band/jms-serializer:~1.0"` command
### Creating an event
``` php
date['message'] = $message;
}public function getMessage()
{
return $this->data['message'];
}
}
```
### Config
Add the following lines under 'event_band' section in your config.yml
```yml
serializers:
serializer:
jms:
format: json
```
All the other settings are similar.