【问题标题】:Cannot connect to Solace Cloud无法连接到 Solace Cloud
【发布时间】:2018-12-21 02:05:28
【问题描述】:

我正在关注发布/订阅的安慰教程(链接:https://dev.solace.com/samples/solace-samples-java/publish-subscribe/)。因此,代码不应该有任何“错误”。

我正在尝试让我的 TopicSubscriber 连接到云。构建我的 jar 后,我运行以下命令:

java -cp target/SOM_Enrichment-1.0-SNAPSHOT.jar TopicSubscriber <host:port> <client-username@message-vpn> <password>

(填写适当的字段)

我收到以下错误:

TopicSubscriber initializing...
Jul 12, 2018 2:27:56 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel call
INFO: Connecting to host 'blocked out' (host 1 of 1, smfclient 2, attempt 1 of 1, this_host_attempt: 1 of 1)
Jul 12, 2018 2:28:17 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel call
INFO: Connection attempt failed to host 'blocked out' ConnectException com.solacesystems.jcsmp.JCSMPTransportException: ('blocked out') - Error communicating with the router. cause: java.net.ConnectException: Connection timed out: no further information ((Client name: 'blocked out'   Local port: -1   Remote addr: 'blocked out') - )
Jul 12, 2018 2:28:20 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel close
INFO: Channel Closed (smfclient 2)
Exception in thread "main" com.solacesystems.jcsmp.JCSMPTransportException" (Client name: 'blocked out'   Local port: -1   Remote addr: 'blocked out') - Error communicating with the router.

以下是 TopicSubscriber.java 文件:

import java.util.concurrent.CountDownLatch;

import com.solacesystems.jcsmp.BytesXMLMessage;
import com.solacesystems.jcsmp.JCSMPException;
import com.solacesystems.jcsmp.JCSMPFactory;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.JCSMPSession;
import com.solacesystems.jcsmp.TextMessage;
import com.solacesystems.jcsmp.Topic;
import com.solacesystems.jcsmp.XMLMessageConsumer;
import com.solacesystems.jcsmp.XMLMessageListener;

public class TopicSubscriber {

    public static void main(String... args) throws JCSMPException {

        // Check command line arguments
    if (args.length != 3 || args[1].split("@").length != 2) {
        System.out.println("Usage: TopicSubscriber <host:port> <client-username@message-vpn> <client-password>");
        System.out.println();
        System.exit(-1);
    }
    if (args[1].split("@")[0].isEmpty()) {
        System.out.println("No client-username entered");
        System.out.println();
        System.exit(-1);
    }
    if (args[1].split("@")[1].isEmpty()) {
        System.out.println("No message-vpn entered");
        System.out.println();
        System.exit(-1);
    }

    System.out.println("TopicSubscriber initializing...");
    final JCSMPProperties properties = new JCSMPProperties();
    properties.setProperty(JCSMPProperties.HOST, args[0]);     // host:port
    properties.setProperty(JCSMPProperties.USERNAME, args[1].split("@")[0]); // client-username
    properties.setProperty(JCSMPProperties.PASSWORD, args[2]); // client-password
    properties.setProperty(JCSMPProperties.VPN_NAME, args[1].split("@")[1]); // message-vpn
    final Topic topic = JCSMPFactory.onlyInstance().createTopic("tutorial/topic");
    final JCSMPSession session = JCSMPFactory.onlyInstance().createSession(properties);

    session.connect();

    final CountDownLatch latch = new CountDownLatch(1); // used for
    // synchronizing b/w threads
    /** Anonymous inner-class for MessageListener
     *  This demonstrates the async threaded message callback */
    final XMLMessageConsumer cons = session.getMessageConsumer(new XMLMessageListener() {
        @Override
        public void onReceive(BytesXMLMessage msg) {
            if (msg instanceof TextMessage) {
                System.out.printf("TextMessage received: '%s'%n",
                        ((TextMessage) msg).getText());
            } else {
                System.out.println("Message received.");
            }
            System.out.printf("Message Dump:%n%s%n", msg.dump());
            latch.countDown();  // unblock main thread
        }

        @Override
        public void onException(JCSMPException e) {
            System.out.printf("Consumer received exception: %s%n", e);
            latch.countDown();  // unblock main thread
        }
    });
    session.addSubscription(topic);
    System.out.println("Connected. Awaiting message...");
    cons.start();
    // Consume-only session is now hooked up and running!

    try {
        latch.await(); // block here until message received, and latch will flip
    } catch (InterruptedException e) {
        System.out.println("I was awoken while waiting");
    }
    // Close consumer
    cons.close();
    System.out.println("Exiting.");
    session.closeSession();
 }
}

任何帮助将不胜感激。

【问题讨论】:

    标签: solace


    【解决方案1】:

    java.net.ConnectException: Connection timed out

    日志条目表明无法建立到指定 DNS 名称/IP 地址的网络连接。

    下一步包括:

    1. 验证您是否能够将 DNS 名称解析为 IP 地址。
    2. 验证是否使用了正确的 DNS 名称/IP 地址/端口 - 您需要 Solace 云连接详细信息中的“SMF 主机”。
    3. 验证 IP 地址/端口未被中间网络设备阻止。

    【讨论】:

    • 嗯,我刚刚检查了我的慰藉服务,状态正在运行。我不太确定如何执行您列出的步骤.. 对这一切有点新哈哈
    • 作为第一步,总是有命令行实用程序 ping: "ping " 要验证与特定 tcp 端口的连接,您可以尝试 telnet:"telnet " 这些命令应该可以在包括 Mac 在内的大多数类 Unix 操作系统和 Windows 上的 Cygwin 上开箱即用。
    猜你喜欢
    • 2020-11-06
    • 2022-01-24
    • 2017-12-02
    • 2013-06-15
    • 2014-11-25
    • 2021-02-12
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多