graze / graze/queue

AMQP Adapter

Abierto
#32 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
49
Forks
10
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

This is just a placeholder for discussion regarding a new AMQP adapter (RabbitMQ, etc).

I did some prototyping of a new adapter using the SqsAdapter as a baseline and my preferred library (one of the best AFAIK): https://github.com/videlalvaro/php-amqplib.

I was able to `enqueue` and `dequeue` the messages rather easily, but have had trouble with `acknowledge` thus far. I'll continue to work on that and link to it when I have something functional.

The AMQP library recommends that consumers use `$channel->basic_consume()`.
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L898

This works by declaring a callback and the consumer will remain attached and receiving messages as long as the callback is registered.

The core logic looks roughly like this:

```
try {
// params: $queue, $consumer_tag, $no_local, $no_ack, $exclusive, $nowait, $callback
$channel->basic_consume($this->name, '', false, false, false, false, $callback);
} catch (Exception $e) {
// @TODO Channel setup exception
}

// Loop as long as the channel has callbacks registered
while (count($channel->callbacks)) {
try {
var_dump('waiting');
$channel->wait();
} catch (Exception $e) {
// @TODO Channel wait exception
}
}
```

I have not yet been able to `dequeue` using the above `basic_consume` logic which I think will be the best long-term approach for this new adapter. I'll circle back to this after I can get `acknowledge` working.

However, I was able to get the `$channel->basic_get()` operation to work within a loop yielding `$factory->createMessage()` items.
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L981

The AMQP library doesn't recommend this due to inefficiencies (etc), but I have seen their maintainers suggest this method as an option for people trying to build their own blocking consumers.

A third option is also a possibility: `$channel->batch_basic_publish()`
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1115
I haven't used it myself and didn't know it was even available until last week.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza comparando el SqsAdapter existente con los puntos de entrada de php-amqplib AMQPChannel mencionados en el issue: basic_consume(), basic_get() y batch_basic_publish(). Investiga primero el comportamiento de acknowledgement y del consumer; el trabajo estará terminado cuando exista un adaptador AMQP funcional que admita enqueue, dequeue y acknowledge.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
php, rabbitmq
Área
backend, distributed-systems
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.