Search code examples
messagingrpcmiddleware

Using Nirvana (or other MOM middleware), what is the best way of implementing RPC?


Using Nirvana (http://my-channels.com/) or other message oriented middleware, what is the best way, in terms of latency, scalability and security, to implement classic RPC (one request - one response)?


Solution

  • A typically pattern is to use a correlation id, such as a GUID, to implement request/response semantics on top of a messaging platform.

    Each request has a new Guid attached to it, and one the server side, the response created has the guid for the request attached to it.

    For instance, on the client, say we have a messageBus instance, with a publish() method to send data to the bus, and an OnNext() method to async receive data from the bus, we could then wrap the messageBus in and IObservable, and write the following:

    function DataItem GetReqResp(QueryItem q)
    {
        q.Guid = Guid.NewGuid();
        messageBus.Publish(q);
        return messageBus.Where(n => n.Guid == q.Guid).Take(1);
    }