ActiveMQ Object Message to json transformation not working

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

ActiveMQ Object Message to json transformation not working

xabhi
Hi,

I am having trouble sending a custom Object Message to a STOMP consumer with ActiveMQ v5.11.1

In Jconsole, I can see messages being dequeued by STOMP consumer but the subscription callback is never called.

However note that if I send a simple string as object message it gets processed by STOMP consumer and I receive a JSON formatted message in this format:
{"string":"hello"}

I create the message as follows:
myMessage = mySession.createObjectMessage("hello");
myProducers.get(destName).send(myMessage);

I am not sure what am i doing wrong here. Could anyone tell what is wrong with this code?



Object Message class:
    public static class SampleObjectMessage implements Serializable
    {
        private static final long serialVersionUID = 1L;
        public String data;
        public long sendTimeMs;
        public SampleObjectMessage(String data, long sendTimeMs) {
            this.data = data;
            this.sendTimeMs = sendTimeMs;
        }
        public String getData() {
            return data;
        }
        public void setData(String data) {
            this.data = data;
        }
        public long getSendTimeMs() {
            return sendTimeMs;
        }
        public void setSendTimeMs(long sendTimeMs) {
            this.sendTimeMs = sendTimeMs;
        }
    }


Code for sending ObjectMessage:
myMessage = mySession.createObjectMessage(
                     new SampleObjectMessage(getMessageText(ourMessageSize),
                                             System.currentTimeMillis()));

myProducers.get(destName).send(myMessage);



STOMP consumer has following headers for subscription:

var subscriptionHeaders = {
  'ack'         : 'auto',
  'transformation' : 'jms-object-json'
};


Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

tabish121@gmail.com
On 03/16/2016 01:38 AM, xabhi wrote:

> Hi,
>
> I am having trouble sending a custom Object Message to a STOMP consumer with
> ActiveMQ v5.11.1
>
> In Jconsole, I can see messages being dequeued by STOMP consumer but the
> subscription callback is never called.
>
> However note that if I send a simple string as object message it gets
> processed by STOMP consumer and I receive a JSON formatted message in this
> format:
> {"string":"hello"}
>
> I create the message as follows:
> myMessage = mySession.createObjectMessage("hello");
> myProducers.get(destName).send(myMessage);
>
> I am not sure what am i doing wrong here. Could anyone tell what is wrong
> with this code?
>
>
>
> Object Message class:
>      public static class SampleObjectMessage implements Serializable
>      {
>          private static final long serialVersionUID = 1L;
>          public String data;
>          public long sendTimeMs;
>          public SampleObjectMessage(String data, long sendTimeMs) {
>              this.data = data;
>              this.sendTimeMs = sendTimeMs;
>          }
>          public String getData() {
>              return data;
>          }
>          public void setData(String data) {
>              this.data = data;
>          }
>          public long getSendTimeMs() {
>              return sendTimeMs;
>          }
>          public void setSendTimeMs(long sendTimeMs) {
>              this.sendTimeMs = sendTimeMs;
>          }
>      }
>
>
> Code for sending ObjectMessage:
> myMessage = mySession.createObjectMessage(
>                       new SampleObjectMessage(getMessageText(ourMessageSize),
>                                               System.currentTimeMillis()));
>
> myProducers.get(destName).send(myMessage);
>
>
>
> STOMP consumer has following headers for subscription:
>
> var subscriptionHeaders = {
>    'ack'         : 'auto',
>    'transformation' : 'jms-object-json'
> };
>
>
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-Object-Message-to-json-transformation-not-working-tp4709447.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Is the class you are sending also available broker side to be
deserialized?  Did you check the broker logs to see if any information
there clues you in to what is going on?

--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/

Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

xabhi
How do I make sure that this class is available at broker side?
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

James A. Robinson-2
I think what it boils down to is figuring out where you need to put the jar
to make it available to the class loader in the java instance that is
running your broker.

So, for example, on my Linux setup I have a directory

/usr/share/activemq/lib

that contains the jars needed to run ActiveMQ and I could place a jar there
if I needed to add new deserialization classes.

In my particular case I've got this running under a tanukiwrapper, and
another option is to add a new directory to the
/etc/activemq/activemq-wrapper.conf that points to a new jar directory.
E.g., extending this block of configuration:

# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
set.default.ACTIVEMQ_HOME=/usr/share/activemq
wrapper.java.classpath.1=/usr/share/java/tanukiwrapper.jar
wrapper.java.classpath.2=%ACTIVEMQ_HOME%/lib/*
wrapper.java.classpath.3=%ACTIVEMQ_HOME%/lib/web/*
wrapper.java.classpath.4=%ACTIVEMQ_HOME%/lib/extra/*
wrapper.java.classpath.5=%ACTIVEMQ_HOME%/lib/optional/*
wrapper.java.classpath.6=%ACTIVEMQ_HOME%/lib/camel/*


Jim


On Wed, Mar 30, 2016 at 11:54 PM xabhi <[hidden email]> wrote:

> How do I make sure that this class is available at broker side?
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/ActiveMQ-Object-Message-to-json-transformation-not-working-tp4709447p4710145.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

Tim Bain
I would have assumed that object serialization and deserialization would
either both happen on the broker or neither happen on the broker, and that
if serialization was going to happen (and fail due to a missing JAR) on the
broker at dispatch time, deserialization would have had to happen at
enqueue time, which would have failed due to a missing JAR.  I'm not seeing
the situation where a missing JAR causes this (though I haven't made any
effort to trace the code); am I missing something?

Tim

On Thu, Mar 31, 2016 at 1:08 AM, James A. Robinson <[hidden email]>
wrote:

> I think what it boils down to is figuring out where you need to put the jar
> to make it available to the class loader in the java instance that is
> running your broker.
>
> So, for example, on my Linux setup I have a directory
>
> /usr/share/activemq/lib
>
> that contains the jars needed to run ActiveMQ and I could place a jar there
> if I needed to add new deserialization classes.
>
> In my particular case I've got this running under a tanukiwrapper, and
> another option is to add a new directory to the
> /etc/activemq/activemq-wrapper.conf that points to a new jar directory.
> E.g., extending this block of configuration:
>
> # Java Classpath (include wrapper.jar) Add class path elements as
> # needed starting from 1
> set.default.ACTIVEMQ_HOME=/usr/share/activemq
> wrapper.java.classpath.1=/usr/share/java/tanukiwrapper.jar
> wrapper.java.classpath.2=%ACTIVEMQ_HOME%/lib/*
> wrapper.java.classpath.3=%ACTIVEMQ_HOME%/lib/web/*
> wrapper.java.classpath.4=%ACTIVEMQ_HOME%/lib/extra/*
> wrapper.java.classpath.5=%ACTIVEMQ_HOME%/lib/optional/*
> wrapper.java.classpath.6=%ACTIVEMQ_HOME%/lib/camel/*
>
>
> Jim
>
>
> On Wed, Mar 30, 2016 at 11:54 PM xabhi <[hidden email]> wrote:
>
> > How do I make sure that this class is available at broker side?
> >
> >
> >
> > --
> > View this message in context:
> >
> http://activemq.2283324.n4.nabble.com/ActiveMQ-Object-Message-to-json-transformation-not-working-tp4709447p4710145.html
> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

James A. Robinson-2
Since he says he can send a generic JSON message, I assume that is without
the "transformation=jms-object-json" message header, the system is properly
mapping JSON to a generic Java Object, right?  If the custom mapping failed
I assumed that would mean the class defined in the
META-INF/services/org/apache/activemq/transport/frametranslator/
mapping was a likely culprit.

Jim

On Fri, Apr 1, 2016 at 7:39 AM Tim Bain <[hidden email]> wrote:

> I would have assumed that object serialization and deserialization would
> either both happen on the broker or neither happen on the broker, and that
> if serialization was going to happen (and fail due to a missing JAR) on the
> broker at dispatch time, deserialization would have had to happen at
> enqueue time, which would have failed due to a missing JAR.  I'm not seeing
> the situation where a missing JAR causes this (though I haven't made any
> effort to trace the code); am I missing something?
>
> Tim
>
> On Thu, Mar 31, 2016 at 1:08 AM, James A. Robinson <[hidden email]>
> wrote:
>
> > I think what it boils down to is figuring out where you need to put the
> jar
> > to make it available to the class loader in the java instance that is
> > running your broker.
> >
> > So, for example, on my Linux setup I have a directory
> >
> > /usr/share/activemq/lib
> >
> > that contains the jars needed to run ActiveMQ and I could place a jar
> there
> > if I needed to add new deserialization classes.
> >
> > In my particular case I've got this running under a tanukiwrapper, and
> > another option is to add a new directory to the
> > /etc/activemq/activemq-wrapper.conf that points to a new jar directory.
> > E.g., extending this block of configuration:
> >
> > # Java Classpath (include wrapper.jar) Add class path elements as
> > # needed starting from 1
> > set.default.ACTIVEMQ_HOME=/usr/share/activemq
> > wrapper.java.classpath.1=/usr/share/java/tanukiwrapper.jar
> > wrapper.java.classpath.2=%ACTIVEMQ_HOME%/lib/*
> > wrapper.java.classpath.3=%ACTIVEMQ_HOME%/lib/web/*
> > wrapper.java.classpath.4=%ACTIVEMQ_HOME%/lib/extra/*
> > wrapper.java.classpath.5=%ACTIVEMQ_HOME%/lib/optional/*
> > wrapper.java.classpath.6=%ACTIVEMQ_HOME%/lib/camel/*
> >
> >
> > Jim
> >
> >
> > On Wed, Mar 30, 2016 at 11:54 PM xabhi <[hidden email]> wrote:
> >
> > > How do I make sure that this class is available at broker side?
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://activemq.2283324.n4.nabble.com/ActiveMQ-Object-Message-to-json-transformation-not-working-tp4709447p4710145.html
> > > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

Tim Bain
Ah, I had assumed (for no good reason, on rereading) that the producer was
also STOMP.  If not, disregard my question.
On Apr 1, 2016 9:01 AM, "James A. Robinson" <[hidden email]> wrote:

> Since he says he can send a generic JSON message, I assume that is without
> the "transformation=jms-object-json" message header, the system is properly
> mapping JSON to a generic Java Object, right?  If the custom mapping failed
> I assumed that would mean the class defined in the
> META-INF/services/org/apache/activemq/transport/frametranslator/
> mapping was a likely culprit.
>
> Jim
>
> On Fri, Apr 1, 2016 at 7:39 AM Tim Bain <[hidden email]> wrote:
>
> > I would have assumed that object serialization and deserialization would
> > either both happen on the broker or neither happen on the broker, and
> that
> > if serialization was going to happen (and fail due to a missing JAR) on
> the
> > broker at dispatch time, deserialization would have had to happen at
> > enqueue time, which would have failed due to a missing JAR.  I'm not
> seeing
> > the situation where a missing JAR causes this (though I haven't made any
> > effort to trace the code); am I missing something?
> >
> > Tim
> >
> > On Thu, Mar 31, 2016 at 1:08 AM, James A. Robinson <[hidden email]>
> > wrote:
> >
> > > I think what it boils down to is figuring out where you need to put the
> > jar
> > > to make it available to the class loader in the java instance that is
> > > running your broker.
> > >
> > > So, for example, on my Linux setup I have a directory
> > >
> > > /usr/share/activemq/lib
> > >
> > > that contains the jars needed to run ActiveMQ and I could place a jar
> > there
> > > if I needed to add new deserialization classes.
> > >
> > > In my particular case I've got this running under a tanukiwrapper, and
> > > another option is to add a new directory to the
> > > /etc/activemq/activemq-wrapper.conf that points to a new jar directory.
> > > E.g., extending this block of configuration:
> > >
> > > # Java Classpath (include wrapper.jar) Add class path elements as
> > > # needed starting from 1
> > > set.default.ACTIVEMQ_HOME=/usr/share/activemq
> > > wrapper.java.classpath.1=/usr/share/java/tanukiwrapper.jar
> > > wrapper.java.classpath.2=%ACTIVEMQ_HOME%/lib/*
> > > wrapper.java.classpath.3=%ACTIVEMQ_HOME%/lib/web/*
> > > wrapper.java.classpath.4=%ACTIVEMQ_HOME%/lib/extra/*
> > > wrapper.java.classpath.5=%ACTIVEMQ_HOME%/lib/optional/*
> > > wrapper.java.classpath.6=%ACTIVEMQ_HOME%/lib/camel/*
> > >
> > >
> > > Jim
> > >
> > >
> > > On Wed, Mar 30, 2016 at 11:54 PM xabhi <[hidden email]> wrote:
> > >
> > > > How do I make sure that this class is available at broker side?
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context:
> > > >
> > >
> >
> http://activemq.2283324.n4.nabble.com/ActiveMQ-Object-Message-to-json-transformation-not-working-tp4709447p4710145.html
> > > > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> > > >
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ Object Message to json transformation not working

xabhi
A little unrelated question but does using 'transformation' header on STOMP consumer causes throughput drop?

I tested it with jms-map-json transformation and throughput dropped to 200 msgs/s when compared to that simple text messages.

Should i do transformation to text message in my Java application? What will i be losing if i do that because throughput is real concern for me.

I have asked this question here: http://activemq.2283324.n4.nabble.com/JMS-to-STOMP-transformation-causes-throughput-drop-in-STOMP-consumers-td4710148.html

Sorry for asking this question here but nobody replied there.

Any pointers on what could be causing it would help me greatly. Thanks for all the help.