use of io.netty.handler.codec.mqtt.MqttDecoder in project activemq-artemis by apache.
the class MQTTProtocolManager method addChannelHandlers.
@Override
public void addChannelHandlers(ChannelPipeline pipeline) {
pipeline.addLast(MqttEncoder.INSTANCE);
pipeline.addLast(new MqttDecoder(MQTTUtil.MAX_MESSAGE_SIZE));
pipeline.addLast(new MQTTProtocolHandler(server, this));
}
use of io.netty.handler.codec.mqtt.MqttDecoder in project netty by netty.
the class MqttHeartBeatBroker method main.
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup);
b.option(ChannelOption.SO_BACKLOG, 1024);
b.channel(NioServerSocketChannel.class);
b.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("encoder", MqttEncoder.INSTANCE);
ch.pipeline().addLast("decoder", new MqttDecoder());
ch.pipeline().addLast("heartBeatHandler", new IdleStateHandler(45, 0, 0, TimeUnit.SECONDS));
ch.pipeline().addLast("handler", MqttHeartBeatBrokerHandler.INSTANCE);
}
});
ChannelFuture f = b.bind(1883).sync();
System.out.println("Broker initiated...");
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
}
use of io.netty.handler.codec.mqtt.MqttDecoder in project rocketmq-externals by apache.
the class MQTTBridge method init.
private void init() {
bossGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfBossGroup());
workerGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfWorkerGroup());
serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup).localAddress(MQTTBridgeConfiguration.port()).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, MQTTBridgeConfiguration.socketBacklog()).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("mqtt-decoder", new MqttDecoder());
pipeline.addLast("mqtt-encoder", MqttEncoder.INSTANCE);
pipeline.addLast("channel-idle-handler", new MqttIdleHandler());
pipeline.addLast("message-dispatcher", messageDispatcher);
pipeline.addLast("connection-manager", connectionHandler);
}
});
subscriptionStore = new InMemorySubscriptionStore();
clientManager = new ClientManagerImpl();
messageDispatcher = new MessageDispatcher(clientManager);
connectionHandler = new MqttConnectionHandler(clientManager, subscriptionStore);
registerMessageHandlers();
}
use of io.netty.handler.codec.mqtt.MqttDecoder in project netty by netty.
the class MqttHeartBeatClient method main.
public static void main(String[] args) throws Exception {
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
b.handler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("encoder", MqttEncoder.INSTANCE);
ch.pipeline().addLast("decoder", new MqttDecoder());
ch.pipeline().addLast("heartBeatHandler", new IdleStateHandler(0, 20, 0, TimeUnit.SECONDS));
ch.pipeline().addLast("handler", new MqttHeartBeatClientHandler(CLIENT_ID, USER_NAME, PASSWORD));
}
});
ChannelFuture f = b.connect(HOST, PORT).sync();
System.out.println("Client connected");
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
}
}
use of io.netty.handler.codec.mqtt.MqttDecoder in project thingsboard by thingsboard.
the class MqttTransportServerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = null;
if (context.isProxyEnabled()) {
pipeline.addLast("proxy", new HAProxyMessageDecoder());
pipeline.addLast("ipFilter", new ProxyIpFilter(context));
} else {
pipeline.addLast("ipFilter", new IpFilter(context));
}
if (sslEnabled && context.getSslHandlerProvider() != null) {
sslHandler = context.getSslHandlerProvider().getSslHandler();
pipeline.addLast(sslHandler);
}
pipeline.addLast("decoder", new MqttDecoder(context.getMaxPayloadSize()));
pipeline.addLast("encoder", MqttEncoder.INSTANCE);
MqttTransportHandler handler = new MqttTransportHandler(context, sslHandler);
pipeline.addLast(handler);
ch.closeFuture().addListener(handler);
}
Aggregations