我是HornetQ的新手,我试图找出2-3天,但没有希望。 我需要创建一个客户端,它将从HornetQ服务器(在虚拟机中)接收消息,但似乎我的客户端无法连接到远程HornetQ服务器。
预期:
1 HornetQ stand-alone and sender (in VM)
2 clients as receivers (in real machine)
发信人:
Map<String, Object> connectionParams = new HashMap<String, Object>();
//localhost(127.0.0.1 where is my VM locates)
//port 5445 (default port of HornetQ)
connectionParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);
//Create ConnectionFactory
ConnectionFactory cf = new HornetQTopicConnectionFactory(false, transportConfiguration);
//Create Connection
connection = cf.createConnection();
//Create Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
//Create Topic
topic = HornetQJMSClient.createTopic("myTopic");
//Create Producer
MessageProducer producer = session.createProducer(topic);
接收器:
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "remote://localhost:5445");
p.put(Context.SECURITY_PRINCIPAL, "username");
p.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext context = new InitialContext(p);
//Create ConnectionFactory
ConnectionFactory factory = (ConnectionFactory)context.lookup("/ConnectFatory");
//Create connection
connection = (Connection) factory.createConnection();
//Create session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (HornetQTopic) HornetQJMSClient.createTopic("myTopic");
//Create consumer
MessageConsumer consumer = session.createConsumer(topic);
当我在VM中运行./run.sh(发件人工作正常) 然后我在真机上运行客户端(接收器),但它无法连接到HornetQ服务器(在VM中运行)
javax.naming.NamingException: Failed to connect to any server. Servers tried: [remote://localhost:5445]
at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:213)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:144)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:125)
at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:241)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.dtv.apg.hornetq.SubA.run(SubA.java:70)
at java.lang.Thread.run(Thread.java:722)
感谢您的任何建议。
答案 0 :(得分:0)
现在我尽量保持简单
param key =&#34; host&#34;值=&#34; 10.88.106.223&#34;
param key =&#34; port&#34;值=&#34; 5445&#34;
它的工作,似乎我为虚拟机选择了错误的IP(127.0.0.1)。 祝你有愉快的一天。