简体   繁体   English

线程“main”中的异常 java.lang.IllegalArgumentException:没有为 URI“http://xxx.xxx.xxx.xxx:xxxx”的方案“http”安装 NetworkModule

[英]Exception in thread “main” java.lang.IllegalArgumentException: no NetworkModule installed for scheme “http” of URI “http://xxx.xxx.xxx.xxx:xxxx”

I'm currently using on MQTT eclipse/paho.mqtt.java library for my project.我目前正在为我的项目使用 MQTT eclipse/paho.mqtt.java 库。 this is the link of eclipse/paho.mqtt.java library.这是 eclipse/paho.mqtt.java 库的链接。

https://github.com/eclipse/paho.mqtt.java https://github.com/eclipse/paho.mqtt.java

I wanted to connect with MQTT with http protocol.我想用 http 协议连接 MQTT。 but the original library make for the tcp protocol.但原始库适用于tcp协议。 I tried to make a connection with mqtt by making a mqtt client.我试图通过创建一个 mqtt 客户端来与 mqtt 建立连接。 I will show my code in below,我将在下面显示我的代码,

Sorry about using the xxx symbols in the IP addresses and the URLs.抱歉在 IP 地址和 URL 中使用xxx符号。

import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;


public class MQTT {
  public static void main(String[] args) {

    String topic        = "MQTT Examples";
    String content      = "Message from MqttPublishSample";
    int qos             = 2;
    //String broker       = "tcp://iot.eclipse.org:1883";
    String broker       = "http://xxx.xxx.xxx.xxx:xxxx";
    String clientId     = "JavaSample";
    MemoryPersistence persistence = new MemoryPersistence();

    try {
        MqttClient sampleClient = new MqttClient(broker, clientId, null);
        MqttConnectOptions connOpts = new MqttConnectOptions();
        connOpts.setCleanSession(true);
        String accessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        String pass = "";
        char[] charArr = pass.toCharArray();
        //I added in here my access token of the server
        connOpts.setUserName(accessToken);
        connOpts.setPassword(charArr);
        System.out.println("Connecting to broker: "+broker);
        sampleClient.connect(connOpts);
        System.out.println("Connected");
        System.out.println("Publishing message: "+content);
        MqttMessage message = new MqttMessage(content.getBytes());
        message.setQos(qos);
        sampleClient.publish(topic, message);
        System.out.println("Message published");
        sampleClient.disconnect();
        System.out.println("Disconnected");
        System.exit(0);
    } catch(MqttException me) {
        System.out.println("reason "+me.getReasonCode());
        System.out.println("msg "+me.getMessage());
        System.out.println("loc "+me.getLocalizedMessage());
        System.out.println("cause "+me.getCause());
        System.out.println("excep "+me);
        me.printStackTrace();
    }
  }
}

It shows following error,它显示以下错误,

Exception in thread "main" java.lang.IllegalArgumentException: no NetworkModule installed for scheme "http" of URI "http://xxx.xxx.xxx.xxx:xxxx"
at org.eclipse.paho.client.mqttv3.internal.NetworkModuleService.validateURI(NetworkModuleService.java:70)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:454)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:320)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:315)
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:227)
at MQTT.main(MQTT.java:17)

So what should I do for this, in example the eclipse had been use tcp protocol in String broker ="tcp://iot.eclipse.org:1883";那么我应该怎么做,例如tcpString broker ="tcp://iot.eclipse.org:1883"; . . but I want to set the http for this, I tried to add it as this, String broker = "http://xxx.xxx.xxx.xxx:xxxx";但我想为此设置http ,我尝试将其添加为, String broker = "http://xxx.xxx.xxx.xxx:xxxx"; then got thte above error, So what should do for this.然后得到了上述错误,那么应该怎么做。

It is not clear from the question what you are trying to do, but this may help clarify a few things for you.从问题中不清楚您要做什么,但这可能有助于为您澄清一些事情。

  1. MQTT is Pub/Sub protocol, HTTP is a request response protocol. MQTT 是 Pub/Sub 协议,HTTP 是请求响应协议。 The whole paradigm is different, you can not just directly substitute one for the other.整个范式是不同的,你不能直接用一个代替另一个。
  2. MQTT normally runs natively on top of TCP/IP, but it can also run using Websockets as the transport layer. MQTT 通常在 TCP/IP 之上本地运行,但它也可以使用 Websockets 作为传输层运行。 Websockets do boot strap over HTTP. Websockets 在 HTTP 上做引导。

The in the Paho client broker URL schema (protocols) can be one of the following: Paho 客户端代理中的 URL 架构(协议)可以是以下之一:

  • tcp:// This is native MQTT over TCP tcp://这是 TCP 上的本机 MQTT
  • ssl:// This is native MQTT over TCP with SSL/TLS ssl://这是在 TCP 上使用 SSL/TLS 的本机 MQTT
  • ws:// This MQTT over Websockets ws://这个 MQTT over Websockets
  • wss:// This is MQTT over Websockets with SSL/TLS wss://这是 MQTT over Websockets with SSL/TLS
  • local:// special case not useful here. local://特殊情况在这里没有用。

In order to use anything other than basic MQTT over TCP ( tcp:// ) you will need to configure the broker to support this as an extra listener on a different port to the default 1883.为了在 TCP ( tcp:// ) 上使用除基本 MQTT 以外的任何东西,您需要将代理配置为在与默认 1883 不同的端口上支持此作为额外的侦听器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将ip字符串xxx.xxx.xxx.xxx:xxxxx转换为xxx.xxx.xxx.xxx? - How to convert a ip string xxx.xxx.xxx.xxx:xxxxx to xxx.xxx.xxx.xxx? java.lang.IllegalArgumentException:具有该名称 [xxx] 的参数不存在 - java.lang.IllegalArgumentException: Parameter with that name [xxx] did not exist JPA java.lang.IllegalArgumentException:名称为[xxx]的参数不存在 - JPA java.lang.IllegalArgumentException: Parameter with that name [xxx] did not exist 获取“java.lang.IllegalArgumentException:不知道如何将 XXX 编码为字节流。” - Getting “java.lang.IllegalArgumentException: Don't know how to encode XXX as a byte stream.” 线程“ main”中的异常java.lang.IllegalArgumentException:URI不是分层的 - Exception in thread “main” java.lang.IllegalArgumentException: URI is not hierar chical HTTPS主机名错误:应为 <xxx.xxx.xxx.xxx> ,请检查URL欺骗。 传递的主机名是什么? - HTTPS hostname wrong: should be <xxx.xxx.xxx.xxx>, checkURLSpoofing. What is the host name being passed? 线程“main”中的异常java.lang.Error:未解决的编译问题:局部变量xxx可能尚未初始化 - Exception in thread "main" java.lang.Error: Unresolved compilation problems: The local variable xxx may not have been initialized 在名为xx的DispatcherServlet中找不到具有URI xxx的HTTP请求的映射 - No mapping found for HTTP request with URI xxx in DispatcherServlet with name xx XXX和java.lang.Class有什么区别<XXX> - what is difference between XXX and java.lang.Class<XXX> Java Spring异常:未找到类型xxx的属性xxx - Java Spring exception: No property xxx found for type class xxx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM