Alfergon
Alfergon

Reputation: 5919

How to connect programmatically to an embedded HornetQ server

I'm running an embedded HornetQ server on an OSGI container following an example for embedded HornetQ Core.

I have three OSGI containers: one for the server, one for a producer and a last one for a consumer. Everything works on local.

The code I'm using in both the producer and consumer for connecting to the server is the following:

// Step 4. 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();

I've tried looking at the TransportConfiguration methods, but no setter was found.

Upvotes: 3

Views: 628

Answers (1)

Clebert Suconic
Clebert Suconic

Reputation: 5383

You need to pass parameters to the Transport configuration:

Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("port", org.hornetq.core.remoting.impl.netty.TransportConstants
                      .DEFAULT_PORT);
parameters.put(TransportConstants.HOST_PROP_NAME, "127.0.0.1");

TransportConfiguration configuration = new TransportConfiguration(
        NettyConnectorFactory.class.getName(), parameters);

Notice you have / could do the same to the NettyAcceptor. I'm not sure how you are configuring the acceptors at your test.. but I hope you get the idea.

Upvotes: 2

Related Questions