4 Replies Latest reply on Aug 13, 2012 3:54 AM by javahamburg

    Can't send message to queue via producer

    javahamburg Newbie


      I'm trying since two days sending a message via the hornetq core api, but I can't get it to work. I read the documentation and searched the web a lot, so I think this is the place where I can get finally help now. I extracted the relevant logic in the demo program below.

      The problem: I send a ClientMessage via the producer, and it seems that everything is fine. No Exception is thrown or anything. But when trying to take a look into the queue with JMSBrowser, the program has massiv problems displaying the message. Also a self written program can't really get every information. The good point is, the messages seem to have arrived at the server/queue, but the "Message ID" as well as the body are empty!

      Please suggest what is wrong with the  program below, I can't see it, and the documentation doesn't helps either, thanks a lot.



      import java.util.HashMap;
      import java.util.Map;
      import org.hornetq.api.core.TransportConfiguration;
      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 Demo {
          public static void main(String[] args) throws Exception {
              Map<String, Object> map = new HashMap<>();
              map.put(TransportConstants.HOST_PROP_NAME, "localhost");
              map.put(TransportConstants.PORT_PROP_NAME, 5445);
              TransportConfiguration config = new TransportConfiguration(NettyConnectorFactory.class.getName(), map);
              ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(config);
              ClientSessionFactory factory = locator.createSessionFactory();
              //ClientSessionFactory factory = locator.createSessionFactory(config); // config already in locator, but using this doesn't works either
              ClientSession session = factory.createSession("username", "password", false, true, true, false, 100); // switching the flags does not help
              // session.start(); // only required for consumers per JavaDoc, but behaviour don't changes if uncommented.
              ClientProducer producer = session.createProducer("jms.queue.demo");
              ClientMessage cm = session.createMessage(true);
              cm.putObjectProperty("hello_world", "testproperty");
              cm.getBodyBuffer().writeString("message should have a text body"); // body is still null
              /* I also tried this, but this creates a "java.lang.OutOfMemoryError: Java heap space" when trying to consume
              if (StringUtils.isNotBlank(msg.getBody())) {
                  ByteArrayInputStream bais = new ByteArrayInputStream(msg.getBody().getBytes(JmsCliCharsets.UTF8));
              // session.commit(); // doesn't helps either