SpinGo / op-rabbit

The Opinionated RabbitMQ Library for Scala and Akka
Other
232 stars 73 forks source link

How do you cleanly close a akka stream connection #106

Closed theunforgiven closed 7 years ago

theunforgiven commented 7 years ago

Hello,

I've been trying to find a way to cleanly close down an akka-stream op-rabbit connection. There doesn't seem to be anyway for me to signal that i'm ending the application and i'd like to gracefully close things. Shutting down the materializer seems to leave the connection open, and when i terminate the actor system i then get a bunch of dead letters.

Thanks.

timcharper commented 7 years ago

Hi, @theunforgiven. There is no way (nor need) to gracefully shut down the op-rabbit connection in general. However, with streams, RabbitSource materialized value is a SubscriptionRef, which has a close() method, and a closed: Future. Once you call close, no further elements will go in to the stream. You can wait for the closed Future to complete, which indicates that all elements put in to the source have been acknowledged.

sandeepjindal commented 4 years ago

@timcharper I have minimal context about akka streams This is how i am materializing the AckedSource to get SubscriptionRef { val queue = Queue(s"$queueName", durable = true, autoDelete = false) val source = RabbitSource(rabbitControl, channel(qos = 1), consume(queue), body(as[T])) source .mapAsyncUnordered(1) { message => Future.successful(processFn(message)) } .to(AckedSink.ack) .run() } Am just curious why you mentioned nor need in this There is no way (nor need) to gracefully shut down