Java WSS 连接无法创建传输异常 [英] Java WSS Connection Could not create transport exception

查看:45
本文介绍了Java WSS 连接无法创建传输异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此很纠结.

我想订阅一个 ActiveMQ 主题.ActiveMQ 适用于 Centos 机器,非本地主机.我可以使用 tcp、http 协议使用消息.代码;

I want to subscribe an ActiveMQ topic. ActiveMQ works on Centos machine, NOT LOCALHOST. I can consume messages with tcp, http protocols. Code;

public static void main(String[] args) throws JMSException {
    PropertyUtils.loadPropertyFile();
    Properties receiverProperties = PropertyUtils.getreceiverProperties();

    // URL of the JMS server
    String url = (String) receiverProperties.get("receiver.connection.url");

    // Name of the queue we will receive messages from
    String subject = (String) receiverProperties.get("receiver.topic.name");

    // Getting JMS connection from the server
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // Creating session for getting messages
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    // Getting the topic
    Destination destination = session.createTopic(subject);

    // MessageConsumer is used for receiving (consuming) messages
    MessageConsumer consumer = session.createConsumer(destination);
    Message message = null;

    // Here we receive the message.
    while (true) {
        message = consumer.receive();
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            System.out.println("Received message '" + textMessage.getText() + "'");
        }
    }

    // We will be using TestMessage in our example. MessageProducer sent us a
    // TextMessage
    // so we must cast to it to get access to its .getText() method.
    // connection.close();
}

我想使用 wss 协议.这对我来说是必须的.当我使用 wss://host:port getting;

I want to use wss protocol. This is a must for me. When I changed url with wss://host:port getting;

Could not create Transport. Reason: java.io.IOException: createTransport() method not implemented!

所以我检查了替代方案.人们通过 Stomp over WS 来解决这个问题.我的第一个成就是 wss 连接.

So I checked the alternatives. People figure this out with Stomp over WS. My first achievement is wss connection.

任何推荐将不胜感激!

推荐答案

您看到的异常是意料之中的,因为您使用的 OpenWire JMS 客户端不支持 WebSocket 连接,而且实际上也不需要.WebSocket 连接实际上只与在有限环境(如 Web 浏览器)中运行的客户端相关.Web 浏览器不支持运行 Java 客户端.

The exception you're seeing is expected because the OpenWire JMS client you're using doesn't support WebSocket connections, and it doesn't really need to. WebSocket connections are really only relevant for clients running in a limited environment like a web browser. Web browsers don't support running Java clients.

如果您真的想在 WebSockets 上使用 STOMP,那么您必须使用支持 WebSockets 的 STOMP 客户端实现(大多数情况下).

If you really want to use STOMP over WebSockets then you'll have to use a STOMP client implementation that supports WebSockets (most do).

请记住,ActiveMQ 是一个代理.它不为它支持的所有协议提供客户端.它只提供了一个 JMS 客户端,因为它是实现 JMS 所必需的.例如,STOMP 是一种标准化协议,任何人都可以实现一个客户端,该客户端将与任何实现 STOMP 的代理一起工作.有许多可用的 STOMP 客户端实现可以用多种不同的语言为许多不同的平台编写.任何好的搜索引擎都会帮助您找到适合您需求的搜索引擎.

Keep in mind that ActiveMQ is a broker. It does not supply clients for all the protocols it supports. It only provides a JMS client because it is required in order to implement JMS. STOMP, for example, is a standardized protocol and anyone can implement a client which will work with any broker implementing STOMP. There are lots of STOMP client implementations available written in many different languages for many different platforms. Any good search engine should help you find one to fit your needs.

这篇关于Java WSS 连接无法创建传输异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