Skip to content

Commit 296e0e4

Browse files
committedOct 2, 2016
add rabbitmq to nab3a bundle.
1 parent 7f2cff2 commit 296e0e4

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
 

‎RabbitMq/EnqueueTweetPlugin.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace RShief\Nab3aBundle\RabbitMq;
4+
5+
use RShief\Nab3aBundle\Evenement\PluginInterface;
6+
use Evenement\EventEmitterInterface;
7+
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
8+
9+
class EnqueueTweetPlugin implements PluginInterface
10+
{
11+
/**
12+
* @var ProducerInterface
13+
*/
14+
private $producer;
15+
/**
16+
* @var string
17+
*/
18+
private $routingKey;
19+
/**
20+
* @var array
21+
*/
22+
private $additionalProperties;
23+
24+
public function __construct(ProducerInterface $producer, $routingKey = '', $additionalProperties = array())
25+
{
26+
$this->producer = $producer;
27+
$this->routingKey = $routingKey;
28+
$this->additionalProperties = $additionalProperties;
29+
}
30+
31+
public function attachEvents(EventEmitterInterface $emitter)
32+
{
33+
$emitter->on('tweet', function ($data) {
34+
$data = json_encode($data);
35+
$this->producer->publish($data, $this->routingKey, $this->additionalProperties);
36+
});
37+
}
38+
39+
/**
40+
* @param $data
41+
*/
42+
private function enqueue($data)
43+
{
44+
}
45+
}

‎Resources/config/rabbitmq.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
nab3a.twitter.message_emitter.plugin.rabbitmq:
3+
class: RShief\Nab3aBundle\RabbitMq\EnqueueTweetPlugin
4+
arguments:
5+
- '@old_sound_rabbit_mq.twitter_producer'
6+
- 'twitter'
7+
- { content_type: 'application/json' }
8+
public: false
9+
tags:
10+
- { name: evenement.plugin, id: nab3a.twitter.message_emitter }

‎Resources/config/services.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ imports:
44
- { resource: console.yml }
55
- { resource: stream.yml }
66
- { resource: event_loop.yml }
7+
- { resource: rabbitmq.yml }
78

89
services:
910
nab3a.standalone.parameters:

0 commit comments

Comments
 (0)
Please sign in to comment.