2017 © Pedro Peláez
 

symfony-bundle bernard-bundle

Integrates Bernard into a Symfony2 application.

image

bernard/bernard-bundle

Integrates Bernard into a Symfony2 application.

  • Sunday, February 25, 2018
  • by henrikbjorn
  • Repository
  • 7 Watchers
  • 85 Stars
  • 147,163 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 27 Forks
  • 9 Open issues
  • 12 Versions
  • 12 % Grown

The README.md

BernardBundle

Integrates Bernard neatly with a Symfony application., (*1)

Build Status, (*2)

Getting Started

Everything starts by installing the bundle. This is done through composer by adding the following lines to your composer.json file and running composer update bernard/bernard-bundle., (*3)

``` json { "require" : { "bernard/bernard-bundle" : "~1.0" } }, (*4)


Next up is adding the bundle to your kernel and configuring it in `config.yml`. ``` php // app/AppKernel.php // .. previous class definition public function registerBundles() { // .. all the other bundles you have registered. $bundles[] = new Bernard\BernardBundle\BernardBundle(); // .. the rest of the method }

``` yml, (*5)

.. previous content of app/config/config.yml

bernard: driver: file # you can choose predis, phpredis, file, doctrine, sqs etc., (*6)


Great! You are now ready to use this diddy. Go and read the rest of the documentation on Bernard at [bernard.readthedocs.org](http://bernard.readthedocs.org). ### Running the Consumer What good is a message queue if you don't know how to run the consumer? Luckily this bundle auto registers the commands with your application. So if you run `php app/console` you should see `bernard:consume` and `bernard:produce`. These work just as the documentation describes but if you are in doubt just add `--help` when running the command. It is important to use `--no-debug` when running the consumer for longer periods of time. This is because Symfony by default in debug mode collects a lot of information and logging and if this is omitted you will run into memory problems sooner or later. ### Adding Receivers In order to know what messages needs to go where you have to register some receivers. This is done with a tag in your service definitions. ``` yaml my_receiver: class: Acme\Receiver # public: true # Make sure the service is public tags: - { name: bernard.receiver, message: SendNewsletter } - { name: bernard.receiver, message: ImportUsers }

As the example shows it is possible to register the same receiver for many different message types., (*7)

Configuration Options

There are different options that can be set that changes the behaviour for various drivers., (*8)

Doctrine

When using the doctrine driver it can be useful to use a seperate connection when using Bernard. In order to change it use the connection option. This also needs to be set if you default connection is called anything else than default., (*9)

``` yaml doctrine: dbal: connections: bernard: host: "%database_host%" charset: UTF8, (*10)

bernard: driver: doctrine options: connection: bernard # default is the default value, (*11)


### FlatFile The file driver needs to know what directory it should use for storing messages and its queue metadata. ``` yaml bernard: driver: file options: directory: %kernel.cache_dir%/bernard

The above example will dump your messages in the cache folder. In most cases you will want to change this to something because the cache folder is deleted every time the cache is cleared (obviously)., (*12)

PhpAmqp / RabbitMQ

PhpAmqp depends on a service called old_sound_rabbit_mq.connection.default with a configured connection instance that extends \PhpAmqpLib\Connection\AbstractConnection class. If you want to use a different name use the phpamqp_service option:, (*13)

``` yaml bernard: driver: phpamqp options: phpamqp_service: my_phpamqp_service, (*14)


You need to define the `phpamqp_exchange`. Optional, you can define `phpamqp_default_message_parameters`: ``` yaml bernard: driver: phpamqp options: phpamqp_exchange: my_phpamqp_service phpamqp_default_message_parameters: content_type: application/json delivery_mode: 2

PhpRedis

PhpRedis depends on a service called snc_redis.bernard with a configured Redis instance. If you want to use a different name use the phpredis_service option:, (*15)

``` yaml bernard: driver: phpredis options: phpredis_service: my_redis_service, (*16)


If you're using the [SncRedisBundle](https://github.com/snc/SncRedisBundle) you have to set logging to false for the bernhard client to ensure that is is a ``Redis`` instance and not wrapped. Also, if the consumer is throwing `RedisException: read error on connection`, you need to set `connection_timeout` (see SncRedisBundle configuration options) option to a value higher than 5 (seconds). ### IronMQ When using the IronMQ driver you have to configure an `IronMQ` connection instance. You can configure it like the following: ``` yaml services: ironmq_connection: class: IronMQ arguments: - { token: %ironmq_token%, project_id: %ironmq_project_id% } public: false bernard: driver: ironmq options: ironmq_service: ironmq_connection

Amazon SQS

To use Amazon SQS, configure your driver like this:, (*17)

``` yaml services: my_sqs_client: class: Aws\Sqs\SqsClient factory: Aws\Sqs\SqsClient::factory arguments: region: "your aws region" # e.g. "eu-west-1" key: "your aws user's key" secret: "your aws user's secret", (*18)

bernard: driver: sqs options: sqs_service: my_sqs_client sqs_queue_map: # optional for aliasing queue urls (default alias is the url section after the last "/"), e.g.: send_newsletter: https://sqs.eu-west-1.amazonaws.com/... prefetch: 1 # optional, but beware the default is >1 and you may run into invisibility timeout problems with that, (*19)


### Pheanstalk To use Pheanstalk (pda/pheanstalk), configure your driver like this: ``` yaml services: my.pheanstalk.connection: class: Pheanstalk\Pheanstalk arguments: - %some.parameter.containing.pheanstalk.host% bernard: driver: pheanstalk options: pheanstalk_service: my.pheanstalk.connection

The Versions

25/02 2018
23/09 2017

1.x-dev

1.9999999.9999999.9999999-dev

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

23/07 2017
29/07 2016

2.0.0-alpha1

2.0.0.0-alpha1 http://bernard.readthedocs.org/

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/03 2016

1.1.2

1.1.2.0

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2015

1.1.0

1.1.0.0 http://bernardphp.com

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2015

1.1.1

1.1.1.0

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

27/01 2014

1.0.1

1.0.1.0

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

27/01 2014

dev-data-collector

dev-data-collector

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/01 2014

1.0.0

1.0.0.0

Integrates Bernard into a Symfony2 application.

  Sources   Download

MIT

The Requires

 

The Development Requires