At the moment I'm struggling to learn HornetQ. The things seem quite straightforward in theory, but I'm having a hard time running even the most basic example.
So far I've tried to start HornetQ as a standalone server, and connect a simple client that sends a message and then receives it back.
The steps I've followed are : (accordingly to HornetQ docs http://hornetq.sourceforge.net/docs/hornetq-2.0.0.GA/user-manual/en/html/using-jms.html)
-Downloaded the latest version of HornetQ (2.2.5) and extracted it. -Modified the INSTALL_DIRECTORY\config\stand-alone\non-clustered\hornetq-jms.xml file to create the objects I need, below is the content :
<configuration xmlns="urn:hornetq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:hornetq ../schemas/hornetq-jms.xsd ">
<connection-factory name="ConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="ConnectionFactory"/>
</entries>
</connection-factory>
<queue name="OrderQueue">
<entry name="queues/OrderQueue"/>
</queue>
</configuration>
-The file INSTALL_DIRECTORY\config\stand-alone\non-clustered\hornetq-beans.xml contain the bean needed to start the JNDI service.
-There is also a file called jndi.properties in the INSTALL_DIRECTORY\config\stand-alone\non-clustered\ folder
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
The Client code is the following :
public void test()
{
try
{
ic = new InitialContext();
cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
orderQueue = (Queue)ic.lookup("/queues/OrderQueue");
connection = cf.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(orderQueue);
consumer = session.createConsumer(orderQueue);
connection.start();
TextMessage message = session.createTextMessage("This is an order");
producer.send(message);
TextMessage receivedMessage = (TextMessage)consumer.receive();
System.out.println("Got order: " + receivedMessage.getText());
}
catch (Exception e)
{
e.printStackTrace();
}
}
Yet whenever I run it, it crashes with the following exception :
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
I think I've tried everything in order to make it run, and yet it still eludes me what I'm doing wrong. Any suggestions on this matter are greatly appreciated !