php-amqplib with libevent

184 vues
Accéder directement au premier message non lu

cxf

non lue,
3 janv. 2012, 22:56:2003/01/2012
à php-amqplib-devel
hi,
I want use php-amqplib and libevent, in receiver, i get the socket
in AMQPConnection (just return $this->sock ) and set it in libevent,
when sending messaget to queue,the receiver has no action (the
callback is not even invoked at all ); is there anyting wrong, thanks
very much.

receiver code as followers:

$exchange = 'router';
$queue = 'msgs';
$consumer_tag = 'consumer';

function getMsg($fd, $events, $arg) {
$ch = $arg[0];
$queue = $arg[1];
$msg = $ch->basic_get($queue, true);
print_r($msg);
print("get a messge:\n");
}

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
$ch->queue_declare($queue, false, true, false, false);
$ch->exchange_declare($exchange, 'direct', false, true, false);
$ch->queue_bind($queue, $exchange);

$fd = $conn->get_socket();

//$ch->basic_consume($queue, $consumer_tag, false, true, false, false,
"getMsg1");

$base_fd = event_base_new();
$event_fd = event_new();
event_set($event_fd, $fd, EV_READ|EV_PERSIST, "getMsg", array($ch,
$queue));
event_base_set($event_fd, $base_fd);
event_add($event_fd);
event_base_loop($base_fd);

Jost Baron

non lue,
24 mars 2016, 04:54:1724/03/2016
à php-amqplib-devel
I've had the same problem. The problem is that RabbitMQ only starts to deliver messages to the consumer if it told RabbitMQ that it wants to receive messages (i.e. it called basic_consume on the queue).

Solution: Call basic_consume on the queue in your initialization so you get messages on the socket, and then call $channel->wait() whenever the event fired. It should also be more efficient than using basic_get.

akayz...@gmail.com

non lue,
29 nov. 2017, 08:03:5629/11/2017
à php-amqplib-devel
hi,I've had the same problem.  do you know the answer now?

在 2012年1月4日星期三 UTC+8上午11:56:20,cxf写道:
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message