권기범
권기범

Reputation: 21

How to terminate Springboot app with Aapche Ignite using ignite messaging?

My apache ignite application is built with springboot. Here is my application flow.

  1. SenderNode send some message to remote node(ReceiverNode)
  2. ReceiverNode do something and send terminate sign(just string 'terminated') to SenderNode
  3. If reply message is terminate sign, I want to terminate SenderNode.

Below is my code.

        ignite.message(ReceiverNode).remoteListen(topic, (nodeId, message) -> {
            doSomething();

            ignite.message(ignite.cluster().forNodeId(nodeId)).send(topic, reply);

            return false;
        });

        ignite.message().localListen(null, (nodeId, message) -> {
            if(message is terminate sign) {
                context.close(); // springcontext

                return false;
            } else {
                return true;
            }
        });

        ignite.message(ReceiverNode).send(message, args);

But after SenderNode receiving terminate sign and closing spring context, ignite node is not terminated.

Is there any way to do this? thnx.

Upvotes: 0

Views: 271

Answers (1)

Denis Mekhanikov
Denis Mekhanikov

Reputation: 3591

You should close an Ignite instance to stop its work. But I think, you'll get a deadlock if you try to shut down Ignite from the message listener.

Try doing it from a separate thread. Put the following code to the listener:

new Thread(ignite::close).start()

If Ignite is a part of the Spring context, then closing of the context will be enough:

new Thread(context::close).start()

Upvotes: 1

Related Questions