Ejemplo n.º 1
0
 public function setUp()
 {
     $this->connection = new Connection(AMQP_TEST_HOST);
     $this->channel = $this->connection->channel();
     $this->channel->exchangeDeclare($this->exchangeName, 'direct', array('auto_delete' => false));
     list($this->queueName, , ) = $this->channel->queueDeclare();
     $this->channel->queueBind($this->queueName, $this->exchangeName, array('routing_key' => $this->queueName));
 }
Ejemplo n.º 2
0
<?php

include __DIR__ . '/config.php';
use AMQP\Connection;
use AMQP\Message;
$exchange = 'fanout_example_exchange';
$connection = new Connection(AMQP_RESOURCE);
$channel = $connection->channel();
/*
    name: $exchange
    type: fanout
    passive: false // don't check is an exchange with the same name exists
    durable: false // the exchange won't survive server restarts
    auto_delete: true //the exchange will be deleted once the channel is closed.
*/
$channel->exchangeDeclare($exchange, 'fanout');
$messageBody = implode(' ', array_slice($argv, 1));
$message = new Message($messageBody, array('content_type' => 'text/plain'));
$channel->basicPublish($message, array('exchange' => $exchange));
$channel->close();
$connection->close();
Ejemplo n.º 3
0
<?php

include __DIR__ . '/config.php';
use AMQP\Connection;
use AMQP\Message;
$exchange = 'basic_get_test';
$queue = 'basic_get_queue';
$conn = new Connection(AMQP_RESOURCE);
$ch = $conn->channel();
/*
    The following code is the same both in the consumer and the producer.
    In this way we are sure we always have a queue to consume from and an
        exchange where to publish messages.
*/
/*
    name: $queue
    passive: false
    durable: true // the queue will survive server restarts
    exclusive: false // the queue can be accessed in other channels
    auto_delete: false //the queue won't be deleted once the channel is closed.
*/
$ch->queueDeclare(array('queue' => $queue, 'durable' => true, 'auto_delete' => false));
/*
    name: $exchange
    type: direct
    passive: false
    durable: true // the exchange will survive server restarts
    auto_delete: false //the exchange won't be deleted once the channel is closed.
*/
$ch->exchangeDeclare($exchange, 'direct', array('durable' => true, 'auto_delete' => false));
$ch->queueBind($queue, $exchange);