• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MqttConnectMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: processAuthTokenConnect

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
private void processAuthTokenConnect(ChannelHandlerContext ctx, MqttConnectMessage msg) {
  String userName = msg.payload().userName();
  String clientIdentifier = msg.payload().clientIdentifier();
  if (StringUtils.isEmpty(userName)) {
    // ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD));
    // ctx.close();
    ctx.writeAndFlush(createMqttConnAckMsg(MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD));
    connected = false;
  } else {
    boolean login = deviceSessionCtx.login(new DeviceTokenCredentials(userName));
    if (!login) {
      ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_REFUSED_NOT_AUTHORIZED));
      connected = false;
    } else {
      MemoryMetaPool.registerClienId(clientIdentifier, ctx.channel());

      ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_ACCEPTED));
      connected = true;
      checkGatewaySession();
    }
    // }
  }

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


示例2: connect

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
public static MqttConnectMessage connect(ConnectOptions options) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
			10);
	MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader(options.version().protocolName(),
			options.version().protocolLevel(), options.userName() != null, options.password() != null,
			options.will() == null ? false : options.will().isRetain(),
			options.will() == null ? 0 : options.will().qos().value(), options.will() != null,
			options.cleanSession(), options.keepAliveTimeSeconds());

	MqttConnectPayload payload = new MqttConnectPayload(Strings.nullToEmpty(options.clientId()),
			options.will() == null ? "" : options.will().topicName(),
			options.will() == null ? "" : new String(options.will().message(), CharsetUtil.UTF_8),
			Strings.nullToEmpty(options.userName()), Strings.nullToEmpty(options.password()));

	return new MqttConnectMessage(fixedHeader, variableHeader, payload);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:17,代码来源:MqttMessageFactory.java


示例3: executeNormalChannelRead0

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
private MqttConnAckMessage executeNormalChannelRead0(String clientId, boolean cleanSession, ChannelId channelId)
		throws Exception {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
			10);
	MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("MQTT", 4, true, true, true, 0, true,
			cleanSession, 60);
	MqttConnectPayload payload = new MqttConnectPayload(clientId, "willtopic", "willmessage", "username",
			"password");

	MqttConnectMessage msg = new MqttConnectMessage(fixedHeader, variableHeader, payload);

	ChannelId cid = channelId == null ? TestUtil.newChannelId(clientId, false) : channelId;

	EmbeddedChannel channel = new EmbeddedChannel(cid, new ConnectReceiver());

	channel.writeInbound(msg);

	return channel.readOutbound();
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:20,代码来源:ConnectReceiverTest.java


