Example #1
0
 public function it_should_create_exchange_from_connection_name(ConnectionRegistry $connectionRegistry, Connection $connection, ChannelFactory $channelFactory, ExchangeRegistry $exchangeRegistry, ExchangeFactory $exchangeFactory, Channel $channel, Exchange $exchange)
 {
     $connectionRegistry->getConnection('default')->willReturn($connection);
     $channelFactory->createFromConnection($connection, Argument::type(Identity::class))->willReturn($channel);
     $exchangeRegistry->hasExchange('exchange', $channel)->willReturn(false);
     $exchangeFactory->createNamed('exchange', $channel)->willReturn($exchange);
     $this->create('default', 'exchange')->shouldReturnAnInstanceOf(Publisher::class);
 }
Example #2
0
 public function it_should_reuse_existing_exchange_when_its_same_channel_and_same_exchange(ConnectionRegistry $connectionRegistry, Connection $connection, ChannelFactory $channelFactory, Channel $channel, Exchange $exchange, Queue $queue, ExchangeRegistry $exchangeRegistry, QueueRegistry $queueRegistry)
 {
     $connectionRegistry->getConnection('default')->willReturn($connection);
     $channelFactory->createFromConnection($connection, Argument::type(Identity::class))->willReturn($channel);
     $exchangeRegistry->hasExchange('exchange', $channel)->willReturn(true);
     $exchangeRegistry->getExchange('exchange', $channel)->willReturn($exchange);
     $queueRegistry->hasQueue('queue', $channel, $exchange)->willReturn(true);
     $queueRegistry->getQueue('queue', $channel, $exchange)->willReturn($queue);
     $consumer = $this->createFromConnection($connection, 'exchange', 'queue');
     $consumer->shouldBeAnInstanceOf(Consumer::class);
 }
Example #3
0
 /**
  * @param Connection $connection
  * @param string     $exchangeName
  * @param array      $options
  *
  * @return Publisher
  */
 public function createFromConnection(Connection $connection, $exchangeName, Channel $channel = null, array $options = [])
 {
     $identity = new Identity();
     if (null === $channel) {
         $channel = $this->channelFactory->createFromConnection($connection, $identity);
     }
     if (!$this->exchangeRegistry->hasExchange($exchangeName, $channel)) {
         $exchange = $this->exchangeFactory->createNamed($exchangeName, $channel);
     } else {
         $exchange = $this->exchangeRegistry->getExchange($exchangeName, $channel);
     }
     $publisher = new Publisher($identity, $this->eventDispatcher, $connection, $channel, $exchange, $options);
     return $publisher;
 }
Example #4
0
 /**
  * @param Connection $connection
  * @param string     $exchangeName
  * @param string     $queueName
  *
  * @return Consumer
  */
 public function createFromConnection(Connection $connection, $exchangeName, $queueName)
 {
     $identity = new Identity();
     $channel = $this->channelFactory->createFromConnection($connection, $identity);
     if (!$this->exchangeRegistry->hasExchange($exchangeName, $channel)) {
         $exchange = $this->exchangeFactory->createNamed($exchangeName, $channel);
     } else {
         $exchange = $this->exchangeRegistry->getExchange($exchangeName, $channel);
     }
     if (!$this->queueRegistry->hasQueue($queueName, $channel, $exchange)) {
         $queue = $this->queueFactory->createNamed($queueName, $channel, $exchange);
     } else {
         $queue = $this->queueRegistry->getQueue($queueName, $channel, $exchange);
     }
     $consumer = new Consumer($identity, $connection, $channel, $exchange, $queue);
     return $consumer;
 }
