码迷,mamicode.com
首页 > 其他好文 > 详细

ignite中的消息使用实例

时间:2016-07-12 19:19:22      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

消息很简单,跟其他的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...

ignite中的消息使用实例

标签:

原文地址:http://www.cnblogs.com/garfieldcgf/p/5664218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!