Antti / rust-amqp

AMQP client in pure rust. Corresponds to rabbitmq spec.
MIT License
249 stars 45 forks source link

Clean way to stop consuming #23

Open mmacedoeu opened 9 years ago

mmacedoeu commented 9 years ago

I could see Channel::read Will block until it reads a frame, other than basic.deliver or maybe get "Error reading packet from channel". I need some way to release the block state so I can handle termination like a OS signal interrupt. It's unclear for me if i need to close the channel or the connection to force it to return an error. What is the clean way to handle termination ? Could you provide a example?

Antti commented 9 years ago

We haven't figure this out yet. If you have an idea of how it should look like, can you provide an abstract code example and I'll try to implement that.

mmacedoeu commented 9 years ago

My Ideia is to close the channel and session on a shared memory, still dont know if it works cause in my way with the compiler checks:

https://gist.github.com/a88ff7e80a3f881b168a.git

pimeys commented 7 years ago

I built a very dirty hack to do this. Just have an Arc<AtomicBool> and set it to true to stop the consumer.

So hacky I don't want to do a pull request, but you can see the commit here: https://github.com/pimeys/rust-amqp/commit/b54c43526ac3f897971e222a649a97e169216eb5

Thorbijoern commented 5 years ago

what is the status of this?

maybe the functions used as callbacks could return different objects to stop the consuming and maybe to return some other data? maybe one could implement a "consume_once" which could be usefull for rpc for example?

also while looking into how i could stop the consuming i notized, that channel.basic_cancel doesn't remove the callback from channel..consumers... is that supposed to be so?

pimeys commented 5 years ago

We don't use rabbitmq anymore, but I made a hack that worked quite well. We just switched to Kafka so it was never cleaned up and pushed to the mainline.

https://github.com/pimeys/rust-amqp/tree/consumer_clean_exit

Thorbijoern commented 5 years ago

thank you for the answer but the cargo package still says: description = "AMQP/RabbitMQ protocol client"

Thorbijoern commented 5 years ago

btw. i just forked and merged it here: https://github.com/Thorbijoern/rust-amqp