当前位置: 首页>>代码示例>>Java>>正文


Java MqttDecoder类代码示例

本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttDecoder的典型用法代码示例。如果您正苦于以下问题:Java MqttDecoder类的具体用法?Java MqttDecoder怎么用?Java MqttDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MqttDecoder类属于io.netty.handler.codec.mqtt包,在下文中一共展示了MqttDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initChannel

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
@Override
  public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = null;
    if (sslHandlerProvider != null) {
      sslHandler = sslHandlerProvider.getSslHandler();
      pipeline.addLast(sslHandler);
    }
    pipeline.addLast("decoder", new MqttDecoder(MAX_PAYLOAD_SIZE));
    pipeline.addLast("encoder", MqttEncoder.INSTANCE);

    MqttTransportHandler handler = new MqttTransportHandler(msgProducer, deviceService, authService, assetService,
        assetAuthService, relationService, sslHandler);
    pipeline.addLast(handler);

//    ch.closeFuture().addListener(handler);

  }
 
开发者ID:osswangxining,项目名称:iothub,代码行数:19,代码来源:MqttTransportServerInitializer.java

示例2: start

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
public void start(int port) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new MqttDecoder());
                        ch.pipeline().addLast(MqttEncoder.INSTANCE);
                        ch.pipeline().addLast(new MqttInBoundHandler());
                    }
                })
                .option(ChannelOption.SO_BACKLOG, 1024)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        ChannelFuture future = bootstrap.bind(port).sync();
        future.channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }

}
 
开发者ID:airballcz,项目名称:iot-platform,代码行数:27,代码来源:Application.java

示例3: MQTTHardwareServer

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
public MQTTHardwareServer(Holder holder) {
    super(holder.props.getProperty("listen.address"),
            holder.props.getIntProperty("hardware.mqtt.port"), holder.transportTypeHolder);

    int hardTimeoutSecs = holder.limits.hardwareIdleTimeout;
    MqttHardwareLoginHandler mqttHardwareLoginHandler = new MqttHardwareLoginHandler(holder);
    HardwareChannelStateHandler hardwareChannelStateHandler =
            new HardwareChannelStateHandler(holder.sessionDao, holder.gcmWrapper);

    channelInitializer = new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
                .addLast("MqttIdleStateHandler", new IdleStateHandler(hardTimeoutSecs, hardTimeoutSecs, 0))
                .addLast(hardwareChannelStateHandler)
                .addLast(new MqttDecoder())
                .addLast(MqttEncoder.INSTANCE)
                .addLast(mqttHardwareLoginHandler)
                .addLast(new HardwareNotLoggedHandler());
        }
    };

    log.debug("hard.socket.idle.timeout = {}", hardTimeoutSecs);
}
 
开发者ID:blynkkk,项目名称:blynk-server,代码行数:25,代码来源:MQTTHardwareServer.java

