atheriel / longears

The RabbitMQ client for R
https://atheriel.github.io/longears/
36 stars 9 forks source link

How to keep consumer alive #8

Closed rudrasur closed 3 years ago

rudrasur commented 4 years ago

Hi, I am looking for help in keeping the consumer alive and listen messages continuously, is there any such feature available using this library ?

Another question: How to read message text (body) from amqp_message object

Thanks, Surendhar

atheriel commented 3 years ago

I am looking for help in keeping the consumer alive and listen messages continuously

You probably want to use a loop:

while (TRUE) {
  amqp_listen(...)
}

How to read message text (body)

The message has a body element accessible as, e.g. msg$body. Since messages can contain non-text content, the body is a raw vector; you can convert it to a string with rawToChar().

rudrasur commented 3 years ago

Great, thank you for response.

bhrigushr commented 2 years ago

@atheriel As suggested for keeping the consumer alive and listening to messages continuously

while (TRUE) {
  amqp_listen(conn, timeout = 900)
}

Above change didn't work for me

So if I try to connect to an empty queue I am getting the following error immediately

<simpleError in amqp_listen(conn, timeout = 900): Disconnected from server.>

If connect to a non-empty queue, my message processing start but as soon the queue becomes empty I see the same error as above. Now if new messages are added to the queue those are not processed and I keep seeing the same error as above

<simpleError in amqp_listen(conn, timeout = 900): Disconnected from server.>
<simpleError in amqp_listen(conn, timeout = 900): Disconnected from server.>
<simpleError in amqp_listen(conn, timeout = 900): Disconnected from server.>
<simpleError in amqp_listen(conn, timeout = 900): Disconnected from server.>

I also saw that in RabbitMQ Admin UI that once the above error start coming connection count keeps on increasing

atheriel commented 2 years ago

@bhrigushr I think you may need to provide a more reproducible example, your description of the problem isn't really enough to go on right now.

bhrigushr commented 2 years ago

Thanks, figured out what I was doing wrong.