本文整理汇总了PHP中AMQPQueue类的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue类的具体用法?PHP AMQPQueue怎么用?PHP AMQPQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AMQPQueue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _initPublisher
private function _initPublisher()
{
if (!$this->open()) {
return false;
}
if ($this->_exchange) {
return true;
}
$channel = new AMQPChannel($this->_conn);
//创建exchange
$this->_exchange = new AMQPExchange($channel);
$this->_exchange->setName($this->_connInfo['exchangeName']);
$this->_exchange->setType(AMQP_EX_TYPE_DIRECT);
$this->_exchange->setFlags(AMQP_DURABLE);
if (!$this->_exchange->declareExchange()) {
$this->close();
return false;
}
//创建队列,生产者和消费者都要创建队列
$queue = new AMQPQueue($channel);
$queue->setName($this->_connInfo['queueName']);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
$queue->bind($this->_connInfo['exchangeName'], $this->_connInfo['routingKey']);
return true;
}
开发者ID:ehovel,项目名称:message-queue,代码行数:26,代码来源:RabbitQueue.php
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('Move messages from queue "%s" (vhost: "%s") to exchange "%s" with routingKey "%s" (vhost: "%s")', $input->getArgument('from_queue'), $input->getArgument('from_vhost'), $input->getArgument('to_exchange'), $input->getArgument('to_routing_key'), $input->getArgument('to_vhost')));
$fromChannel = $this->getChannel($input->getArgument('from_connection'), $input->getArgument('from_vhost'));
if (null === ($toConnectionName = $input->getOption('to_connection'))) {
$toChannel = $this->getChannel($input->getArgument('from_connection'), $input->getArgument('to_vhost'));
} else {
$toChannel = $this->getChannel($input->getOption('to_connection'), $input->getArgument('to_vhost'));
}
$queue = new \AMQPQueue($fromChannel);
$queue->setName($input->getArgument('from_queue'));
$exchange = new \AMQPExchange($toChannel);
$exchange->setName($input->getArgument('to_exchange'));
$messageProvider = new PeclPackageMessageProvider($queue);
$messagePublisher = new PeclPackageMessagePublisher($exchange);
$options = array();
$stack = new \Swarrot\Processor\Stack\Builder();
if (0 !== ($max = (int) $input->getOption('max-messages'))) {
$stack->push('Swarrot\\Processor\\MaxMessages\\MaxMessagesProcessor');
$options['max_messages'] = $max;
}
$stack->push('Swarrot\\Processor\\Insomniac\\InsomniacProcessor');
$stack->push('Swarrot\\Processor\\Ack\\AckProcessor', $messageProvider);
$processor = $stack->resolve(new MoveProcessor($messagePublisher, $input->getArgument('to_routing_key')));
$consumer = new Consumer($messageProvider, $processor);
$consumer->consume($options);
}
开发者ID:stof,项目名称:rabbit-mq-admin-toolkit,代码行数:27,代码来源:MessageMoveCommand.php
示例3: process
/**
* @param \AMQPEnvelope $envelope
* @param \AMQPQueue $queue
* @param PushPipe $pushPipe
* @param string $errorQueue
* @param ReceiveCancellationToken $cancellationToken
* @param EndpointControlToken $endpointControlToken
*
* @return bool
*/
public function process(\AMQPEnvelope $envelope, \AMQPQueue $queue, PushPipe $pushPipe, $errorQueue, ReceiveCancellationToken $cancellationToken, EndpointControlToken $endpointControlToken)
{
try {
$messageId = '';
$headers = [];
$pushMessage = false;
try {
$messageId = $this->messageConverter->retrieveMessageId($envelope);
$headers = $this->messageConverter->retrieveHeaders($envelope);
$pushMessage = true;
} catch (\Exception $e) {
$this->routingTopology->sendToQueue($this->brokerModel, $errorQueue, $envelope->getBody(), ['headers' => $envelope->getHeaders()]);
}
if ($pushMessage) {
$pushPipe->push(new PushContext($messageId, $headers, $envelope->getBody() ?: '', $cancellationToken, $endpointControlToken));
}
if ($cancellationToken->isCancellationRequested()) {
$queue->reject($envelope->getDeliveryTag(), AMQP_REQUEUE);
} else {
$queue->ack($envelope->getDeliveryTag());
}
} catch (CriticalErrorException $e) {
// just ... die
throw $e;
} catch (\Exception $e) {
$queue->reject($envelope->getDeliveryTag(), AMQP_REQUEUE);
}
if ($endpointControlToken->isShutdownRequested()) {
return false;
}
return true;
}
开发者ID:phpservicebus,项目名称:core,代码行数:42,代码来源:MessageProcessor.php
示例4: Run
public function Run()
{
// Declare a new exchange
$ex = new AMQPExchange($this->cnn);
$ex->declare('game', AMQP_EX_TYPE_FANOUT);
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q2 = new AMQPQueue($this->cnn);
$q2->declare('queue2');
// Bind it on the exchange to routing.key
//$ex->bind('queue1', 'broadcast=true,target=queue1,x-match=any');
$ex->bind('queue1', '');
$ex->bind('queue2', '');
$msgBody = 'hello';
// Publish a message to the exchange with a routing key
$ex->publish($msgBody, 'foo');
// Read from the queue
$msg = $q1->consume();
$this->AssertEquals(count($msg), 1);
$this->AssertEquals($msg[0]['message_body'], $msgBody, 'message not equal');
// Read from the queue
$msg = $q2->consume();
$this->AssertEquals(count($msg), 1);
$this->AssertEquals($msg[0]['message_body'], $msgBody, 'message not equal');
$this->AddMessage(var_export($msg[0], true));
}
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:27,代码来源:amqp_ut.php
示例5: bind
/**
* Bind queue to exchange using dispatcher event names as routing keys
*
* @return void
* @throws AMQPExchangeException
*/
public function bind(\AMQPQueue $queue, \AMQPExchange $exchange)
{
$events = preg_grep($this->pattern, array_keys($this->getDispatcher()->getListeners()));
foreach ($events as $eventName) {
$queue->bind($exchange->getName(), $eventName);
}
$this->dispatcher->dispatch(static::BIND_EVENT, new SymfonyEvent($events, ["pattern" => $this->pattern, "exchange" => $exchange->getName(), "queue" => $queue->getName()]));
}
开发者ID:gallna,项目名称:amqp-event,代码行数:14,代码来源:Consumer.php
示例6: declareQueue
public function declareQueue($name, $flags = AMQP_DURABLE)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($name);
$queue->setFlags($flags);
$queue->declareQueue();
return $queue;
}
开发者ID:Jmoati,项目名称:SwarrotBootstrapBundle,代码行数:8,代码来源:PeclAmqpPackageProvider.php
示例7: getAMQPQueue
protected function getAMQPQueue($name)
{
$connection = new \AMQPConnection(array('vhost' => 'swarrot'));
$connection->connect();
$channel = new \AMQPChannel($connection);
$queue = new \AMQPQueue($channel);
$queue->setName($name);
return $queue;
}
开发者ID:Niktux,项目名称:swarrot,代码行数:9,代码来源:PeclPackageMessageProviderTest.php
示例8: getQueue
/**
* @param string $name
*
* @return \AMQPQueue
*/
protected function getQueue($name)
{
if (!isset($this->queues[$name])) {
$queue = new \AMQPQueue($this->getChannel());
$queue->setName($name);
$this->queues[$name] = $queue;
}
return $this->queues[$name];
}
开发者ID:event-band,项目名称:band-transport-amqp-pecl,代码行数:14,代码来源:PeclAmqpDriver.php
示例9: register
/**
* {@inheritDoc}
*/
public function register(Container $c)
{
$c['amqp.connections.initializer'] = function ($c) {
$config = $c['amqp.options'];
$connections = array();
if (isset($config['connections'])) {
foreach ($config['connections'] as $name => $options) {
$connections[$name] = new \AMQPConnection($options);
}
return $connections;
}
if (isset($config['connection'])) {
return array('default' => new \AMQPConnection($config['connection']));
}
throw new \LogicException('No connection defined');
};
$c['queue.factory'] = function ($c) {
$connections = $c['amqp.connections.initializer'];
return function ($queueName, $connectionName = null) use($connections) {
$names = array_keys($connections);
if (null === $connectionName) {
$connectionName = reset($names);
}
if (!array_key_exists($connectionName, $connections)) {
throw new \InvalidArgumentException(sprintf('Unknown connection "%s". Available: [%s]', $connectionName, implode(', ', $names)));
}
$connection = $connections[$connectionName];
if (!$connection->isConnected()) {
$connection->connect();
}
$channel = new \AMQPChannel($connection);
$queue = new \AMQPQueue($channel);
$queue->setName($queueName);
return $queue;
};
};
$c['exchange.factory'] = function ($c) {
$connections = $c['amqp.connections.initializer'];
return function ($exchangeName, $connectionName = null) use($connections) {
$names = array_keys($connections);
if (null === $connectionName) {
$connectionName = reset($names);
}
if (!array_key_exists($connectionName, $connections)) {
throw new \InvalidArgumentException(sprintf('Unknown connection "%s". Available: [%s]', $connectionName, implode(', ', $names)));
}
$connection = $connections[$connectionName];
if (!$connection->isConnected()) {
$connection->connect();
}
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName($exchangeName);
return $exchange;
};
};
}
开发者ID:odolbeau,项目名称:amqp-service-provider,代码行数:60,代码来源:AMQPServiceProvider.php
示例10: get
public function get($queueName, $timeout = null)
{
if (null === $this->queue) {
$queue = new \AMQPQueue($this->channel);
$queue->setName($queueName);
$queue->declare();
}
return unserialize($queue->consume());
}
开发者ID:rcambien,项目名称:riverline-worker-bundle,代码行数:9,代码来源:AMQP.php
示例11: createQueue
/**
* @inheritdoc
*/
public function createQueue(ChannelInterface $channel, $name = null, $flags = null, array $args = [])
{
$delegate = new \AMQPQueue($channel->getDelegate());
$delegate->setFlags(Queue::convertToDelegateFlags($flags));
$delegate->setArguments($args);
if (null !== $name) {
$delegate->setName($name);
}
return new Queue($delegate, $channel);
}
开发者ID:treehouselabs,项目名称:queue,代码行数:13,代码来源:AmqpFactory.php
示例12: read
/**
* @param \AMQPQueue $queue
* @return bool|string
*/
public static function read(\AMQPQueue $queue)
{
usleep(10000);
$envelope = $queue->get(\AMQP_NOPARAM);
if ($envelope) {
$message = $envelope->getBody();
$queue->ack($envelope->getDeliveryTag());
return $message;
}
return false;
}
开发者ID:zarincheg,项目名称:celium,代码行数:15,代码来源:Rabbit.php
示例13: Run
public function Run()
{
// Declare a new exchange
$ex = new AMQPExchange($this->cnn);
$ex->declare('game', AMQP_EX_TYPE_TOPIC);
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q1->purge('queue1');
$q2 = new AMQPQueue($this->cnn);
$q2->declare('queue2');
$q1->purge('queue2');
$q3 = new AMQPQueue($this->cnn);
$q3->declare('queue3');
$q3->purge('queue3');
$options = array('min' => 0, 'max' => 10, 'ack' => true);
// Bind it on the exchange to routing.key
$ex->bind('queue1', 'game1.#');
$ex->bind('queue2', 'game1.#');
$ex->bind('queue3', 'game1.#');
$ex->bind('queue3', 'queue3.#');
$msgbody1 = 'hello';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody1, 'game1.msg');
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody2 = 'world';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody2, 'game1.msg');
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody3 = 'hello player3';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody3, 'queue3.command');
$this->AssertEquals($result, TRUE, 'publish message failed');
// Read from the queue
$msg = $q1->consume($options);
$this->AddMessage(var_export($msg, true));
$this->AssertEquals(count($msg), 2);
$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q2->consume($options);
$this->AssertEquals(count($msg), 2);
$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q3->consume($options);
$this->AddMessage(var_export($msg, true));
$this->AssertEquals(count($msg), 3);
$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
$this->AssertEquals($msg[2]['message_body'], $msgbody3, 'message not equal');
$msg = $q3->consume($options);
$this->AssertEquals(count($msg), 0);
}
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:54,代码来源:amqp_topic_ut.php
示例14: take
public function take()
{
$q = new \AMQPQueue($this->amqpChannel);
$q->setName($this->name);
$msg = $q->get();
if (empty($msg)) {
return false;
} else {
return new MessageTakeControl($q, $msg);
}
}
开发者ID:xezzus,项目名称:amqp-im,代码行数:11,代码来源:Message.php
示例15: getQueue
/**
* getQueue.
*
* @param string $name
* @param string $connection
*
* @return \AMQPQueue
*/
public function getQueue($name, $connection)
{
if (!isset($this->queues[$connection][$name])) {
if (!isset($this->queues[$connection])) {
$this->queues[$connection] = array();
}
$queue = new \AMQPQueue($this->getChannel($connection));
$queue->setName($name);
$this->queues[$connection][$name] = $queue;
}
return $this->queues[$connection][$name];
}
开发者ID:virhi,项目名称:SwarrotBundle,代码行数:20,代码来源:PeclFactory.php
示例16: Run
public function Run()
{
// Declare a new exchange
$ex = new AMQPExchange($this->cnn);
$ex->declare('game', AMQP_EX_TYPE_HEADER);
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q1->purge('queue1');
$q2 = new AMQPQueue($this->cnn);
$q2->declare('queue2');
$q1->purge('queue2');
$q3 = new AMQPQueue($this->cnn);
$q3->declare('queue3');
$q3->purge('queue3');
$options = array('min' => 0, 'max' => 10, 'ack' => true);
// Bind it on the exchange to routing.key
$ex->bind('queue1', 'broadcast=1,target=1,x-match=any');
$ex->bind('queue2', 'broadcast=1,target=2,x-match=any');
$ex->bind('queue3', 'broadcast=1,target=3,x-match=any');
$msgbody1 = 'hello';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody1, NULL, AMQP_IMMEDIATE, array('headers' => array('broadcast' => 1)));
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody2 = 'world';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody2, NULL, AMQP_IMMEDIATE, array('headers' => array('broadcast' => 1)));
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody3 = 'queue3';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody1, NULL, AMQP_IMMEDIATE, array('headers' => array('target' => 3)));
$this->AssertEquals($result, TRUE, 'publish message failed');
// Read from the queue
$msg = $q1->consume($options);
$this->AddMessage(var_export($msg, true));
$this->AssertEquals(count($msg), 2);
//$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
//$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q2->consume($options);
$this->AssertEquals(count($msg), 2);
//$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
//$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q3->consume($options);
$this->AssertEquals(count($msg), 3);
//$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
//$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
//$this->AssertEquals($msg[2]['message_body'], $msgbody3, 'message not equal');
}
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:50,代码来源:amqp_xmatch_ut.php
示例17: setUpAmqp
/**
* {@inheritDoc}
*/
protected function setUpAmqp()
{
$this->conn = new \AMQPConnection(['host' => $_SERVER['AMQP_HOST'], 'port' => $_SERVER['AMQP_PORT'], 'login' => $_SERVER['AMQP_USER'], 'password' => $_SERVER['AMQP_PASS'], 'vhost' => $_SERVER['AMQP_VHOST']]);
$this->conn->connect();
$channel = new \AMQPChannel($this->conn);
$exchange = new \AMQPExchange($channel);
$exchange->setName('event_band.test.exchange');
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->setType(AMQP_EX_TYPE_TOPIC);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName('event_band.test.event');
$queue->declareQueue();
$queue->bind('event_band.test.exchange', 'event.#');
}
开发者ID:event-band,项目名称:band-transport-amqp-pecl,代码行数:18,代码来源:PeclAmqpDriverTest.php
示例18: consume
public function consume($queueName, $callBackFunction)
{
try {
$queue = new AMQPQueue($this->channel);
$queue->setName($queueName);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
echo ' [*] Waiting for messages on ' . $queueName . '. To exit press CTRL+C ', PHP_EOL;
$queue->consume($callBackFunction);
} catch (AMQPQueueException $ex) {
print_r($ex);
} catch (Exception $ex) {
print_r($ex);
}
}
开发者ID:inilotic,项目名称:vks_nodes_core,代码行数:15,代码来源:AMQWrapper.class.php
示例19: setupConnection
public static function setupConnection(\AMQPConnection $connection, $config)
{
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName($config['exchange_name']);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->setFlags(AMQP_DURABLE);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName($config['queue_name']);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
// $exchange->bind($config['queue_name'], 'gos.websocket.pusher');
return [$channel, $exchange, $queue];
}
开发者ID:rsrodrig,项目名称:MeetMeSoftware,代码行数:15,代码来源:Utils.php
示例20: Run
public function Run()
{
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q1->purge('queue1');
$options = array('min' => 0, 'max' => 10, 'ack' => true);
// Bind it on the exchange to routing.key
$q1->bind(\Constant\AMQPChannelConstant::AMF, \Constant\AMQPCommand::BingoBroadcast);
// Read from the queue
while (TRUE) {
$msg = $q1->consume($options);
var_dump($msg);
}
}
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:15,代码来源:amqp_amfevent_ut.php
注:本文中的AMQPQueue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论