BatchProducer: bug fix and cleanup

- BatchProducer should run in daemon mode and should die when the main process dies and all messages should be flushed.