Search in sources :

Example 1 with MqttDecoder

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));
}
Also used : MqttDecoder(io.netty.handler.codec.mqtt.MqttDecoder)

Example 2 with MqttDecoder

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();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) MqttDecoder(io.netty.handler.codec.mqtt.MqttDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 3 with MqttDecoder

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();
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) MqttDecoder(io.netty.handler.codec.mqtt.MqttDecoder) ClientManagerImpl(org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) MqttIdleHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.MqttIdleHandler) MessageDispatcher(org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher) MqttConnectionHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.MqttConnectionHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) InMemorySubscriptionStore(org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore)

Example 4 with MqttDecoder

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();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) MqttDecoder(io.netty.handler.codec.mqtt.MqttDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 5 with MqttDecoder

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);
}
Also used : IpFilter(org.thingsboard.server.transport.mqtt.limits.IpFilter) ProxyIpFilter(org.thingsboard.server.transport.mqtt.limits.ProxyIpFilter) ProxyIpFilter(org.thingsboard.server.transport.mqtt.limits.ProxyIpFilter) MqttDecoder(io.netty.handler.codec.mqtt.MqttDecoder) HAProxyMessageDecoder(io.netty.handler.codec.haproxy.HAProxyMessageDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Aggregations

MqttDecoder (io.netty.handler.codec.mqtt.MqttDecoder)5 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 SocketChannel (io.netty.channel.socket.SocketChannel)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HAProxyMessageDecoder (io.netty.handler.codec.haproxy.HAProxyMessageDecoder)1 SslHandler (io.netty.handler.ssl.SslHandler)1 ClientManagerImpl (org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl)1 MessageDispatcher (org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher)1 MqttConnectionHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.MqttConnectionHandler)1 MqttIdleHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.MqttIdleHandler)1 InMemorySubscriptionStore (org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore)1 IpFilter (org.thingsboard.server.transport.mqtt.limits.IpFilter)1 ProxyIpFilter (org.thingsboard.server.transport.mqtt.limits.ProxyIpFilter)1