首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对php-amqplib使用确认(发布者确认)

对php-amqplib使用确认(发布者确认)
EN

Stack Overflow用户
提问于 2013-09-05 04:45:04
回答 2查看 2K关注 0票数 3

我正在尝试通过php-amqplib库来使用确认(Publisher Acknowledgements),这是在http://rabbitmq.com/上推荐使用RabbitMQ和PHP的库。

代码本身没有很好的文档记录,我找不到任何与我找到的Java和python接口的接口相对应的东西。

Java的例子是here

我贪婪地寻找在PHP源代码中可以想到的函数名的各种组合,但没有找到任何东西。我正在寻找类似的东西:

代码语言:javascript
复制
$channel->confirm_select();

...

$channel->wait();

看起来https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Helper/Protocol/Protocol091.php支持该功能,但我不知道它是如何向用户公开的。

EN

回答 2

Stack Overflow用户

发布于 2016-12-15 16:16:32

我今天一直在寻找它,发现php-amqplib已经实现了它。

看看这个demo for details

下面是一段代码:

代码语言:javascript
复制
$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $connection->channel();
$channel->set_ack_handler(
    function (AMQPMessage $message) {
        echo "Message acked with content " . $message->body . PHP_EOL;
    }
);
$channel->set_nack_handler(
    function (AMQPMessage $message) {
        echo "Message nacked with content " . $message->body . PHP_EOL;
    }
);
/*
 * bring the channel into publish confirm mode.
 * if you would call $ch->tx_select() befor or after you brought the channel into this mode
 * the next call to $ch->wait() would result in an exception as the publish confirm mode and transactions
 * are mutually exclusive
 */
$channel->confirm_select();
/*
    name: $exchange
    type: fanout
    passive: false // don't check if 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->exchange_declare($exchange, 'fanout', false, false, true);
$i = 1;
$msg = new AMQPMessage($i, array('content_type' => 'text/plain'));
$channel->basic_publish($msg, $exchange);
/*
 * watching the amqp debug output you can see that the server will ack the message with delivery tag 1 and the
 * multiple flag probably set to false
 */
$channel->wait_for_pending_acks();
票数 3
EN

Stack Overflow用户

发布于 2013-09-05 05:24:02

显然,PECL AMQP库和纯php-amqplib库都没有实现确认扩展。此时唯一真正的解决方案是实现两个队列来模拟对发布者的确认。

在这两个库中都有实现确认的计划,但我都没有看到任何进展。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18623444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档