Search code examples
javaignite

Apache ignite - easiest way to send message between nodes and get synchronous response?


In Apache ignite, I want to send a message from one server node to another server node and get a synchronous response back, e.g. send a HTTP GET from server node A to server node B and get the response body back from server node B. I have the ignite ids of the servers but nothing else.

Ignite messaging is topic-based publish-subscribe, so the only way I can think to do this is that each node subscribes to a topic which is its id and we do something like ignite.message().send("idOfServer", "myMessage") from server A to server B and then back again. However this will be asynchronous.

Is there any easy way to do this synchronously, e.g. get IP of server B somehow and send a HTTP GET directly for example? What's the easiest way to achieve this?


Solution

  • Compute API can call a node by id:

    UUID nodeId = ...;
    
    ClusterGroup clusterGroup = ignite.cluster().forNodeId(nodeId);
    
    String callResult = ignite.compute(clusterGroup).call(new IgniteCallable<String>() {
        @Override public String call() {
            // This code exectutes on remote node.
            return "Hello from another node";
        }
    });
    
    

    You can also get node addesses and do other things like HTTP requests, if required:

    Collection<String> addrs = ignite.cluster().node(nodeId).addresses();