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.