本文整理汇总了PHP中PhpAmqpLib\Channel\AMQPChannel::basic_publish方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPChannel::basic_publish方法的具体用法?PHP AMQPChannel::basic_publish怎么用?PHP AMQPChannel::basic_publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpAmqpLib\Channel\AMQPChannel
的用法示例。
在下文中一共展示了AMQPChannel::basic_publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: publishWithAMQP
/**
* @param DomainMessage $domainMessage
*/
private function publishWithAMQP(DomainMessage $domainMessage)
{
$payload = $domainMessage->getPayload();
$eventClass = get_class($payload);
$this->logger->info("publishing message with event type {$eventClass} to exchange {$this->exchange}");
$this->channel->basic_publish($this->messageFactory->createAMQPMessage($domainMessage), $this->exchange);
}
示例2: publish
/**
* @param $queue
* @param $message
*
* @return bool
*/
public function publish($queue, $message)
{
$exchange = $this->getExchange($queue);
$msg = new AMQPMessage($message, array('content_type' => 'text/plain', 'delivery_mode' => 2));
$this->ch->basic_publish($msg, $exchange);
return true;
}
示例3: send
/**
* Send a message.
*/
public function send()
{
$this->getChannel()->queue_declare('hello', false, false, false, false);
$msg = new AMQPMessage('Hello World!');
$this->channel->basic_publish($msg, '', 'hello');
echo ' [X] Sent "Hello World!"' . PHP_EOL;
}
示例4: schedule
/**
* Schedule a job in the future
*
* @access public
* @param Job $job
* @param DateTime $dateTime
* @return $this
*/
public function schedule(Job $job, DateTime $dateTime)
{
$now = new DateTime();
$when = clone $dateTime;
$delay = $when->getTimestamp() - $now->getTimestamp();
$message = new AMQPMessage($job->serialize(), array('delivery_mode' => 2));
$message->set('application_headers', new AMQPTable(array('x-delay' => $delay)));
$this->channel->basic_publish($message, $this->exchange);
return $this;
}
示例5: testPublishConsume
public function testPublishConsume()
{
$this->msg_body = 'foo bar baz äëïöü';
$msg = new AMQPMessage($this->msg_body, array('content_type' => 'text/plain', 'delivery_mode' => 1, 'correlation_id' => 'my_correlation_id', 'reply_to' => 'my_reply_to'));
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name);
$this->ch->basic_consume($this->queue_name, getmypid(), false, false, false, false, array($this, 'process_msg'));
while (count($this->ch->callbacks)) {
$this->ch->wait();
}
}
示例6: write
/**
* {@inheritDoc}
*/
protected function write(array $record)
{
$data = $record["formatted"];
$routingKey = $this->getRoutingKey($record);
if ($this->exchange instanceof AMQPExchange) {
$this->exchange->publish($data, $routingKey, 0, array('delivery_mode' => 2, 'content_type' => 'application/json'));
} else {
$this->exchange->basic_publish($this->createAmqpMessage($data), $this->exchangeName, $routingKey);
}
}
示例7: write
/**
*
* {@inheritDoc}
*
*/
protected function write(array $record)
{
$data = $record["formatted"];
$routingKey = sprintf('%s.%s', substr($record['level_name'], 0, 4), $record['channel']);
if ($this->exchange instanceof AMQPExchange) {
$this->exchange->publish($data, strtolower($routingKey), 0, array('delivery_mode' => 2, 'Content-type' => 'application/json'));
} else {
$this->exchange->basic_publish(new AMQPMessage((string) $data, array('delivery_mode' => 2, 'content_type' => 'application/json')), $this->exchangeName, strtolower($routingKey));
}
}
示例8: testSendFile
public function testSendFile()
{
$this->msg_body = file_get_contents(__DIR__ . '/fixtures/data_1mb.bin');
$msg = new AMQPMessage($this->msg_body, array('delivery_mode' => 1));
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name);
$this->ch->basic_consume($this->queue_name, '', false, false, false, false, array($this, 'process_msg'));
while (count($this->ch->callbacks)) {
$this->ch->wait();
}
}
示例9: publish
/**
* @param AMQPMessage $message
* @param string $routingKey
* @return bool
*/
public function publish(AMQPMessage $message, $routingKey = '')
{
$this->getLogger()->info('amqp.publish', ['route' => $routingKey, 'value' => $message->body]);
try {
$this->channel->basic_publish($message, self::CHANNEL_NAME, $routingKey);
return true;
} catch (\Exception $e) {
$this->getLogger()->error($e->getMessage());
return false;
}
}
示例10: call
/**
* @param $n
* @return int
*/
public function call($n)
{
$this->response = null;
$this->corr_id = uniqid();
$msg = new AMQPMessage((string) $n, ['correlation_id' => $this->corr_id, 'reply_to' => $this->callback_queue]);
$this->channel->basic_publish($msg, '', 'rpc_queue');
while (!$this->response) {
$this->channel->wait();
}
return intval($this->response);
}
示例11: testPublishPacketSizeLongMessage
public function testPublishPacketSizeLongMessage()
{
// Connection frame_max;
$frame_max = 131072;
// Publish 3 messages with sizes: packet size - 1, equal packet size and packet size + 1
for ($length = $frame_max - 9; $length <= $frame_max - 7; $length++) {
$this->msg_body = str_repeat('1', $length);
$msg = new AMQPMessage($this->msg_body, array('content_type' => 'text/plain', 'delivery_mode' => 1, 'correlation_id' => 'my_correlation_id', 'reply_to' => 'my_reply_to'));
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name);
}
}
示例12: testFrameOrder
public function testFrameOrder()
{
$msg = new AMQPMessage("test message");
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name1);
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name1);
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name2);
$this->ch->basic_consume($this->queue_name1, "", false, true, false, false, array($this, 'process_msg1'));
while (count($this->ch->callbacks)) {
$this->ch->wait();
}
}
示例13: testFrameOrder
public function testFrameOrder()
{
$msg = new AMQPMessage('');
$hdrs = new AMQPTable(array('x-foo' => 'bar'));
$msg->set('application_headers', $hdrs);
for ($i = 0; $i < $this->msg_count; $i++) {
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name);
}
$this->ch2->basic_consume($this->queue_name, '', false, true, false, false, array($this, 'process_msg'));
while (count($this->ch2->callbacks)) {
$this->ch2->wait();
}
}
示例14: call
/**
* @param AMQPMessage $message
* @param string $exchange
* @param string $routingKey
*
* @return Invoker\Reply
*
* @throws \Exception
*/
public function call(AMQPMessage $message, $exchange = '', $routingKey = '')
{
$this->enqueue($reply = new Invoker\Reply($this));
try {
$message->set('reply_to', $this->getReplyQueue());
$message->set('correlation_id', $reply->id());
$this->channel->basic_publish($message, $exchange, $routingKey);
} catch (\Exception $e) {
$this->dequeue($reply);
throw $e;
}
return $reply;
}
示例15: handle
/**
* @param AMQPMessage $message
*
* @throws \Exception
*/
public function handle(AMQPMessage $message)
{
$reply = null;
try {
$reply = $this->handler->handle($message);
$this->channel->basic_ack($message->delivery_info['delivery_tag'], false);
} catch (RequestNotSupportedException $exception) {
$this->channel->basic_ack($message->delivery_info['delivery_tag'], false);
} catch (\Exception $e) {
$this->channel->basic_reject($message->delivery_info['delivery_tag'], false);
throw $e;
}
if ($reply !== null) {
$this->channel->basic_publish($reply, '', $message->get('reply_to'));
}
}