4 Replies Latest reply on Mar 20, 2014 11:52 AM by Jesus Gabriel y Galan

    Empty body consuming messages via Stomp

    Jesus Gabriel y Galan Newbie

      Hi,

       

      I am trying to setup the following: I have a producer in Java using the Core API, and I'd like to have a Stomp client in Ruby, to have the logstash stomp plugin consuming from HornetQ. Logstash has a Stomp plugin that uses the OnStomp ruby client.

      This is the relevant code of the producer:

       

              Map<String, Object> props = newHashMap();
              props.put("host", "localhost");
              props.put("port", "5445");
              ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), props));
              ClientSessionFactory sf = null;
              ClientSession session = null;
              ClientProducer producer = null;
              try {
                  sf = serverLocator.createSessionFactory();
                  session = sf.createSession();
                  producer = session.createProducer("testaddress");
                  ClientMessage message = session.createMessage(true);
                  message.putStringProperty("type", "testLog");
                  message.getBodyBuffer().writeString("test from java");
                  producer.send(message);

              } finally {
                  producer.close();
                  session.close();
                  sf.close();
                  serverLocator.close();
              }

       

      And here is the consumer:

       

      require 'onstomp'

       

      client = OnStomp::Client.new("stomp://localhost:5445", :login => "guest", :passcode => "guest")
      client.connect
      client.subscribe("test") do |msg|
          p msg
          puts "Body: #{msg.body}"
      end

       

      gets
      client.close

       

      I run the producer to generate 1 message in the queue. Then I run the client:

       

      #<OnStomp::Components::Frame:0x0000000185af38 @command="MESSAGE", @headers=#<OnStomp::Components::FrameHeaders:0x0000000185aee8 @values={:subscription=>["1"], :"message-id"=>["988093"], :destination=>["testaddress"], :expires=>["0"], :redelivered=>["false"], :priority=>["4"], :timestamp=>["1395163541751"], :type=>["testLog"]}>, @body="">
      Body:

       

      As you can see the body is empty. Trying with the Stomp ruby client, instead of OnStomp, I get a little bit more info:

       

      #<Stomp::Message:0x000000012ae210 @command="MESSAGE", @headers={"subscription"=>"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", "message-id"=>"988082", "destination"=>"testaddress", "expires"=>"0", "redelivered"=>"false", "priority"=>"4", "timestamp"=>"1395163068430", "type"=>"testLog"}, @body="", @original="MESSAGE\nsubscription:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\nmessage-id:988082\ndestination:testaddress\nexpires:0\nredelivered:false\npriority:4\ntimestamp:1395163068430\ntype:testLog\n\n\u0000">

       

      As you see there's a \u0000 after the Stomp headers.

       

      So, is there a way to have the body correctly generated from HornetQ Core API to the Stomp interface? Am i doing anything wrong?

       

      Thanks,

       

      Jesus.