forked from c3zi/DataAggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
producer.php
38 lines (30 loc) · 973 Bytes
/
producer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* Created by PhpStorm.
* User: c3zi
* Date: 16/06/15
* Time: 21:05
*/
require_once __DIR__.'/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
use DataAggregator\InputProvider\FileProvider;
$path = __DIR__ . '/data/facebook_contacts.txt';
try {
$fileProvider = new FileProvider($path);
} catch (\InvalidArgumentException $ex) {
print(sprintf("Some probles with file: %s\n", $path));
die();
}
$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
//$channel->queue_declare('task_aggregator3', false, true, false, false);
foreach ($fileProvider->load() as $contact) {
$msg = new AMQPMessage($contact,
array('delivery_mode' => 2) # make message persistent
);
$channel->basic_publish($msg, '', 'task_aggregator3');
}
print(sprintf("\n [x] Sent contacts from file: %s\n", $path));
$channel->close();
$connection->close();