Search in sources :

Example 1 with MqttConnectionHandler

use of org.apache.rocketmq.iot.protocol.mqtt.handler.MqttConnectionHandler 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)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 MqttDecoder (io.netty.handler.codec.mqtt.MqttDecoder)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