Download the PHP package vinelab/bowler without Composer

On this page you can find all versions of the php package vinelab/bowler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package bowler

Bowler

A Laravel package that implements the AMQP protocol using the Rabbitmq Server easily and efficiently. Built on top of the php-amqplib, with the aim of providing a simple abstraction layer to work with.

Build Status

Bowler allows you to:

In addition to the above Bowler offers limited admin functionalities.

These features will facilitate drastically the way you use Rabbitmq and broaden its functionality. This package do not intend to take over the user's responsability of designing the messaging schema.

Tools like the Rabbitmq Management plugin, will certainly help you monitor the server's activity and visualize the setup.

Table of Contents

Setup
Development
Usage
   Producer
   Consumer
      Manual
      Console
   Publisher/Subscriber
   Dispatcher
   Dead Lettering
   Error Handling
   Error Reporting
   Health Checks
   Lifecycle Hooks
   Testing
Important Notes
Todo

Supported Laravel versions

Starting version v0.4.2 this library requires Laravel 5.4 or later versions.

Starting version v0.5.0 this library requires Laravel 5.7 or later versions.

Starting version v0.9.0 this library requires Laravel 6.0 or later versions.

Setup

Install the package via Composer:

Laravel 5.4 users will also need to add the service provider to the providers array in config/app.php:

After installation, you can publish the package configuration using the vendor:publish command. This command will publish the bowler.php configuration file to your config directory:

You may configure RabbitMQ credentials in your .env file:

Development

Create the Docker container

Bash into the container

Install dependencies

Run tests

Usage

Producer

In order to be able to send a message, a producer instance needs to be created and an exchange needs to be set up.

or Inject the producer and let the IOC resolve the connection:

You need to make sure the exchange setup here matches the consumer's, otherwise a Vinelab\Bowler\Exceptions\DeclarationMismatchException is thrown.

If you mistakenly set an undefined value, setting up the exchange, e.g. $exchangeType='noneExistingType' a Vinelab\Bowler\Exceptions\InvalidSetupException is thrown.

Consumer

Add 'Registrator' => Vinelab\Bowler\Facades\Registrator::class, to the aliases array in config/app.

In order to consume a message an exchange and a queue needs to be set up and a message handler needs to be created.

Configuring the consumer can be done both manually or from the command line:

Manual

  1. Register your queues and handlers inside the queues.php file (think about the queues file as the routes file from Laravel), note that the queues.php file should be under App\Messaging directory:

    Use the options array to setup your queues and exchanges. All of these are optional, defaults will apply to any parameters that are not specified here. The descriptions and defaults of these parameters are provided later in this document.

  2. Create your handlers classes to handle the received messages:

    Similarly to the above, additional functionality is also provided to the consumer's handler like deleteExchange, purgeQueue and deleteQueue. Use these wisely and take advantage of the unused and empty parameters. Keep in mind that it is not recommended that an application exception be handled by manipulating the server's setup.

Console

Register queues and handlers with php artisan bowler:make:queue {queue} {handler} e.g. php artisan bowler:make:queue analytics_queue AnalyticsData.

The previous command:

  1. Adds Registrator::queue('analytics_queue', 'App\Messaging\Handlers\AnalyticsDataHandler', []); to App\Messaging\queues.php.

    If no exchange name is provided the queue name will be used as default.

    The options array: if any option is specified it will override the parameter set in the command. This help to emphasize the queues.php file as a setup reference.

  2. Creates the App\Messaging\Handlers\AnalyticsDataHandler.php in App\Messaging\Handlers directory.

Now, in order to listen to any queue, run the following command from your console: php artisan bowler:consume {queue} e.g. php artisan bowler:consume analytics_queue. You need to specify the queue name and any other optional parameter, if applicable to your case.

bowler:consume complete arguments list description:

Consuming a none registered queue will throw Vinelab\Bowler\Exceptions\UnregisteredQueueException.

If you wish to handle a message based on the routing key it was published with, you can use a switch case in the handler's handle method, like so:

Publisher/Subscriber

Bowler provide a default Pub/Sub implementation, where the user doesn't need to care about the setup.

In short, publish with a routingKey and consume with matching bindingKey(s).

1. Publish

In your Producer

Or inject the Publisher similarly to what we've seen here.

As you might have noted, here we instantiate a Publisher not a Producer object. Publisher is a Producer specification, it holds the default Pub/Sub exchange setup.

Signature

2. Subscribe

In your Consumer

i. Register the queue and generate its message handler

From the command line use the bowler:make:subscriber command.

php artisan bowler:make:subscriber reporting ReportingMessage --expressive

