900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > php如何防止消息被篡改 php如何用libevent处理rabbitmq发来的消息 防止消息丢失或者

php如何防止消息被篡改 php如何用libevent处理rabbitmq发来的消息 防止消息丢失或者

时间:2019-06-02 02:04:24

相关推荐

php如何防止消息被篡改 php如何用libevent处理rabbitmq发来的消息 防止消息丢失或者

之前是用官方提供的方法来处理的

``

$channel->basic_consume('hello', '', false, true, false, false, $callback);

while(count($channel->callbacks)) {

$channel->wait();

}

``

发现中断程序的时候 每个消息没有被完全处理完,比如拿到消息还没有处理完入库就被中断了。

后来打算用libevent 据说在事件处理中,除非强制kill掉,不然事件会处理完再中断,但是以下代码还是不断报错;

``

$this->connection = new AMQPStreamConnection($config['host'], $config['port'], $config['user'], $config['password'], $config['vhost']);

$this->channel = $this->connection->channel();;

$this->channel->queue_declare($queue, false, true, false, false);

// $this->channel->basic_consume($queue, '', false, true, false, false, function ($msg) {

// set_trace_prefix(md5($msg->body . time()));

// trace('receive msg:' . $msg->body);

// trace('done');

// });

$ch = $this->channel;

$fd = $this->connection->getSocket();

Worker::$globalEvent->add($fd, EventInterface::EV_READ, function ($fd) use ($queue, $ch){

$msg = $ch->basic_get($queue, true);

print_r($msg);

print("get a messge:\n");

});

``

php如何防止消息被篡改 php如何用libevent处理rabbitmq发来的消息 防止消息丢失或者人为的中断导致消息没有被处理完整...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。