-
1. Re: HornetQ core client API with standalone non-clustered server
jbertram Mar 12, 2012 10:44 PM (in response to pgiacome)1 of 1 people found this helpfulConnecting to a remote HornetQ server using the "core" API is basically the same as connecting to an embedded server except you (of course) don't start an embedded server and you pass a few different parameters to the server locator factory. For example:
HashMap<String, Object> connectionParams = new HashMap<String, Object>();
connectionParams.put(TransportConstants.HOST_PROP_NAME, "remoteHost");
connectionParams.put(TransportConstants.PORT_PROP_NAME, "5445);
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams));
ClientSessionFactory sf = serverLocator.createSessionFactory();
session = sf.createSession(false, true, true);
...
-
2. Re: HornetQ core client API with standalone non-clustered server
pgiacome Mar 13, 2012 6:31 AM (in response to jbertram)Thanks Justin for your reply I was able to manage the connection however the consumerclient gave me an error
the code is this
HashMap map = new HashMap(); map.put("host", "localhost"); map.put("port", 5445); TransportConfiguration configuration = new TransportConfiguration(
NettyConnectorFactory.class.getName(), map);
ServerLocator serverLocator = null;
ClientSessionFactory factory = null;
ClientSession session = null;
try {
serverLocator = HornetQClient.createServerLocatorWithoutHA(configuration);
factory = serverLocator.createSessionFactory();
session = factory.createSession();
ClientProducer producer = session.createProducer("compris.channel");
System.out.println(producer.isClosed());
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("Hello");
message.setExpiration(60000)
; System.out.println("message = "
+ message.getBodyBuffer().readString());
producer.send(message);
session.start();
ClientConsumer consumer = session.createConsumer("compris.channel");
ClientMessage msgReceived = consumer.receive(100);
System.out.println("message = "+ msgReceived.getBodyBuffer().readString());
session.close();
} catch (Exception e) {
e.printStackTrace();
}finally
{
if (session != null)
{
try {
session.close(); } catch (HornetQException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
if (factory != null)
{
factory.close();
}
if(serverLocator != null)
{
serverLocator.close();
}
}
I get an errror like this
false
message = Hello
HornetQException[errorCode=100 message=Queue compris.channel does not exist]
at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:286)
at org.hornetq.core.client.impl.ClientSessionImpl.internalCreateConsumer(ClientSessionImpl.java:1685)
at org.hornetq.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:461)
at org.hornetq.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:427)
at org.hornetq.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:396)
at org.hornetq.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:401)
at org.hornetq.core.client.impl.DelegatingSession.createConsumer(DelegatingSession.java:231)
at Example1.main(Example1.java:54)
when I try to
execute
ClientConsumer consumer = session.createConsumer("compris.channel");
but it seems that the message send method works great
If someone can gave some suggestions
Thks
-
3. Re: HornetQ core client API with standalone non-clustered server
jbertram Mar 13, 2012 10:07 AM (in response to pgiacome)Can you confirm that you've created the proper artifacts on the server? If you send a message to an address (since you always send to an address and never directly to a queue) which doesn't have any queues bound to it the message simply vanishes, but if you try to create a consumer for a queue which doesn't exist you will receive an error.
-
4. Re: HornetQ core client API with standalone non-clustered server
pgiacome Mar 14, 2012 12:45 PM (in response to jbertram)Ok so I miss to bound the address to the queue but how can I do this?
Piero