【发布时间】:2021-05-16 06:57:59
【问题描述】:
我很纠结这个。
我想订阅一个 ActiveMQ 主题。 ActiveMQ 在 Centos 机器上工作,NOCALHOST。我可以使用 tcp、http 协议来使用消息。代码;
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 更改 url 时;
Could not create Transport. Reason: java.io.IOException: createTransport() method not implemented!
所以我检查了替代方案。人们通过 Stomp over WS 来解决这个问题。我的第一个成就是 wss 连接。
任何推荐将不胜感激!
【问题讨论】:
-
您是否尝试使用 ActiveMQ JMS 客户端连接到 STOMP 传输连接器?
-
您将使用什么语言和 STOMP 客户端实现来连接?
-
@TimBish 是的,蒂姆。但这是我的第二个成就。我正在测试所有连接器。首先,我会选择 wss 连接器。
-
@JustinBertram 我将使用 Java。