-1

I'm new in HornetQ, and I have tried to figure out for 2-3 days but hopeless. I need to create a client which will receive message from HornetQ server (in Virtual Machine) but it seems like my client cannot connect to remote HornetQ server.

Expected:

1 HornetQ stand-alone and sender (in VM)
2 clients as receivers (in real machine)

Sender:

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);

Receiver:

    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);

When I ./run.sh in VM (sender work fine) then I run clients(receivers) in real machine but it cannot connect to HornetQ server (which is running in 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)

Thank you for any suggestion.

4

1 回答 1

0

现在我尽量保持简单

  1. 我在其他 PC (10.88.106.223) 中启动 HornetQ 并在 hornetq-configuration.xml 中更改接受器

参数键="主机" 值="10.88.106.223"

参数键=“端口”值=“5445”

它的工作,似乎我为虚拟机(127.0.0.1)选择了错误的IP。祝你有愉快的一天。

于 2014-07-31T06:07:13.653 回答