-
1. Re: Connecting to Embedded JMS from anther VM
clebert.suconic Mar 28, 2012 8:50 AM (in response to abdaraeh)Look on the acceptors and connectors chapter.
You just have to configure the acceptor and the connector with a proper IP, etc.. same way it happens on any HornetQ server. (It's no different here)
-
2. Re: Connecting to Embedded JMS from anther VM
abdaraeh Mar 28, 2012 2:31 PM (in response to clebert.suconic)I know how it is done using XML config files but not sure how do you configure this programatically. Do you have sample code on how to set the connector/acceptor with the proper IP and port.
-
3. Re: Connecting to Embedded JMS from anther VM
ideaalloc Apr 20, 2012 3:43 AM (in response to abdaraeh)You can also set connector/acceptor programatically. The example 'examples\core\embedded-remote' has every details on this.
// Server
try
{
// Step 2. Create the Configuration, and set the properties accordingly
Configuration configuration = new ConfigurationImpl();
configuration.setPersistenceEnabled(false);
configuration.setSecurityEnabled(false);
TransportConfiguration transpConf = new TransportConfiguration(NettyAcceptorFactory.class.getName());
HashSet<TransportConfiguration> setTransp = new HashSet<TransportConfiguration>();
setTransp.add(transpConf);
configuration.setAcceptorConfigurations(setTransp);
// Step 3. Create and start the server
HornetQServer server = HornetQServers.newHornetQServer(configuration);
server.start();
System.out.println("STARTED::");
}
catch (Exception e)
{
System.out.println("FAILED::");
e.printStackTrace();
}
// client
try
{
// Step 1. As we are not using a JNDI environment we instantiate the objects directly
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
ClientSessionFactory sf = serverLocator.createSessionFactory();
// Step 2. Create a core queue
ClientSession coreSession = sf.createSession(false, false, false);
final String queueName = "queue.exampleQueue";
coreSession.createQueue(queueName, queueName, true);
coreSession.close();
ClientSession session = null;
try
{
// Step 3. Create the session, and producer
session = sf.createSession();
ClientProducer producer = session.createProducer(queueName);
// Step 4. Create and send a message
ClientMessage message = session.createMessage(false);
final String propName = "myprop";
message.putStringProperty(propName, "Hello sent at " + new Date());
System.out.println("Sending the message.");
producer.send(message);
// Step 5. Create the message consumer and start the connection
ClientConsumer messageConsumer = session.createConsumer(queueName);
session.start();
// Step 6. Receive the message.
ClientMessage messageReceived = messageConsumer.receive(1000);
System.out.println("Received TextMessage:" + messageReceived.getStringProperty(propName));
}
finally
{
// Step 7. Be sure to close our resources!
if (sf != null)
{
sf.close();
}
}
}
catch (Exception e)
{
e.printStackTrace();
System.exit(-1);
}