daoshenzzg / socket-mqtt Goto Github PK
View Code? Open in Web Editor NEW基于Netty+MQTT的高性能推送服务框架。支持普通Socket、MQTT、MQTT web socket协议。非常方便接入上层业务实现推送业务。
License: Apache License 2.0
基于Netty+MQTT的高性能推送服务框架。支持普通Socket、MQTT、MQTT web socket协议。非常方便接入上层业务实现推送业务。
License: Apache License 2.0
Hi,mqtt是否支持集群,另外,是否支持mqtt用户名和密码?
您好 可以加一个 您的 qq 交流么,我是 android 开发的。临时过来 写这个 很多不太懂
另外一个问题就是 我看你这个 app 不是启动项把?
因为netty4之后BytBuf加入了计数器概念
我们在创建Server的时候开启了异步执行,如下图:
这个时候呢,在代码执行到ServerDispatchHandler.channelRead()这个方法时,里面有这么一句代码 eventDispatcher.dispatchMessageEvent(ctx, channel, msg);
这句代码的实现是这样的:
因为是异步的情况,在我们还没有读取ByteBuf数据时就已经先执行了如下图这句代码:
这时候ByteBuf已经被释放了,所以我们抛出了io.netty.util.IllegalReferenceCountException: refCnt: 0异常。
解决方法:
1. 改为同步执行
2. 修改作者代码
@service("ClientServiceImpl")
public class ClientServiceImpl implements IClientService {
public String messageSend(String ip,Integer port,String message){
MsgDecoder decoder = new MsgDecoder();
MsgEncoder encoder = new MsgEncoder();
Client client=new Client();
client.setIp(ip);
client.setPort(port);
client.setConnectTimeout(10000);
client.setCheckHeartbeat(false);
client.addChannelHandler("decoder", decoder);
client.addChannelHandler("encoder", encoder);
client.connect();
Request request = new Request();
request.setSequence(1);
request.setMessage(message);
Response response=null;
try {
response = client.sendWithSync(request, 30000);
client.shutdown();
return response.getResult().toString();
}catch (Exception e){
client.shutdown();
log.error("消息发送失败:{},指令:{}",e.getMessage(),message);
throw new RestfulEx(RestfulStatus.H500,"消息发送失败!");
}finally {
//强制回收内存
client=null;
decoder=null;
encoder=null;
request=null;
response=null;
System.gc();
}
}
}
请问下 这个项目的日志是打印在哪里呢?我想测试,但没找到打印日志和日志配置文件
生产项目应用过吗
// Server端默认使用业务处理线程池。
this.openExecutor = true;
在这种情况下,使用MQTT协议发布消息的时候,dispatchMessageEvent 的时候会出现传值异常,无法解析内容部分,引发IllegalReferenceCountException异常
我用mqttfx测试了一下,除了连接,其他的发送,接收都不走
if (msg instanceof MqttMessage) {
MqttMessage message = (MqttMessage) msg;
MqttMessageType messageType = message.fixedHeader().messageType();
switch (messageType) {
case CONNECT:
this.connect(channel, (MqttConnectMessage) message);
break;
case PUBLISH:
this.publish(channel, (MqttPublishMessage) message);
break;
case SUBSCRIBE:
this.subscribe(channel, (MqttSubscribeMessage) message);
break;
case UNSUBSCRIBE:
this.unSubscribe(channel, (MqttUnsubscribeMessage) message);
break;
case PINGREQ:
this.pingReq(channel, message);
break;
case DISCONNECT:
this.disConnect(channel, message);
break;
default:
if (logger.isDebugEnabled()) {
logger.debug("Nonsupport server message type of '{}'.", messageType);
}
break;
}
}
这段代码
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.