示例#1
0
 public function it_should_create_queue_from_name(Channel $channel, Exchange $exchange, ContextRegistry $contextRegistry, QueueRegistry $queueRegistry, Context $context)
 {
     $contextRegistry->getQueueContext('queue')->willReturn($context);
     $queueRegistry->addQueue(Argument::type(Queue::class))->shouldBeCalled();
     $queue = $this->createNamed('queue', $channel, $exchange);
     $queueRegistry->addQueue($queue)->shouldHaveBeenCalled();
 }
示例#2
0
 public function it_should_create_exchange(Channel $channel, ExchangeRegistry $exchangeRegistry, ContextRegistry $contextRegistry, Context $context)
 {
     $contextRegistry->getExchangeContext('exchange')->willReturn($context);
     $exchange = $this->createNamed('exchange', $channel);
     $exchangeRegistry->addExchange($exchange)->shouldHaveBeenCalled();
 }
示例#3
0
use Evaneos\Hector\Connection\ConnectionFactory;
use Evaneos\Hector\Connection\ConnectionRegistry;
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);
示例#4
0
 /**
  * @param string  $name
  * @param Channel $channel
  *
  * @return Exchange
  */
 public function createNamed($name, Channel $channel)
 {
     $exchange = new Exchange($name, $channel, $this->contextRegistry->getExchangeContext($name));
     $this->exchangeRegistry->addExchange($exchange);
     return $exchange;
 }
示例#5
0
<?php

use Evaneos\Hector\Channel\ChannelFactory;
use Evaneos\Hector\Channel\ChannelRegistry;
use Evaneos\Hector\Connection\ConnectionFactory;
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\QueueFactory;
use Evaneos\Hector\Queue\QueueRegistry;
use Symfony\Component\EventDispatcher\EventDispatcher;
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));
$exchangeFactory = new ExchangeFactory($contextRegistry, $exchangeRegistry);
$channel = $channelFactory->createFromConnectionName('default', new Identity());
$exchange = $exchangeFactory->createNamed('exchange_a', $channel);
$publisherFactory = new PublisherFactory($connectionRegistry, $exchangeFactory, $channelFactory, null, $exchangeRegistry);
$publisher = $publisherFactory->create('default', 'exchange_a');
$publisher->publish('Hello world', 'routing_key');
示例#6
0
use Evaneos\Hector\Connection\ConnectionRegistry;
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\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);
示例#7
0
 /**
  * @param string   $name
  * @param Channel  $channel
  * @param Exchange $exchange
  *
  * @return Queue
  */
 public function createNamed($name, Channel $channel, Exchange $exchange)
 {
     $queue = new Queue($name, $channel, $exchange, $this->contextRegistry->getQueueContext($name));
     $this->registry->addQueue($queue);
     return $queue;
 }