SpinGo / op-rabbit

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

Can someone help provide how to do proper shutdown in demo? #196

Open kkalavantavanich opened 3 years ago

kkalavantavanich commented 3 years ago

I'm trying to figure out how to do a proper shutdown. The SubscriptionRef.close() and SubscriptionRef.await() weren't doing their jobs for me. It would be great if the demo can show a proper shutdown.

chameleon82 commented 2 years ago

@timcharper @aaabramov @pjfanning also interested in best practice, could you guys help?

pjfanning commented 2 years ago

Not sure if this helps but I used op-rabbit in the previous company I worked for and the code was deployed in Play servers - so we injected the play.api.inject.ApplicationLifecycle instance and added a stop hook to the ApplicationLifecycle to close the subscribers.

An alternative is https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

aaabramov commented 2 years ago

@timcharper @aaabramov @pjfanning also interested in best practice, could you guys help?

Same as per @pjfanning's answer. Either use Akka's ActorSystem lifecycle or Play's ApplicationLifecycle.