-
Notifications
You must be signed in to change notification settings - Fork 1
Zbus
T-baby edited this page Aug 8, 2016
·
1 revision
为了大家方便,移植了zbus插件
依赖
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>
<dependency>
<groupId>org.zbus</groupId>
<artifactId>zbus</artifactId>
<version>6.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.9</version>
<scope>provided</scope>
</dependency>
使用
在ICEREST config类的configPlugin下:
//初始化zbus插件
String brokerAddress = "127.0.0.1:155555";
String scanRootPackage = "com.wellbole";
ZbusPlugin zbusPlugin = new ZbusPlugin(brokerAddress,scanRootPackage);
pluginLoader.add(zbusPlugin);
在其他地方,通过Zbus来发送消息。
//初始化一个MQ泛型发送器,构造函数参数为MQ名
Sender<Dict> mqSender = new MqSender<Dict>("MyMQ");
Dict dict = new Dict();
dict.setId(1L);
dict.set("key", "key"+1);
dict.set("value", "value"+1);
//同步发送对象到MQ
mqSender.sendSync(dict);
//sendAsync
//异步发送对象到MQ
//mqSender.sendAsync(dict);
//初始化一个Topic泛型(String类型)发送器,构造函数参数为,MQ名,Topic名
Sender<String> topicSender = new TopicSender<String>("Topic", "Check");
//同步发送对象到topic
topicSender.sendSync("这时一个订阅消息");
//异步发送对象到topic
//topicSender.sendAsync("这时一个订阅消息");
接收zbus传送的消息
//MQ消息处理器
@MqHandler("MyMQ")
//Topic(pubsub)消息处理器
//@TopicHandler(mq="Topic", topic="Check")
public class DictMsgHandler extends TMsgHandler<Dict> {
private static final Logger LOG = Logger.getLogger("DictMsgHandler");
@Override
public void handle(Dict msg) {
LOG.info(msg.toString());
}
}