Download the PHP package hnto/bick without Composer
On this page you can find all versions of the php package hnto/bick. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bick
Bick
Bick is a RabbitMQ wrapper built with the official php-amqlib library. Besides a wrapper for simple setup, publish and consume, Bick can also be used for batch publshing messages, keeping track of them etc.
#
Install
#
Possibilities
- simple setup, publish and consume using one Bick class
- batch publishing messages
- stored in a data storage of your choice
- prioritizing messages
- keeping track of messages
- store faulty messages in a data storage of your choice for further research
#
Setup
- Instantiate a
Bickclass by providing aBickConnectionSetup- The
BickConnectionSetuprequires a config with the values:- host
- port
- user
- pass
- vhost (default "/")
- Execute the
setupmethod by providing the queues, exchanges and bindings Bickthrows an exception on a connection fault
- The
Example
Publish message
The Bick object can be used to retrieve a BickPublisherInterface and publish a message.
The publish method inside the publisher requires a BickMessageInterface object and
throws an exception on an invalid BickMessage
Due note: when using the default BickPublisher class and you don't want to use persistence, set it to false using the publisher method BickPublisher::persistMessages(false).
Example
Publish messages (batch)
The Bick object also offers the option to publish messages in a batch.
The logic is the same as when publishing one message. The difference is that you send an array of BickMessage objects.
Example
Consuming messages
For consuming messages you must create your own consumer class. This class must implement BickConsumerInterface and BickConnectionShutdownInterface.
For a more easy setup, you can also extend the abstract BickConsumer. The only method you are required to implement is
the process method. This method is given a BickMessageInterface. Within this method you are required to return a status.
These statuses can be found within the BickMessageInterface as constants. A consumer class can be retrieved by executing the Bick object method consumer.
To start consuming messages execute the consume method inside the consumer class.
Due note: when using the BickConsumer abstract, set the protected member var $persist to false if you don't want to use persistence
Example
When using the BickConsumer you can "translate" a raw AMQP message to a message of your own that implements BickMessageInterface.
This way you have full control over what goes inside the message body and further info. Upon requesting the default BickConsumer the
standard translator is set in order to create a default BickMessage object. Replacing the default translator can be done with the setTranslator method.
Message persistence
Persisting messages in order to keep track of them
In Bick you can persist messages into a data storage by providing a data storage adapter object.
This adapter can be whatever you'd like (MySQL, Redis, File).
The BickPublisher and BickConsumer objects already have the implemention available for persisting messages into a data storage using the method persist of your adapter.
The only thing they require is an Adapter variable that you set in the setAdapter method of these classes.
This adapter must implement the PersistenceAdapterInterface. What and how you save this data, is up to you.
Example
Persisting messages after a NACK in order to analyse them
In Bick you can persist a message that was a "NACK" and provide optional information regarding the fault. In order to implement this functionality your consumer must implement the interface MessageFaultAnalyseInterface.
This interface requires that you define a method called analyse which requires a BickMessage object.
Furthermore you must assign a BickMessageFault object to the member var protected $fault. This fault is sent to the data storage along with the message; this class implements JsonSerializable.
The BickConsumer has this implementation by default. So if you extend it you're messages are stored automatically into a data storage when returning a NACK status.
Example
Bick adapter
Bick has its own adapter for saving/tracking the messages. This is a PDO adapter connecting to a relational database of your choice (MySQL/MariaDB/Postgre).
SQL tables
Example
You can implement the Bick adapter in this way
Facts
- Upon instantiating a
Bickobject the config is saved- The connection to RabbitMQ is not created until an action is requested
- Upon setup a connection is opened and a channel is requested
- The channel and connection are closed afterwards
- Upon publishing a message a connection is opened and a channel is requested
- The channel and connection are closed afterwards
- Upon consuming a queue a connection is opened and a channel is requested
- The channel and connection are not closed afterwards. These will be closed if the consumer is stopped.
To do
- Implement sending an event or notification upon a finished message (in a batch) or a faulty one
- Prioritizing messages in a batch
- Dashboard for viewing fault messages, edit them and republish them accordingly
All versions of bick with dependencies
php-amqplib/php-amqplib Version ^2.8
ramsey/uuid Version ^3.8
ext-json Version *