Example #5
0
use Evaneos\Hector\Consumer\ConsumerFactory;
use Evaneos\Hector\Context\ContextRegistry;
use Evaneos\Hector\Exchange\Context;
use Evaneos\Hector\Exchange\ExchangeFactory;
use Evaneos\Hector\Exchange\ExchangeRegistry;
use Evaneos\Hector\Identity\Identity;
use Evaneos\Hector\Queue\QueueFactory;
use Evaneos\Hector\Queue\QueueRegistry;
require __DIR__ . '/vendor/autoload.php';
$connectionRegistry = new ConnectionRegistry();
$channelRegistry = new ChannelRegistry();
$exchangeRegistry = new ExchangeRegistry();
$queueRegistry = new QueueRegistry();
$contextRegistry = new ContextRegistry();
$connectionFactory = new ConnectionFactory($connectionRegistry, ['default' => ['host' => 'rabbitmq', 'port' => 5672, 'login' => 'admin', 'password' => 'admin', 'vhost' => '/', 'read_timeout' => 0.5, 'write_timeout' => 0.5, 'conntect_timeout' => 0.5]]);
$channelFactory = new ChannelFactory($connectionRegistry, $channelRegistry, $channelFactory);
$connection = $connectionFactory->createNamed('default');
$contextRegistry->addExchangeContext('exchange_a', new Context(\AMQP_DURABLE));
$contextRegistry->addExchangeContext('exchange_b', new Context(\AMQP_DURABLE));
$contextRegistry->addExchangeContext('exchange_c', new Context(\AMQP_DURABLE));
$contextRegistry->addQueueContext('queue_a_foo', new \Evaneos\Hector\Queue\Context('a.foo'));
$contextRegistry->addQueueContext('queue_a_bar', new \Evaneos\Hector\Queue\Context('a.bar'));
$contextRegistry->addQueueContext('queue_b', new \Evaneos\Hector\Queue\Context());
$exchangeFactory = new ExchangeFactory($contextRegistry, $exchangeRegistry);
// A channel is a virtual connection to insulate work process inside her.
// Our worker will process across 3 queues from different exchange, all communication between the broker and worker will be through this channel
$channel = $channelFactory->createFromConnectionName('default', new Identity());
$exchangeA = $exchangeFactory->createNamed('exchange_a', $channel);
$exchangeB = $exchangeFactory->createNamed('exchange_b', $channel);
$queueFactory = new QueueFactory($contextRegistry, $queueRegistry);
/**
Example #6
0
use Evaneos\Hector\Context\ContextRegistry;
use Evaneos\Hector\Exchange\Context;
use Evaneos\Hector\Exchange\ExchangeFactory;
use Evaneos\Hector\Exchange\ExchangeRegistry;
use Evaneos\Hector\Identity\Identity;
use Evaneos\Hector\Publisher\PublisherFactory;
use Evaneos\Hector\Queue\QueueFactory;
use Evaneos\Hector\Queue\QueueRegistry;
require __DIR__ . '/vendor/autoload.php';
$connectionRegistry = new ConnectionRegistry();
$channelRegistry = new ChannelRegistry();
$exchangeRegistry = new ExchangeRegistry();
$queueRegistry = new QueueRegistry();
$contextRegistry = new ContextRegistry();
$connectionFactory = new ConnectionFactory($connectionRegistry, ['default' => ['host' => 'rabbitmq', 'port' => 5672, 'login' => 'admin', 'password' => 'admin', 'vhost' => '/', 'read_timeout' => 0.5, 'write_timeout' => 0.5, 'conntect_timeout' => 0.5]]);
$channelFactory = new ChannelFactory($connectionRegistry, $channelRegistry, $channelFactory);
$connection = $connectionFactory->createNamed('default');
$contextRegistry->addExchangeContext('exchange_a', new Context(AMQP_EX_TYPE_DIRECT));
$contextRegistry->addExchangeContext('exchange_b', new Context(AMQP_EX_TYPE_DIRECT));
$contextRegistry->addExchangeContext('exchange_c', new Context(AMQP_EX_TYPE_DIRECT));
$contextRegistry->addQueueContext('queue_a_foo', new \Evaneos\Hector\Queue\Context('a.foo', AMQP_AUTOACK));
$contextRegistry->addQueueContext('queue_a_bar', new \Evaneos\Hector\Queue\Context('a.bar', AMQP_AUTOACK));
$contextRegistry->addQueueContext('queue_b', new \Evaneos\Hector\Queue\Context('', AMQP_AUTOACK));
$exchangeFactory = new ExchangeFactory($contextRegistry, $exchangeRegistry);
$channelProcess1 = $channelFactory->createFromConnectionName('default', new Identity());
$channelProcess2 = $channelFactory->createFromConnectionName('default', new Identity());
$channelProcess3 = $channelFactory->createFromConnectionName('default', new Identity());
$exchangeAProcess1 = $exchangeFactory->createNamed('exchange_a', $channelProcess1);
$exchangeAProcess2 = $exchangeFactory->createNamed('exchange_a', $channelProcess2);
$exchangeBProcess3 = $exchangeFactory->createNamed('exchange_b', $channelProcess3);
$queueFactory = new QueueFactory($contextRegistry, $queueRegistry);
use Evaneos\Hector\Connection\ConnectionRegistry;
use Evaneos\Hector\Context\ContextRegistry;
use Evaneos\Hector\Exchange\Context;
use Evaneos\Hector\Exchange\ExchangeFactory;
use Evaneos\Hector\Exchange\ExchangeRegistry;
use Evaneos\Hector\Identity\Identity;
use Evaneos\Hector\Publisher\PublisherFactory;
use Evaneos\Hector\Queue\QueueRegistry;
require __DIR__ . '/vendor/autoload.php';
$connectionRegistry = new ConnectionRegistry();
$channelRegistry = new ChannelRegistry();
$exchangeRegistry = new ExchangeRegistry();
$queueRegistry = new QueueRegistry();
$contextRegistry = new ContextRegistry();
$connectionFactory = new ConnectionFactory($connectionRegistry, ['default' => ['host' => 'rabbitmq', 'port' => 5672, 'login' => 'admin', 'password' => 'admin', 'vhost' => '/', 'read_timeout' => 0.5, 'write_timeout' => 0.5, 'conntect_timeout' => 0.5]]);
$channelFactory = new ChannelFactory($connectionRegistry, $channelRegistry, $channelFactory);
$connection = $connectionFactory->createNamed('default');
$contextRegistry->addExchangeContext('exchange_a', new Context(\AMQP_EX_TYPE_DIRECT));
$contextRegistry->addExchangeContext('exchange_b', new Context(\AMQP_EX_TYPE_DIRECT));
$exchangeFactory = new ExchangeFactory($contextRegistry, $exchangeRegistry);
$channelA = $channelFactory->createFromConnectionName('default', new Identity());
$channelB = $channelFactory->createFromConnectionName('default', new Identity());
$exchange = $exchangeFactory->createNamed('exchange_a', $channelA);
$exchange = $exchangeFactory->createNamed('exchange_b', $channelB);
$publisherFactory = new PublisherFactory($connectionRegistry, $exchangeFactory, $channelFactory, null, $exchangeRegistry);
$publisherA = $publisherFactory->create('default', 'exchange_a');
$publisherB = $publisherFactory->create('default', 'exchange_b');
//simple publish to a
$publisherA->publish('Hello world', 'routing_key');
//simple publish to b
$publisherB->publish('Hello world', 'routing_key');