0

我们在 Openshift 3.11 上运行 AMQ 7。尝试从 Openshift 平台使用 JMS 连接 Java 客户端时没有问题。但是,为了从外部客户端访问它,我创建了一个到 61617 端口的安全路由。在 Openshift 上,这条路线应该以https://my-route:443 的形式提供,我可以 ping my-route。但是我如何使用它来建立 JMS 连接,我不断得到:

javax.jms.JMSException: Failed to create session factory
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:886)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:299)
    at be.digipolis.artemis_consumer.ArtemisConsumerApplication.run(ArtemisConsumerApplication.java:39)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at be.digipolis.artemis_consumer.ArtemisConsumerApplication.main(ArtemisConsumerApplication.java:25)
Caused by: ActiveMQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=AMQ219013: Timed out waiting to receive cluster topology. Group:null]
    at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:821)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:884)
    ... 8 more

我的代码:

Connection connection = null;
InitialContext initialContext = null;

try {
    initialContext = new InitialContext();
    Queue queue = (Queue) initialContext.lookup("queue/hugo");
    ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
    connection = cf.createConnection(USERNAME, PASSWORD);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(queue);
    TextMessage message = session.createTextMessage("This is a text message");
    logger.info("Sent message: ", message.getText());
    producer.send(message);
    MessageConsumer consumer = session.createConsumer(queue);
    connection.start();
    TextMessage messageReceived = (TextMessage) consumer.receive(5000);
    logger.info("Received message : ", messageReceived);
    initialContext.close();
} catch (NamingException | JMSException e) {
    logger.error("Exception", e);
    e.printStackTrace();
} finally {
    if (initialContext != null) {
        initialContext.close();
    }
    if (connection != null) {
        connection.close();
    }
}

和 jndi.properties :


java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=tcp://my-route:443
queue.queue/hugo=hugo

我必须已经使用tcp而不是https,否则我会得到“无效的代理 url”。

如果有人能指出我正确的方向,那就太棒了。

4

1 回答 1

0

尝试这个:

tcp://my-route:443?httpEnabled=true&sslEnabled=true
于 2020-03-24T14:16:23.890 回答