Search code examples
javarmichroniclechronicle-queue

Can Chronicle Queue be used like RMI?


I want my two JVM applications speak to each other on the same machine. I considered using RMI, but then I found Chronicle Queue which claims that it is very fast. I wonder whether I can use Chronicle to invoke a method on the other JVM and wait for the return value. Are there any use cases for that?


Solution

  • It's doable, but might be an overkill (especially if you don't have to keep the history of the request/responses). Imagine a simple scenario with two processes: C (client) and S (server). Create two IndexedChronicles:

    • Q1 for sending requests from C to S
    • Q2 for sending responses from S to C

    Server has a thread that is polling (busy spin with back-off) on Q1. When it receives a request (with id=x it does whatever is needed and writes out response to Q2 (with id=x. C polls Q2 with some policy and reads out responses as they appear. It uses the id to tie responses to requests.

    Main task would be in devising a wire-level protocol for serialising your commands (equivalent of the method calls) from the client. This is application specific and can be done efficiently with the Chronicle tools.

    Another issues to consider:

    • what should the client do with the historical responses on startup?
    • some heartbeat system so that client knows the server is alive
    • archiving of the old queues (VanillaChronicle makes it easier at some cost)