Could not send the message to HornetQ 2.2.2 using core api
signbird Apr 8, 2011 4:51 AMHi, I'm trying to use the core api to send a message to hornetq standalone server, but failed. we get no exception at client side, while the hornetq server shows:
[hornetq-failure-check-thread] 16:30:02,048 WARNING [org.hornetq.core.protocol.c ore.impl.RemotingConnectionImpl] Connection failure has been detected: Did not receive data from /127.0.0.1:60392. It is likely the client has exited or crashe d without closing its connection, or the network between the server and client h as failed. You also might have configured connection-ttl and client-failure-chec k-period incorrectly. Please check user manual for more information. The connect ion will now be closed. [code=3]
Could u plz give me any advice about it? thx a lot.
The Java Codes:
import java.util.HashMap; import java.util.Map; import org.hornetq.api.core.TransportConfiguration; import org.hornetq.api.core.client.ClientConsumer; import org.hornetq.api.core.client.ClientMessage; import org.hornetq.api.core.client.ClientProducer; import org.hornetq.api.core.client.ClientSession; import org.hornetq.api.core.client.ClientSessionFactory; import org.hornetq.api.core.client.HornetQClient; import org.hornetq.api.core.client.ServerLocator; import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; import org.hornetq.core.remoting.impl.netty.TransportConstants; public class Test { public static void main(String[] args) throws Exception { Map<String, Object> params = new HashMap<String, Object>(); params.put(TransportConstants.HOST_PROP_NAME, "localhost"); params.put(TransportConstants.PORT_PROP_NAME, "5445"); TransportConfiguration configuration = new TransportConfiguration( NettyConnectorFactory.class.getName(), params); 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"); System.out.println("message = " + message.getBodyBuffer().readString()); producer.send(message); session.start(); ClientConsumer consumer = session.createConsumer("compris.channel"); ClientMessage msgReceived = consumer.receive(2000); System.out.println("message = " + msgReceived.getBodyBuffer().readString()); session.close(); } catch (Exception e) { e.printStackTrace(); }finally { if (session != null) { session.close(); } if (factory != null) { factory.close(); } if(serverLocator != null) { serverLocator.close(); } } } }
The hornetq-beans.xml
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="urn:jboss:bean-deployer:2.0"> <!-- MBean server --> <bean name="MBeanServer" class="javax.management.MBeanServer"> <constructor factoryClass="java.lang.management.ManagementFactory" factoryMethod="getPlatformMBeanServer"/> </bean> <!-- The core configuration --> <bean name="Configuration" class="org.hornetq.core.config.impl.FileConfiguration"> </bean> <!-- The core server --> <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl"> <constructor> <parameter> <inject bean="Configuration"/> </parameter> <parameter> <inject bean="MBeanServer"/> </parameter> </constructor> <start ignored="false"/> <stop ignored="false"/> </bean> </deployment>
The hornetq-configuration.xml
<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd"> <security-enabled>false</security-enabled> <persistence-enabled>true</persistence-enabled> <journal-sync-non-transactional>true</journal-sync-non-transactional> <journal-sync-transactional>true</journal-sync-transactional> <journal-min-files>20</journal-min-files> <journal-buffer-timeout>20000</journal-buffer-timeout> <log-journal-write-rate>false</log-journal-write-rate> <run-sync-speed-test>false</run-sync-speed-test> <acceptors> <acceptor name="netty"> <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class> <param key="host" value="${hornetq.remoting.netty.host:localhost}"/> <param key="port" value="${hornetq.remoting.netty.port:5445}"/> <param key="tcp-no-delay" value="true"/> <param key="tcp-send-buffer-size" value="1048576"/> <param key="tcp-receive-buffer-size" value="1048576"/> </acceptor> </acceptors> <!-- <perf-blast-pages>5000</perf-blast-pages> --> <queues> <queue name="compris.channel"> <address>compris</address> </queue> <queue name="compris.response"> <address>compris</address> </queue> </queues> <address-settings> <address-setting match="compris"> <max-size-bytes>10485760</max-size-bytes> <address-full-policy>BLOCK</address-full-policy> </address-setting> </address-settings> </configuration>