往apache-apollo推送数据,报错check your installation and try again
package com.utils;
import javax.jms.Connection;
import javax.jms.JMSException;
import org.fusesource.stomp.jms.StompJmsConnectionFactory;
import com.typesafe.config.Config;
public class ApolloUtil {
private static Connection connection = null;
public static Connection getConnection() {
if(connection == null){
String user = "admin";
String password = "password";
String host = "10.0.4.153";
int port = 61613;
try {
StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
factory.setBrokerURI("tcp://" + host + ":" + port);
connection = factory.createConnection(user, password);
connection.start();
} catch (JMSException e) {
return null;
}
}
return connection;
}
}
package com.utils;
import javax.jms.Connection;
import javax.jms.Session;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.TextMessage;
import org.fusesource.stomp.jms.StompJmsDestination;
import org.fusesource.stomp.jms.message.StompJmsBytesMessage;
public class ScreenSendData {
public static void main(String[] args) {
Session session = null;
Connection connection = null;
try {
String destination = "/topic/topic-controller"; // destination 目的
ApolloUtil.getConnection();
connection = ApolloUtil.getConnection(); // 连接 Apollo
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = new StompJmsDestination(destination);
MessageConsumer consumer = session.createConsumer(dest);
try {
Message msg = consumer.receive();
if (msg instanceof TextMessage) {
System.out.println("终于从 Apollo 收到消息了");
}
}catch (Exception e) {
System.out.println(e);
}
} catch (JMSException e) {
System.out.println(e);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论