MQTT常见问题

What is MQTT?

MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimise network bandwidth and device resource

MQTT是什么?

MQTT是一项异步消息传输协议,它是一种极其简洁,轻量级的信息接收/推送协议,专门设计适用于受限制的,低带宽或者高延时不稳定的网络环境下的设备之间的通信。设计的原则是用最少的设备的资源,和最小的网络带宽,在不稳定的网络环境下保证信息的完整传输。

requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make theprotocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.

这个设计原则也同时也是现在出现的“机器与机器”(M2M)或者“物联网”理念的理论基础,特别适用于这些网络带宽受限或者电量受限的设备之间的通信。

Who invented MQTT?MQTT was invented by Dr Andy Stanford-Clark of IBM, and Arlen Nipper of Arcom (now Eurotech), in 1999

谁发明的MQTT?

MQTT由IBM发明

Where is MQTT in use?

MQTT has been widely implemented across a variety of industries since 1999.

MQTT从1999年开始就在工业上非常广泛的使用。

Is MQTT a standard?

As of March 2013, MQTT is in the process of undergoing standardisation at OASIS.

MQTT是一个标准吗?自2014年3月份开始,MQTT就开始了oasis(结构化信息标准促进组织)的标准化的进程。

The protocol specification has been openly published with a royalty-free license for many years, and companies such as Eurotech (formerly known as Arcom) have implemented the protocol in their products.

该协议规范已经使用一个特许的免费license公开发表了多年,并且像Eurotech这样的公司已经在他们的产品中使用了这个协议。

In November 2011 IBM and Eurotech announced their joint participation in the Eclipse M2M Industry Working Group and donation of MQTT code to the proposed Eclipse Paho project.

How does MQTT relate to SCADA protocol and MQIsdp?

The “SCADA protocol” and the “MQ Integrator SCADA Device Protocol” (MQIsdp) are both old names for what is now known as the MQ Telemetry Transport (MQTT). The protocol has also been known as “WebSphere MQTT” (WMQTT), though that name is also no longer used.

MQTT 和 SCADA还有MQIsdp有什么关系?

他们3个指的都是同一个东西。只是其他两个是MQTT的旧名字

What is WebSphere MQ Telemetry?

This is a product from IBM which implements the MQTT protocol in a very scalable manner and which interoperates directly with the WebSphere MQ family of products.

什么是WebSphere MQ Telemetry?

这是一个在很大一部分上都实现了MQTT协议的一个产品,并且可以和WebSphere MQ家族的产品很好的交互

There are other implementations of MQTT listed on the Software page.

Are there standard ports for MQTT to use?

Yes. TCP/IP port 1883 is reserved with IANA for use with MQTT. TCP/IP port 8883 is also registered, for using MQTT over SSL.

有MQTT使用的标准端口吗?

有的 TCP/IP的 1833 端口就是IANA(互联网数字分配机构)为MQTT保留的保留端口,同时也注册了8883端口用于MQTT在SSL上的传输

Does MQTT support security?

You can pass a user name and password with an MQTT packet in V3.1 of the protocol. Encryption across the network can be handled with SSL,

independently of the MQTT protocol itself (it is worth noting that SSL is not the lightest of protocols, and does add significant network overhead).

Additional security can be added by an application encrypting data that it sends and receives, but this is not something built-in to the protocol,

MQTT支持安全传输吗?

你可以在V3.1版本的MQTT协议中用在传输包中传输用户名和密码。网络加密可以用SSL加密来处理。(值得注意的是,SSL是不是轻量级的协议,并会显著增加网络开销)

而外的加密我们可以用我们的应用来实现加密我们要发送和接收的额数据。而这些功能都不包括在我们MQTT协议的本身,协议本身更专注于简单和轻量级。

in order to keep it simple and lightweight.

Where can I find out more?

The specification and other documentation are available via the Documentation page.

Ask questions via one of the methods on the Community page.

### Java MQTT 面试问题及答案 #### 什么是MQTT协议? MQTT(Message Queuing Telemetry Transport)是一种轻量级的消息传输协议,专为低带宽、高延迟或不可靠网络环境设计。该协议采用发布/订阅模式,在物联网(IoT)领域广泛应用[^1]。 ```java // 创建MqttClient实例连接到服务器 String broker = "tcp://iot.eclipse.org:1883"; String clientId = MqttClient.generateClientId(); MemoryPersistence persistence = new MemoryPersistence(); MqttClient sampleClient = new MqttClient(broker, clientId, persistence); sampleClient.connect(); ``` #### 如何创建一个简单的MQTT客户端? 通过`org.eclipse.paho.client.mqttv3.MqttClient`类可以方便地建立与MQTT代理之间的TCP/IP连接。开发者需指定Broker地址以及唯一的clientId来初始化对象并调用connect()方法完成链接过程。 #### 发布消息时需要注意哪些事项? 当向主题发送数据包之前应该设置QoS级别(服务质量),它决定了消息传递的确切次数;同时还可以配置保留标志位使得最新的一条记录始终保存于对应的主题下以便新加入者获取最及时的信息更新。 ```java // 设置消息内容和属性 MqttMessage message = new MqttMessage("Hello World".getBytes()); message.setQos(2); // QoS Level 2 message.setRetained(true); // 发布消息至特定主题 sampleClient.publish("test/topic", message); ``` #### 订阅某个主题后如何接收来自其他设备发布的消息? 实现IMqttActionListener接口监听回调事件,并重写其内部的方法如onSuccess(), onFailure(). 当成功接收到一条新的通知时会触发deliveryComplete()函数从而允许应用程序进一步处理所关心的数据流变化情况。 ```java // 定义回调处理器 sampleClient.setCallback(new MqttCallbackExtended() { @Override public void connectComplete(boolean reconnect, String serverURI) {} @Override public void connectionLost(Throwable cause) {} @Override public void messageArrived(String topic, MqttMessage message) throws Exception { System.out.println("Received Message:" + new String(message.getPayload())); } @Override public void deliveryComplete(IMqttDeliveryToken token) {} }); // 开始订阅给定的主题过滤器 sampleClient.subscribe("test/#"); ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值