Download the PHP package sebk/small-events-swoft without Composer

On this page you can find all versions of the php package sebk/small-events-swoft. 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 small-events-swoft

sebk/small-events-swoft

Swoft cross applications events dispatcher and receiver

Install

Create your Swoft project : http://swoft.io/docs/2.x/en/quick-start/install.html

Require package (https://github.com/sebk69/small-events-swoft) :

Documentation

Supported connectors

For now, only RabbitMq is supported.

In future, Apache Kafka and MySql connectors are planned.

Configuration

Add contract to choose your massage brocker to your 'bean.php' :

Here RabbitMq message broker will be used.

Create a 'small_events.php' file in your config dir :

The applicationId must be unique between all your applications : it will be used to create a queue to receive events.

In the RabbitMq section, you can set server host, user and password.

The smallEventsExchange is the exchane that will be used to dispatch events in all your applications.

In the queues array, declare all queues that you will use for events or messaging. The first queue is dedicated to your events flow and must be declared :

The second queue can be used to send messages outside event flow.

The consumers array must contain the list of consumers objects, used to listen all queues outside events queue (see below for how to create consumer class).

Send a message outside event flow

Their is a simple method to send messages to other applications :

This command will send $message to the exchange of 'test' queue.

Send an event

The class SmallEvent, allow you to create an event that will be shared with all listening applications :

The first parameter is the event name and the second parameter is the data of your event.

Note that the data must be json serializable.

Then use the dispatcher to send event to other applications (including yours) :

Create consumers

The simple messages (not event one) can be consumed by creating consumers (the ones we have seen in configuation section)

Here is an example :

A consumer must extends 'AbstractSmallConsumer' class and define the queue name to listen in constructor.

The method 'consume' will be called at every time a message is received from the queue. It must return true to ack message.

Listen to a queue

You must use the following command to listen a queue :

This command will wait for messages of teh queue 'test' and call your consumer class at each message.

If you don't use --queue parameter, the proccess will listen to events.

To manage your workers, you can use tools like Supervisor : http://supervisord.org

And events ? How to subscribe

Events are dispatched via Swoft/Event standard package (http://swoft.io/docs/2.x/en/event/usage.html).

Here is a small example to subscibe to our 'testEvent' :


All versions of small-events-swoft with dependencies

PHP Build Version
Package Version
Requires swoft/framework Version ~2.0.0
php-amqplib/php-amqplib Version ~3.1.0
swoft/event Version ~2.0.0
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 sebk/small-events-swoft contains the following files

Loading the files please wait ....