示例4: initChannel

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
protected void initChannel(SocketChannel channel) throws Exception {
    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("idleState", new IdleStateHandler(90,0,0, TimeUnit.SECONDS));
    pipeline.addLast("mqttDecoder", new MqttDecoder());
    pipeline.addLast("mqttEncoder", MqttEncoder.INSTANCE);
    pipeline.addLast("mqttHandler", new MqttHandler(new MqttProcessor(server)));
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:8,代码来源:TCPHandlerInitializer.java

示例5: initChannel

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
private void initChannel(ChannelPipeline pipeline) {

    pipeline.addBefore("handler", "mqttEncoder", MqttEncoder.INSTANCE);
    if (this.options.getMaxMessageSize() > 0) {
      pipeline.addBefore("handler", "mqttDecoder", new MqttDecoder(this.options.getMaxMessageSize()));
    } else {
      // max message size not set, so the default from Netty MQTT codec is used
      pipeline.addBefore("handler", "mqttDecoder", new MqttDecoder());
    }

    // adding the idle state handler for timeout on CONNECT packet
    pipeline.addBefore("handler", "idle", new IdleStateHandler(this.options.timeoutOnConnect(), 0, 0));
    pipeline.addBefore("handler", "timeoutOnConnect", new ChannelDuplexHandler() {

      @Override
      public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {

        if (evt instanceof IdleStateEvent) {
          IdleStateEvent e = (IdleStateEvent) evt;
          if (e.state() == IdleState.READER_IDLE) {
            // as MQTT 3.1.1 describes, if no packet is sent after a "reasonable" time (here CONNECT timeout)
            // the connection is closed
            ctx.channel().close();
          }
        }
      }
    });
  }
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:29,代码来源:MqttServerImpl.java

示例6: initChannel

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
private void initChannel(ChannelPipeline pipeline) {

    // add into pipeline netty's (en/de)coder
    pipeline.addBefore("handler", "mqttEncoder", MqttEncoder.INSTANCE);

    if (this.options.getMaxMessageSize() > 0) {
      pipeline.addBefore("handler", "mqttDecoder", new MqttDecoder(this.options.getMaxMessageSize()));
    } else {
      // max message size not set, so the default from Netty MQTT codec is used
      pipeline.addBefore("handler", "mqttDecoder", new MqttDecoder());
    }

    if (this.options.isAutoKeepAlive() &&
      this.options.getKeepAliveTimeSeconds() != 0) {

      pipeline.addBefore("handler", "idle",
        new IdleStateHandler(0, this.options.getKeepAliveTimeSeconds(), 0));
      pipeline.addBefore("handler", "keepAliveHandler", new ChannelDuplexHandler() {

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {

          if (evt instanceof IdleStateEvent) {
            IdleStateEvent e = (IdleStateEvent) evt;
            if (e.state() == IdleState.WRITER_IDLE) {
              ping();
            }
          }
        }
      });
    }
  }
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:33,代码来源:MqttClientImpl.java

示例7: initChannel

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = null;
    if (sslHandlerProvider != null) {
        sslHandler = sslHandlerProvider.getSslHandler();
        pipeline.addLast(sslHandler);
    }
    pipeline.addLast("decoder", new MqttDecoder(MAX_PAYLOAD_SIZE));
    pipeline.addLast("encoder", MqttEncoder.INSTANCE);

    MqttTransportHandler handler = new MqttTransportHandler(processor, deviceService, authService, relationService, adaptor, sslHandler);
    pipeline.addLast(handler);
    ch.closeFuture().addListener(handler);
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:16,代码来源:MqttTransportServerInitializer.java

示例8: customizePipeline

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
@Override
protected void customizePipeline(EventExecutorGroup eventExecutorGroup, ChannelPipeline pipeline) {
    pipeline.addLast("decoder", new MqttDecoder());
    pipeline.addLast("encoder", new MqttEncoder());

    // we finally have the chance to add some business logic.
    pipeline.addLast(eventExecutorGroup, "iotracah-mqtt", new MqttServerHandler((MqttServerImpl) getServerImpl()));
}
 
开发者ID:caricah,项目名称:iotracah,代码行数:9,代码来源:MqttServerInitializer.java

示例9: addChannelHandlers

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
@Override
public void addChannelHandlers(ChannelPipeline pipeline) {
   pipeline.addLast(MqttEncoder.INSTANCE);
   pipeline.addLast(new MqttDecoder(MQTTUtil.MAX_MESSAGE_SIZE));

   pipeline.addLast(new MQTTProtocolHandler(server, this));
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:8,代码来源:MQTTProtocolManager.java

示例10: init

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
void init() {
        String host = "0.0.0.0";
        int port = 1883;
        m_bossGroup = new NioEventLoopGroup();
        m_workerGroup = new NioEventLoopGroup();

        ServerBootstrap b = new ServerBootstrap();
        b.group(m_bossGroup, m_workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline pipeline = ch.pipeline();
                        try {
                            pipeline.addLast("decoder", new MqttDecoder());
                            pipeline.addLast("encoder", MqttEncoder.INSTANCE);
                            pipeline.addLast("handler", new PublishReceiverHandler());
//                            pipeline.addLast("decoder", new MqttDecoder());
//                            pipeline.addLast("encoder", MqttEncoder.INSTANCE);
//                            pipeline.addLast("handler", new NettyPublishReceiverHandler());
                        } catch (Throwable th) {
                            LOG.error("Severe error during pipeline creation", th);
                            throw th;
                        }
                    }
                })
                .option(ChannelOption.SO_BACKLOG, 128)
                .option(ChannelOption.SO_REUSEADDR, true)
                .option(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.SO_KEEPALIVE, true);
        try {
            // Bind and start to accept incoming connections.
            ChannelFuture f = b.bind(host, port);
            LOG.info("Server binded host: {}, port: {}", host, port);
            f.sync();
        } catch (InterruptedException ex) {
            LOG.error(null, ex);
        }
    }
 
开发者ID:andsel,项目名称:moquette,代码行数:40,代码来源:ProtocolPublishDecodingServer.java

