SpinGo / op-rabbit

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

Publish message then exit #139

Closed borice closed 6 years ago

borice commented 6 years ago

Hello.

I'm trying to use op-rabbit in a small Scala app that needs to publish a single message to an exchange, then exit. I'm able to get the message published, but not sure how to properly cause the app to exit.

I tried to actorSystem.registerOnTermination { System.exit(0) } and used rabbitControl ! PoisonPill after the rabbitControl ! Message.topic(...) but the app doesn't exit.

What's the proper way to send a single message, then exit the app (ideally after it's confirmed that the message was successfully delivered to the exchange)?

Thank you!

borice commented 6 years ago

I've managed to make a working version. It involves using the ask pattern and waiting for the resulting future completion, then invoking actorSystem.terminate() combined with Await.ready(actorSystem.whenTerminated, ...