基於ikvm的rocketmq的c#客戶端,因爲阿里對c#不敏感,對這方面的東西缺乏。由於工做須要弄了一個,分享給你們 https://github.com/franknew/RocketMQ-Clientgit
如何使用:github
1.添加引用json
IKVM.OpenJDK.Charsets.dll IKVM.OpenJDK.Core.dll IKVM.OpenJDK.Jdbc.dll IKVM.OpenJDK.Management.dll IKVM.OpenJDK.Security.dll IKVM.OpenJDK.SwingAWT.dll IKVM.OpenJDK.Text.dll IKVM.OpenJDK.Util.dll IKVM.Runtime.dll netty-all-4.0.36.Final.dll rocketmq-client-4.2.0-incubating.dll rocketmq-common-4.2.0-incubating.dll rocketmq-remoting-4.2.0-incubating.dll slf4j-api-1.7.5.dll fastjson-1.2.12.dll
2.生產消息c#
DefaultMQProducer p = new DefaultMQProducer("test"); p.setNamesrvAddr("192.168.100.3:9876"); p.start(); var data = Encoding.UTF8.GetBytes(txbMessage.Text); com.alibaba.rocketmq.common.message.Message m = new com.alibaba.rocketmq.common.message.Message("defaulttopic1", data); p.send(m); p.shutdown();
3.消費消息api
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("test"); consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); consumer.setNamesrvAddr("192.168.100.3:9876"); consumer.subscribe("defaulttopic", "*"); consumer.registerMessageListener(new TestListener()); consumer.start();
4.推送消息的監聽器ide
public class TestListener : MessageListenerConcurrently { public ConsumeConcurrentlyStatus consumeMessage(List list, ConsumeConcurrentlyContext ccc) { for (int i = 0; i < list.size(); i++) { var msg = list.get(i) as Message; byte[] body = msg.getBody(); var str = Encoding.UTF8.GetString(body); if (body.Length == 2 && body[0] == 0 && body[1] == 0) { //System.out.println("Got the end signal"); continue; } } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } }
建議安裝JDK1.7及以上版本spa