forked from smart-devs/FireGento_RabbitMQ
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Niedergesäß
committed
Jul 19, 2017
0 parents
commit 55d0d39
Showing
29 changed files
with
3,313 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
FireGento_RabbitMQ | ||
====================== | ||
RabbitMQ implementation for Magento 1 with logic for producer and consumer. | ||
|
||
Facts | ||
----- | ||
* version: 1.0.0 | ||
* [extension on GitHub](https://github.com/firegento/firegento-rabbitmq) | ||
|
||
Description | ||
----------- | ||
This module provides the possibility to publish and consume messages via rabbitmq. You can define multiple queues and exchanges via rabbitmq.xml | ||
|
||
Requirements | ||
------------------- | ||
* PHP 5.3 or higher | ||
* [php-amqplib](https://github.com/php-amqplib/php-amqplib) | ||
|
||
Compatibility | ||
-------------- | ||
* Magento CE1.6.x-1.9.x/EE1.11.x-1.14.x | ||
|
||
Installation Instructions | ||
------------------------- | ||
1. Install the extension via composer or modman. If you use modman please install [php-amqplib](https://github.com/php-amqplib/php-amqplib) on your own. | ||
2. Clear the cache, logout from the admin panel and then login again. | ||
3. Configure and activate the extension under System - Configuration - FireGento - RabbitMQ | ||
4. set up connection credentials in local.xml | ||
|
||
```xml | ||
<config> | ||
<global> | ||
<resources> | ||
<rabbitmq> | ||
<default> | ||
<connection> | ||
<host>127.0.0.1</host> | ||
<port>5672</port> | ||
<user>vagrant</user> | ||
<password>vagrant</password> | ||
<vhost>firegento_develop</vhost> | ||
</connection> | ||
</default> | ||
</rabbitmq> | ||
</resources> | ||
</global> | ||
</config> | ||
``` | ||
Uninstallation | ||
-------------- | ||
1. Remove all extension files from your Magento installation | ||
|
||
Support | ||
------- | ||
If you have any issues with this extension, open an issue on [GitHub](https://github.com/firegento/FireGento_RabbitMQ/issues). | ||
|
||
Contribution | ||
------------ | ||
Any contribution is highly appreciated. The best way to contribute code is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests). | ||
|
||
Developer | ||
--------- | ||
FireGento Team | ||
* Website: [http://firegento.com](http://firegento.com) | ||
* Twitter: [@firegento](https://twitter.com/firegento) | ||
|
||
Team: | ||
* [Daniel Niedergesäß (Lead)](https://twitter.com/sqlexception) | ||
* [Andreas Mautz (Maintainer)](https://twitter.com/mautz_et_tong) | ||
|
||
License | ||
------- | ||
[GNU General Public License, version 3 (GPLv3)](http://opensource.org/licenses/gpl-3.0) | ||
|
||
Copyright | ||
--------- | ||
(c) 2011-2017 FireGento Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "firegento/rabbitmq", | ||
"license": ["GPL-3.0"], | ||
"type": "magento-module", | ||
"description": "RabbitMQ implementation for Magento 1 with producer and consumer", | ||
"homepage": "https://github.com/firegento/firegento-rabbitmq", | ||
"require": { | ||
"magento-hackathon/magento-composer-installer": "*", | ||
"php-amqplib/php-amqplib": "~2.6.0" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "composer", | ||
"url": "http://packages.firegento.com" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Collectors | ||
A collector collects objects on model save and delete actions. | ||
To create a collector, you need to add a new model and you need to adjust your config.xml. | ||
|
||
## Adding custom collectors | ||
Adding custom collectors for your own module / entity is simply adding a node in config.xml and creating a small collector model. | ||
|
||
|
||
```xml | ||
<config> | ||
<rabbitmq> | ||
<collectors> | ||
<your_unique_collector_identifier>your_module/collector</your_unique_identifier> | ||
</collectors> | ||
</amqp> | ||
</config> | ||
``` | ||
|
||
```php | ||
<?php | ||
|
||
class Your_Module_Model_Collector | ||
extends FireGento_RabbitMQ_Model_Abstract_Collector | ||
implements FireGento_RabbitMQ_Interface_Collector | ||
{ | ||
protected $applicableClasses = array( | ||
'Your_Module_Model_Entity' | ||
); | ||
} | ||
``` | ||
## Adding custom events | ||
Per default the collector listens to following applicable events "model_save_commit_after" and also "model_delete_commit_after". In case you need it you can customize it. In the following example i want to collect the customer login event. | ||
|
||
```xml | ||
<config> | ||
<global> | ||
<events> | ||
<customer_login> | ||
<observers> | ||
<rabbitmq_customer_login> | ||
<type>singleton</type> | ||
<class>rabbitmq/observer</class> | ||
<method>collect</method> | ||
</rabbitmq_customer_login> | ||
</observers> | ||
</customer_login> | ||
</collectors> | ||
</global> | ||
</config> | ||
``` | ||
|
||
|
||
```php | ||
<?php | ||
|
||
class Your_Module_Model_Collector | ||
extends FireGento_RabbitMQ_Model_Abstract_Collector | ||
implements FireGento_RabbitMQ_Interface_Collector | ||
{ | ||
protected $applicableClasses = array( | ||
'Mage_Customer_Model_Customer' | ||
); | ||
|
||
/** | ||
* List of applicable event names | ||
* | ||
* @var string[] | ||
*/ | ||
protected $applicableEvents = array( | ||
'customer_login' | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Consumer | ||
A consumer retrieves an AMQPMessage and dispatches an events with the data which is send via RabbitMQ. | ||
|
||
## Adding custom consumer | ||
To create a consumer, you need to create an rabbitmq.xml in the etc folder of your module. In the following example so see the implementation of an consumer with a name Navision. | ||
|
||
|
||
```xml | ||
<rabbitmq> | ||
<consumer> | ||
<navision ack="true" passive="false" durable="false" exclusive="false" auto_delete="false"> | ||
<topics> | ||
<bind exchange="magento.producer" topic="magento.navision.customer.*"/> | ||
<bind exchange="magento.producer" topic="magento.navision.customer.address.*"/> | ||
</topics> | ||
</navision> | ||
</consumer> | ||
</rabbitmq> | ||
``` | ||
|
||
As example the topic "magento.navision.customer.create" would dispatch an event "rabbitmq_magento_navision_customer_create". To get the events dispatched, you need to create an event area inside of the config.xml of your module. | ||
```xml | ||
<config> | ||
<navision> | ||
<events> | ||
<rabbitmq_magento_navision_customer_create> | ||
<observers> | ||
<!-- your observer logic --> | ||
</observers> | ||
</rabbitmq_magento_navision_customer_create> | ||
</navision> | ||
</config> | ||
``` | ||
|
||
|
||
Finally you can start your consumer `php shell/consumer.php --consume navision` | ||
|
||
Note | ||
---- | ||
If you wanna prevent an infinite loop during an model action in an consumer you can disable the collection / producing of events and messages in your consumer ```Mage::getSingleton('rabbitmq/observer')->disableEventCollectors()```. If you wanna reenable them ```Mage::getSingleton('rabbitmq/observer')->enableEventCollectors()``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Producer | ||
A producer returns an AMQPMessage with the data which is send via RabbitMQ. | ||
|
||
## Adding custom producers with standard message | ||
To create a producer, you also need to add a new model and adjust your config.xml. Per default all data in and object is returned. Per default a producer handles following applicable events "model_save_commit_after" and also "model_delete_commit_after". In case you need it you can also customize it. Simply add a property like in the collector example to produce a custom event message. | ||
|
||
```xml | ||
<config> | ||
<rabbitmq> | ||
<producers> | ||
<your_unique_producer_identifier>your_module/producer</your_unique_producer_identifier> | ||
</producers> | ||
</amqp> | ||
</config> | ||
``` | ||
|
||
```php | ||
<?php | ||
|
||
class Your_Module_Model_Producer | ||
extends FireGento_RabbitMQ_Applicable | ||
{ | ||
|
||
protected $routingKey = 'magento.yournamespace.yourentity.%s'; | ||
|
||
protected $applicableClasses = array( | ||
'YourNameSpace_YourModule_Model_YourModel' | ||
); | ||
} | ||
``` | ||
## Adding custom producers with custom message | ||
To customize the content of the message simply overload the method "getRabbitMQMessage" in your custom producer and add the content to the body content. | ||
|
||
```php | ||
<?php | ||
/** | ||
* Navision Service Customer RabbitMQ Message Producer | ||
* | ||
*/ | ||
class Service_Navision_Model_Producer_Customer | ||
extends FireGento_RabbitMQ_Producer | ||
{ | ||
|
||
/** | ||
* routing key / topic for message | ||
* | ||
* @var string | ||
*/ | ||
protected $routingKey = 'magento.navision.customer.%s'; | ||
|
||
/** | ||
* class names where producer is applicable | ||
* | ||
* @var string[] | ||
*/ | ||
protected $applicableClasses = array( | ||
'Mage_Customer_Model_Customer' | ||
); | ||
|
||
/** | ||
* get message for current object | ||
* | ||
* @return PhpAmqpLib\Message\AMQPMessage[] | ||
*/ | ||
protected function getRabbitMQMessage() | ||
{ | ||
$body = array(); | ||
$body['data'] = $this->getObject()->getId(); | ||
return $this->createRabbitmqMessage( | ||
sprintf($this->getRoutingKey(), $this->getEventType()), | ||
$body | ||
); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Troubleshooting | ||
|
||
* my consumer runs out of memory. | ||
- One of the problems is the Magento DB Profiler which collects stats for all queries. | ||
One solution is to disable the profiler in the local.xml | ||
```xml | ||
<profiler>false</profiler> | ||
``` | ||
- Another problem is a possible memory leak caused by not proberly destructed objects. A solution would be to call the following method | ||
```php | ||
Mage_Core_Model_Abstract::clearInstance() | ||
``` | ||
* my consumer saves a model and produces and infinite event loop | ||
- to prevent an infinite loop during an model action in an consumer you can disable the collection / producing of events and messages in your consumer | ||
```php | ||
Mage::getSingleton('rabbitmq/observer')->disableEventCollectors() | ||
``` | ||
- to enable them again you can use | ||
```php | ||
Mage::getSingleton('rabbitmq/observer')->enableEventCollectors() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src/app/etc/modules/FireGento_RabbitMQ.xml app/etc/modules/FireGento_RabbitMQ.xml | ||
src/app/code/core/FireGento/RabbitMQ app/code/community/FireGento/RabbitMQ | ||
src/shell/consumer.php shell/consumer.php |
Oops, something went wrong.