示例11: init

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
void init() {
    String host = "0.0.0.0";
    int port = 1883;
    m_bossGroup = new NioEventLoopGroup();
    m_workerGroup = new NioEventLoopGroup();

    ServerBootstrap b = new ServerBootstrap();
    b.group(m_bossGroup, m_workerGroup)
            .channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline pipeline = ch.pipeline();
                    try {
                        pipeline.addFirst("idleStateHandler", new IdleStateHandler(2, 0, 0));
                        pipeline.addAfter("idleStateHandler", "idleEventHandler", new MoquetteIdleTimeoutHandler());
                        pipeline.addLast("decoder", new MqttDecoder());
                        pipeline.addLast("encoder", MqttEncoder.INSTANCE);
                        pipeline.addLast("handler", new LoopMQTTHandler(state));
                    } catch (Throwable th) {
                        LOG.error("Severe error during pipeline creation", th);
                        throw th;
                    }
                }
            })
            .option(ChannelOption.SO_BACKLOG, 128)
            .option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.SO_KEEPALIVE, true);
    try {
        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(host, port);
        LOG.info("Server binded host: {}, port: {}", host, port);
        f.sync();
    } catch (InterruptedException ex) {
        LOG.error(null, ex);
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:39,代码来源:ProtocolDecodingServer.java

示例12: initializePlainTCPTransport

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
private void initializePlainTCPTransport(final NettyMQTTHandler handler,
                                         IConfig props) throws IOException {
    LOG.info("Configuring TCP MQTT transport");
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String tcpPortProp = props.getProperty(PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(tcpPortProp)) {
        LOG.info("Property {} has been set to {}. TCP MQTT will be disabled", BrokerConstants.PORT_PROPERTY_NAME,
            DISABLED_PORT_BIND);
        return;
    }
    int port = Integer.parseInt(tcpPortProp);
    initFactory(host, port, "TCP MQTT", new PipelineInitializer() {

        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            // pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            if (errorsCather.isPresent()) {
                pipeline.addLast("bugsnagCatcher", errorsCather.get());
            }
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MqttDecoder());
            pipeline.addLast("encoder", MqttEncoder.INSTANCE);
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            if (metrics.isPresent()) {
                pipeline.addLast("wizardMetrics", metrics.get());
            }
            pipeline.addLast("handler", handler);
        }
    });
}
 
开发者ID:andsel,项目名称:moquette,代码行数:35,代码来源:NettyAcceptor.java

示例13: initializeWebSocketTransport

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
    LOG.info("Configuring Websocket MQTT transport");
    String webSocketPortProp = props.getProperty(WEB_SOCKET_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(webSocketPortProp)) {
        // Do nothing no WebSocket configured
        LOG.info("Property {} has been setted to {}. Websocket MQTT will be disabled",
            BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
        return;
    }
    int port = Integer.parseInt(webSocketPortProp);

    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();

    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    initFactory(host, port, "Websocket MQTT", new PipelineInitializer() {

        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addLast(new HttpServerCodec());
            pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
            pipeline.addLast("webSocketHandler",
                    new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
            pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
            pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
            pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MqttDecoder());
            pipeline.addLast("encoder", MqttEncoder.INSTANCE);
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}
 
开发者ID:andsel,项目名称:moquette,代码行数:36,代码来源:NettyAcceptor.java

示例14: initializeSSLTCPTransport

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext)
        throws IOException {
    LOG.info("Configuring SSL MQTT transport");
    String sslPortProp = props.getProperty(SSL_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(sslPortProp)) {
        // Do nothing no SSL configured
        LOG.info("Property {} has been set to {}. SSL MQTT will be disabled",
            BrokerConstants.SSL_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
        return;
    }

    int sslPort = Integer.parseInt(sslPortProp);
    LOG.info("Starting SSL on port {}", sslPort);

    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
    final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
    initFactory(host, sslPort, "SSL MQTT", new PipelineInitializer() {

        @Override
        void init(ChannelPipeline pipeline) throws Exception {
            pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
            pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            // pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MqttDecoder());
            pipeline.addLast("encoder", MqttEncoder.INSTANCE);
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}
 
开发者ID:andsel,项目名称:moquette,代码行数:36,代码来源:NettyAcceptor.java

示例15: initializeWSSTransport

import io.netty.handler.codec.mqtt.MqttDecoder; //导入依赖的package包/类
private void initializeWSSTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext)
        throws IOException {
    LOG.info("Configuring secure websocket MQTT transport");
    String sslPortProp = props.getProperty(WSS_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(sslPortProp)) {
        // Do nothing no SSL configured
        LOG.info("Property {} has been set to {}. Secure websocket MQTT will be disabled",
            BrokerConstants.WSS_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
        return;
    }
    int sslPort = Integer.parseInt(sslPortProp);
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
    final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
    initFactory(host, sslPort, "Secure websocket", new PipelineInitializer() {

        @Override
        void init(ChannelPipeline pipeline) throws Exception {
            pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
            pipeline.addLast("httpEncoder", new HttpResponseEncoder());
            pipeline.addLast("httpDecoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
            pipeline.addLast("webSocketHandler",
                    new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
            pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
            pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
            pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MqttDecoder());
            pipeline.addLast("encoder", MqttEncoder.INSTANCE);
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}
 
开发者ID:andsel,项目名称:moquette,代码行数:39,代码来源:NettyAcceptor.java


注:本文中的io.netty.handler.codec.mqtt.MqttDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。