Using the --expressive or -E option will make the queue name reflect that it is used for Pub/Sub. Results in reporting-pub-sub as the generated queue name; otherwise the queue name you provided will be used.

Add the bindingKeys array parameter to the registered queue in queues.php like so:

Notice that it is not required to specify the exchange since it uses the default pub-sub exchange.

ii. Handle messages

Like we've seen earlier.

iii. Run the consumer

From the command line use the bowler:consume command.

php artisan bowler:consume reporting-pub-sub

The Pub/Sub implementation is meant to be used as-is. It is possible to consume all published messages to a given exchange by setting the consumer's binding keys array to ['*'].

If no binding keys are provided a Vinelab\Bowler\Exception\InvalidSubscriberBindingException is thrown.

If you would like to configure manually, you can surely do so by setting up the Producer and Consumer as explained earlier.

Signature

Dispatcher (Work Queue)

Similar to Pub/Sub, except you may define the exchange and messages will be distributed according to the least busy consumer (see Work Queue - Fair Dispatch).

1. Dispatch

Dispatch messages to a specific exchange with a routingKey and consume with matching bindingKey(s).

Signature

2. Consume

Registering a queue consumer is the same as Pub/Sub, except the exchange name in the registration needs to match.

The above will catch all the messages in the farm exchange that match the routing key *.cow.*

Dead Lettering

Dead lettering is solely the responsability of the consumer and part of it's queue configuration. Enabeling dead lettering on the consumer is done through the command line using the same command that run the consumer with the dedicated optional arguments or by setting the corresponding optional parameters in the aforementioned, options array. At least one of the --deadLetterQueueName or --deadLetterExchangeName options should be specified.

If only one of the mentioned optional parameters are set, the second will default to it. Leading to the same dlx and dlq name.

If you would like to avoid using Dead Lettering, you could leverage a striped down behaviour, by requeueing dead messages using $broker->rejectMessage(true) in the queue's MessageHandler::handleError().

Error Handling

Error Handling in Bowler is limited to application exceptions.

Handler::handleError($e, $broker) allows you to perfom action on the queue. Whether to acknowledge, nacknowledge or reject a message is up to you.

It is not recommended to alter the Rabbitmq setup in reponse to an application exception, e.g. for an InvalidInputException to purge the queue! In any case, if deemed necessary for the use case, it should be used with caution since you will loose all the queued messages or even worst, your exchange.

While server exceptions will be thrown. Server errors not wrapped by Bowler will be thrown as Vinelab\Bowler\Exceptions\BowlerGeneralException.

Error Reporting

Bowler supports application level error reporting.

To do so, the default laravel exception handler normaly located in app\Exceptions\Handler, should implement Vinelab\Bowler\Contracts\BowlerExceptionHandler.

ExceptionHandler::reportQueue(Exception $e, AMQPMessage $msg) allows you to report errors as you wish. While providing the exception and the queue message itsef for maximum flexibility.

Health Checks

IMPORTANT: Management plugin is required to be installed in order to perform health checks.

Based on this Reliability Guide, Bowler figured that it would be beneficial to provide a tool to check the health of connected consumers and is provided through the bowler:healthcheck:consumer command with the following signature:

Example: php artisan bowler:healthcheck:consumer the-queue

Will return exit code 0 for success and 1 for failure along with a message why.

Lifecycle Hooks

Bowler exposes the following lifecycle hooks:

By default, Bowler logs and suppress errors that occur inside the callback. You can configure this behavior via bowler.lifecycle_hooks.fail_on_error configuration option.

Testing

If you would like to silence the Producer/Publisher to restrict it from actually sending/publishing messages to an exchange, bind it to a mock, locally in your test or globally.

Globally:

Use Vinelab\Bowler\Producer in App\Tests\TestCase;

Add the following to App\Tests\TestCase::createApplication():

`

Important Notes

  1. It is of most importance that the users of this package, take onto their responsability the mapping between exchanges and queues. And to make sure that exchanges declaration are matching both on the producer and consumer side, otherwise a Vinelab\Bowler\Exceptions\DeclarationMismatchException is thrown.

  2. The use of nameless exchanges and queues is not supported in this package. Can be reconsidered later.

TODO


All versions of bowler with dependencies

PHP Build Version
Package Version
Requires php Version 8.*
php-amqplib/php-amqplib Version v3.2.*
illuminate/console Version ^6 || ^7 || ^8 || ^9
illuminate/support Version ^6 || ^7 || ^8 || ^9
illuminate/filesystem Version ^6 || ^7 || ^8 || ^9
vinelab/http Version ^1.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vinelab/bowler contains the following files

Loading the files please wait ....