ignite中的消息使用实例

消息很简单,跟其他的mq相仿,关键点:

  一,添加监听,订阅主题

  二,发送消息

写了一个简单的示例:

Receiver.java

package test.ignite.broadcast;

import java.util.UUID;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteMessaging;
import org.apache.ignite.Ignition;
import org.apache.ignite.lang.IgniteBiPredicate;

public class Receiver {
    public static void main(String[] args) {
        System.out.println("======================================================");
        Ignite ignite = Ignition.start("ignite.xml");
        IgniteMessaging msg = ignite.message();
        msg.localListen("aaa", new IgniteBiPredicate<UUID, Integer>() {
            @Override
            public boolean apply(UUID nodeId, Integer funId) {
                System.out.println(funId);
                return true; 
            }
        });
        
    }

}

Sender.java

package test.ignite.broadcast;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteMessaging;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.transactions.Transaction;

public class Sender {
    public static void main(String[] args) {
        Ignition.setClientMode(true);
        Ignite ignite = Ignition.start("ignite.xml");
        IgniteMessaging msg = ignite.message();
        msg.sendOrdered("aaa", 100,0);
    }

}

  see what do we get...

posted @ 2016-07-12 17:12  但行好事-莫问前程  阅读(1637)  评论(0编辑  收藏  举报