forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_task.php
36 lines (26 loc) · 829 Bytes
/
new_task.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
<?php
// composer require enqueue/amqp-bunny
require_once __DIR__.'/vendor/autoload.php';
use Enqueue\AmqpBunny\AmqpConnectionFactory;
use Interop\Amqp\AmqpMessage;
use Interop\Amqp\AmqpQueue;
$config = [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
];
$connection = new AmqpConnectionFactory($config);
$context = $connection->createContext();
$queue = $context->createQueue('task_queue');
$queue->addFlag(AmqpQueue::FLAG_DURABLE);
$context->declareQueue($queue);
$data = implode(' ', array_slice($argv, 1));
if (empty($data)) {
$data = 'Hello World!';
}
$message = $context->createMessage($data);
$message->setDeliveryMode(AmqpMessage::DELIVERY_MODE_PERSISTENT);
$context->createProducer()->send($queue, $message);
echo ' [x] Sent ', $data, "\n";
$context->close();