示例4: processMqttMsg

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
private void processMqttMsg(ChannelHandlerContext ctx, MqttMessage msg) {
  // deviceSessionCtx.setChannel(ctx);
  // assetSessionCtx.setChannel(ctx);

  switch (msg.fixedHeader().messageType()) {
  case CONNECT:
    processConnect(ctx, (MqttConnectMessage) msg);
    break;
  case PUBLISH:
    processPublish(ctx, (MqttPublishMessage) msg);
    // System.out.println("write...");
    // ctx.write("just for test");
    break;
  case SUBSCRIBE:
    processSubscribe(ctx, (MqttSubscribeMessage) msg);
    break;
  case UNSUBSCRIBE:
    processUnsubscribe(ctx, (MqttUnsubscribeMessage) msg);
    break;
  case PINGREQ:
    if (checkConnected(ctx)) {
      ctx.writeAndFlush(new MqttMessage(new MqttFixedHeader(PINGRESP, false, AT_MOST_ONCE, false, 0)));
    }
    break;
  case DISCONNECT:
    if (checkConnected(ctx)) {
      processDisconnect(ctx);
    }
    break;
  }
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:32,代码来源:MqttTransportHandler.java


示例5: newWill

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
private Message newWill(String clientId, MqttConnectMessage conn) {
	if (!conn.variableHeader().isWillFlag()) { return null; } // [MQTT-3.1.2-12]

	return new Message(-1, conn.payload().willTopic(), clientId,
			conn.payload().willMessage().getBytes(CharsetUtil.UTF_8),
			MqttQoS.valueOf(conn.variableHeader().willQos()), conn.variableHeader().isWillRetain());
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:8,代码来源:ConnectReceiver.java


示例6: filterPlugins

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
private boolean filterPlugins(ChannelHandlerContext ctx, MqttConnectMessage msg) {
	String clientId = msg.payload().clientIdentifier();
	String userName = msg.variableHeader().hasUserName() ? msg.payload().userName() : null;
	String password = msg.variableHeader().hasPassword() ? msg.payload().password() : null;

	if (!Plugins.INSTANCE.get(ServiceChecker.class).isServiceAvailable()) {
		sendNoneAcceptMessage(ctx, MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE);
		return false;
	}

	if (!Plugins.INSTANCE.get(Authenticator.class).isValid(clientId)) {
		sendNoneAcceptMessage(ctx, MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED); // [MQTT-3.1.3-9]
		return false;
	}

	if (!Plugins.INSTANCE.get(Authenticator.class).isValid(clientId, userName, password)) {
		sendNoneAcceptMessage(ctx, MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD);
		return false;
	}

	if (!Plugins.INSTANCE.get(Authorizer.class).isAuthorized(clientId, userName)) {
		sendNoneAcceptMessage(ctx, MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED);
		return false;
	}

	return true;
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:28,代码来源:ConnectReceiver.java


示例7: intercept

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
@Override
public boolean intercept(final MqttMessage mqttMessage, RemotingConnection connection) {
   System.out.println("MQTT control packet was intercepted " + mqttMessage.fixedHeader().messageType());

   // If you need to handle an specific packet type:
   if (mqttMessage instanceof MqttPublishMessage) {
      MqttPublishMessage message = (MqttPublishMessage) mqttMessage;


      String originalMessage = message.payload().toString(Charset.forName("UTF-8"));
      System.out.println("Original message: " + originalMessage);

      // The new message content must not be bigger that the original content.
      String modifiedMessage = "Modified message ";

      message.payload().setBytes(0, modifiedMessage.getBytes());
   } else {
      if (mqttMessage instanceof MqttConnectMessage) {
         MqttConnectMessage connectMessage = (MqttConnectMessage) mqttMessage;
         System.out.println("MQTT CONNECT control packet was intercepted " + connectMessage);
      }
   }


   // We return true which means "call next interceptor" (if there is one) or target.
   // If we returned false, it means "abort call" - no more interceptors would be called and neither would
   // the target
   return true;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:30,代码来源:SimpleMQTTInterceptor.java


示例8: handleConnect

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
/**
 * Called during connection.
 *
 * @param connect
 */
void handleConnect(MqttConnectMessage connect, ChannelHandlerContext ctx) throws Exception {
   this.ctx = ctx;
   connectionEntry.ttl = connect.variableHeader().keepAliveTimeSeconds() * 1500L;

   String clientId = connect.payload().clientIdentifier();
   session.getConnectionManager().connect(clientId, connect.payload().userName(), connect.payload().passwordInBytes(), connect.variableHeader().isWillFlag(), connect.payload().willMessageInBytes(), connect.payload().willTopic(), connect.variableHeader().isWillRetain(), connect.variableHeader().willQos(), connect.variableHeader().isCleanSession());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:MQTTProtocolHandler.java


示例9: notifyClientConnected

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
@Override
public void notifyClientConnected(final MqttConnectMessage msg) {
    for (final InterceptHandler handler : this.handlers.get(InterceptConnectMessage.class)) {
        LOG.debug("Sending MQTT CONNECT message to interceptor. CId={}, interceptorId={}",
                msg.payload().clientIdentifier(), handler.getID());
        executor.execute(() -> handler.onConnect(new InterceptConnectMessage(msg)));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例10: newSession

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
private Session newSession(MqttConnectMessage msg, boolean cleanSession, String clientId, String clientIp,
		int clientPort) {
	return new Session(clientId, clientIp, clientPort, msg.variableHeader().keepAliveTimeSeconds(), cleanSession,
			newWill(clientId, msg));
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:6,代码来源:ConnectReceiver.java


示例11: channelRead

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
   try {
      if (stopped) {
         disconnect(true);
         return;
      }

      MqttMessage message = (MqttMessage) msg;

      // Disconnect if Netty codec failed to decode the stream.
      if (message.decoderResult().isFailure()) {
         log.debug("Bad Message Disconnecting Client.");
         disconnect(true);
         return;
      }

      connection.dataReceived();

      MQTTUtil.logMessage(session.getState(), message, true);

      this.protocolManager.invokeIncoming(message, this.connection);

      switch (message.fixedHeader().messageType()) {
         case CONNECT:
            handleConnect((MqttConnectMessage) message, ctx);
            break;
         case PUBLISH:
            handlePublish((MqttPublishMessage) message);
            break;
         case PUBACK:
            handlePuback((MqttPubAckMessage) message);
            break;
         case PUBREC:
            handlePubrec(message);
            break;
         case PUBREL:
            handlePubrel(message);
            break;
         case PUBCOMP:
            handlePubcomp(message);
            break;
         case SUBSCRIBE:
            handleSubscribe((MqttSubscribeMessage) message);
            break;
         case UNSUBSCRIBE:
            handleUnsubscribe((MqttUnsubscribeMessage) message);
            break;
         case PINGREQ:
            handlePingreq();
            break;
         case DISCONNECT:
            disconnect(false);
            break;
         case UNSUBACK:
         case SUBACK:
         case PINGRESP:
         case CONNACK: // The server does not instantiate connections therefore any CONNACK received over a connection is an invalid control message.
         default:
            disconnect(true);
      }
   } catch (Exception e) {
      log.debug("Error processing Control Packet, Disconnecting Client", e);
      disconnect(true);
   } finally {
      ReferenceCountUtil.release(msg);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:69,代码来源:MQTTProtocolHandler.java


示例12: InterceptConnectMessage

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
public InterceptConnectMessage(MqttConnectMessage msg) {
    super(msg);
    this.msg = msg;
}
 
开发者ID:andsel,项目名称:moquette,代码行数:5,代码来源:InterceptConnectMessage.java


示例13: notifyClientConnected

import io.netty.handler.codec.mqtt.MqttConnectMessage; //导入依赖的package包/类
void notifyClientConnected(MqttConnectMessage msg); 
开发者ID:andsel,项目名称:moquette,代码行数:2,代码来源:Interceptor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LineNumberTableElement类代码示例发布时间:2022-05-23
下一篇:
Java EurekaServerContext类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap