You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by cnadukula <cn...@gmail.com> on 2018/03/15 18:05:26 UTC

Removing values appended by Artemis in message body when doing a message copy in Interceptor

hi ,

I am trying to intercept a message in Artemis using my own interceptor code,
but when i intercept the message a i make a copy of the message so the
consumer still receives the actual message on the other end of Artemis.

i make a copy as follows:

*if (packet instanceof SessionSendMessage) {
                SessionSendMessage realPacket = (SessionSendMessage) packet;
                Message msg = realPacket.getMessage();
                Message msgCopy = msg.copy();
                ByteBufInputStream inputStream = new
ByteBufInputStream(msg.getBuffer());
                String output = inputStream.readLine();
                inputStream.close();*

Now after i made a copy of the message and put it in a stream, the string
returned should a json string of the payload sent by the producer. But the
"*String output*" has some Artemis Appended values(at least that is what i
think) in the beginning and ending of the string 

Sample is :

Beginning of the String - êØ{"companyId":"4711"
Ending of the string - 123"}}]}aesôŽ1 (Yè›Sj0þßÜ

how do i get the pure raw message body instead of these garbage values
appended to it?

P.S: the message at the end, near the consumer is totally fine, but the
interceptor is the one that has this issue.

Please advise ASAP.

Thank you,
Chandra



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Removing values appended by Artemis in message body when doing a message copy in Interceptor

Posted by Justin Bertram <jb...@apache.org>.
If you invoke getBuffer() on org.apache.activemq.artemis.api.core.Message
that's going to give you the whole message buffer (i.e. all headers,
properties, internal stuff, etc.).  I think what you want is just the
"body" of the message so you should cast the message to
org.apache.activemq.artemis.api.core.ICoreMessage and invoke
getReadOnlyBodyBuffer().  I think that will also eliminate any need to copy
the message (which is quite costly).


Justin

On Mon, Mar 19, 2018 at 9:23 AM, cnadukula <cn...@gmail.com> wrote:

> hi guys , any update for me on this?
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>

Re: Removing values appended by Artemis in message body when doing a message copy in Interceptor

Posted by cnadukula <cn...@gmail.com>.
hi guys , any update for me on this?



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Removing values appended by Artemis in message body when doing a message copy in Interceptor

Posted by cnadukula <cn...@gmail.com>.
hi Justin,

I am using version - apache-artemis-2.4.0. and for the Java dependency i am
importing "*org.apache.activemq:artemis-core-client:2.2.0*"

<http://activemq.2283324.n4.nabble.com/file/t378513/Screen_Shot_2018-03-15_at_8.png> 

as you can see above the, Packet which is cast to the type
SessionSendMessage has a getMessage() implementation which has the return
Type of the implementation of the Interface ICoreMessage
When in my IntelliJ i click to navigate to where the implementation is it
takes me to the below class. 

import org.apache.activemq.artemis.api.core.ICoreMessage;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;

public abstract class MessagePacket extends PacketImpl implements
MessagePacketI {

   protected ICoreMessage message;

   public MessagePacket(final byte type, final ICoreMessage message) {
      super(type);

      this.message = message;
   }

   @Override
   public ICoreMessage getMessage() {
      return message;
   }

   @Override
   public String getParentString() {
      return super.getParentString() + ", message=" + message;
   }

}

The interface ICoreMessage has multiple implementations as seen below

<http://activemq.2283324.n4.nabble.com/file/t378513/Screen_Shot_2018-03-15_at_8.png> 


Now the copy Method is being picked up from one of the two implementations
(ClientMessageImpl or CoreMessage) as shown below

<http://activemq.2283324.n4.nabble.com/file/t378513/Screen_Shot_2018-03-15_at_9.png> 

The getBuffer() method is in CoreMessage implementation, whose return type
is ByteBuf (io.netty.buffer.ByteBuf)

Please let me know if i missed any details or if am wrong. 

Thanks,
Chandra



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Removing values appended by Artemis in message body when doing a message copy in Interceptor

Posted by Justin Bertram <jb...@apache.org>.
What version of Artemis are you using?  It looks like 1.x.  However, even
in 1.x the org.apache.activemq.artemis.api.core.Message interface (which is
what is returned by
org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage.getMessage())
doesn't have a method named copy() or getBuffer().  Please clarify exactly
what you're doing.


Justin

On Thu, Mar 15, 2018 at 1:05 PM, cnadukula <cn...@gmail.com> wrote:

> hi ,
>
> I am trying to intercept a message in Artemis using my own interceptor
> code,
> but when i intercept the message a i make a copy of the message so the
> consumer still receives the actual message on the other end of Artemis.
>
> i make a copy as follows:
>
> *if (packet instanceof SessionSendMessage) {
>                 SessionSendMessage realPacket = (SessionSendMessage)
> packet;
>                 Message msg = realPacket.getMessage();
>                 Message msgCopy = msg.copy();
>                 ByteBufInputStream inputStream = new
> ByteBufInputStream(msg.getBuffer());
>                 String output = inputStream.readLine();
>                 inputStream.close();*
>
> Now after i made a copy of the message and put it in a stream, the string
> returned should a json string of the payload sent by the producer. But the
> "*String output*" has some Artemis Appended values(at least that is what i
> think) in the beginning and ending of the string
>
> Sample is :
>
> Beginning of the String - êØ{"companyId":"4711"
> Ending of the string - 123"}}]}aesôŽ1 (Yè›Sj0þßÜ
>
> how do i get the pure raw message body instead of these garbage values
> appended to it?
>
> P.S: the message at the end, near the consumer is totally fine, but the
> interceptor is the one that has this issue.
>
> Please advise ASAP.
>
> Thank you,
> Chandra
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>