You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by To...@t-systems.com on 2021/03/22 14:52:08 UTC

send message

I try to send and receive a netty ByteBuf message, but it fails.
What I'm doing wrong here? I even don't know ist he mistake in sending or receiving!
I was thinking to use the jms layer, but I'm receiving the data buffer throught a netty buffer and I want to avoid to convert the buffer to a byte array!

       public void sendMessageToSmtpQueue(ByteBuf buf) throws ActiveMQException {
             ClientSession session = this.sessionFactory.createSession();
             try {
                    session.start();
                    ClientMessage message = session.createMessage(true);
                    message.getBodyBuffer().writeBytes(buf, 0, buf.readableBytes());
                    ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
                    producer.send(message);
             } finally {
                    session.close();
             }
       }

       public ActiveMQBuffer receiveMessageFromSmtpQueue() throws ActiveMQException {
             ActiveMQBuffer result;
             ClientSession session = this.sessionFactory.createSession();
             try {
                    session.start();
                    ClientConsumer consumer = session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
                    ClientMessage message = consumer.receive();
                    result = ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
                    message.getBodyBuffer().readBytes(result);
             } finally {
                    session.close();
             }

             return result;
       }


       public void startServer() throws Exception {
             this.configuration = new ConfigurationImpl();
             this.configuration.addAcceptorConfiguration("in-vm", ACTIVE_MQ_EMBEDDED_SERVER_URL);
             this.configuration.setPersistenceEnabled(true);
             this.configuration.setSecurityEnabled(false);
             this.configuration.addQueueConfiguration(new QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));

             this.server = new ActiveMQServerImpl(this.configuration);
             this.server.start();
       }

AW: send message

Posted by To...@t-systems.com.
When I send/receive I ByteBuf Message my test fails saying the input/output is not equal!

	public void sendMessageToSmtpQueue(ByteBuf buf) throws ActiveMQException {
		ClientSession session = this.sessionFactory.createSession();
		try {
			session.start();
			ClientMessage message = session.createMessage(true);
			message.getBodyBuffer().writeBytes(buf, 0, buf.readableBytes());
			ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
			producer.send(message);
		} finally {
			session.close();
		}
	}
	public ActiveMQBuffer receiveMessageFromSmtpQueue() throws ActiveMQException {
		ActiveMQBuffer result;
		ClientSession session = this.sessionFactory.createSession();
		try {
			session.start();
			ClientConsumer consumer = session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
			ClientMessage message = consumer.receive();
			result = ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
			message.getBodyBuffer().readBytes(result);
		} finally {
			session.close();
		}

		return result;
	}

-----Ursprüngliche Nachricht-----
Von: Justin Bertram <jb...@apache.org> 
Gesendet: Montag, 22. März 2021 16:34
An: users@activemq.apache.org
Betreff: Re: send message

What actually fails? Do you have a stack-trace?


Justin

On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:

> I try to send and receive a netty ByteBuf message, but it fails.
> What I'm doing wrong here? I even don't know ist he mistake in sending 
> or receiving!
> I was thinking to use the jms layer, but I'm receiving the data buffer 
> throught a netty buffer and I want to avoid to convert the buffer to a 
> byte array!
>
>        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> ActiveMQException {
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientMessage message = session.createMessage(true);
>                     message.getBodyBuffer().writeBytes(buf, 0, 
> buf.readableBytes());
>                     ClientProducer producer = 
> session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
>                     producer.send(message);
>              } finally {
>                     session.close();
>              }
>        }
>
>        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
> ActiveMQException {
>              ActiveMQBuffer result;
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientConsumer consumer = 
> session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
>                     ClientMessage message = consumer.receive();
>                     result =
> ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
>                     message.getBodyBuffer().readBytes(result);
>              } finally {
>                     session.close();
>              }
>
>              return result;
>        }
>
>
>        public void startServer() throws Exception {
>              this.configuration = new ConfigurationImpl();
>              this.configuration.addAcceptorConfiguration("in-vm",
> ACTIVE_MQ_EMBEDDED_SERVER_URL);
>              this.configuration.setPersistenceEnabled(true);
>              this.configuration.setSecurityEnabled(false);
>              this.configuration.addQueueConfiguration(new
> QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
>
>              this.server = new ActiveMQServerImpl(this.configuration);
>              this.server.start();
>        }
>

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
I tried this, and it works:

https://github.com/apache/activemq-artemis/blob/89ea4ecda760918cd8da82b2f1f2af26c1e5f91e/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/MessageBufferTest.java#L92-L135


I can't figure out what you did wrong.

On Tue, Mar 23, 2021 at 9:59 AM Clebert Suconic
<cl...@gmail.com> wrote:
>
> You were supposed to call reset right before sending though... but I
> did not need it on my test.. I will post a link...
>
> Anyway, if you use the JMS API, the JMS layer is very thin, and I
> don't think it would affect your performance in any way. you could
> create a BytesMessage and all the detail would be hidden away from the
> internal API.
>
> On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic
> <cl...@gmail.com> wrote:
> >
> > I'm adding a test doing exactly what you did, and it's working...
> >
> > give me 10 minutes and I will post a link here...
> >
> > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > >
> > > Same Issue!
> > >         public void sendMessageToSmtpQueue(String text) throws ActiveMQException {
> > >                 ClientSession session = this.sessionFactory.createSession();
> > >                 try {
> > >                         session.start();
> > >                         ClientMessage message = session.createMessage(true);
> > >                         message.setType(ClientMessage.TEXT_TYPE);
> > >                         message.getBodyBuffer().resetReaderIndex();
> > >                         message.getBodyBuffer().writeString(text);
> > >                         ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > >                         producer.send(message);
> > >                 } finally {
> > >                         session.close();
> > >                 }
> > >         }
> > >
> > > java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
> > >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > >         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > >         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > >         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > >         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > >         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > >         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > >         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > >         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
> > >
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Dienstag, 23. März 2021 13:48
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?
> > >
> > > if that does not work I will try your code and see what happens. (Let me know if doesn't please)
> > >
> > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
> > > >
> > > > maybe take inspiration from
> > > > https://github.com/apache/activemq-artemis/blob/master/tests/integrati
> > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integration/c
> > > > lient/MessageBufferTest.java that passes a string, but there are
> > > > corresponding byte[] or buffer variants in the api. If you want to
> > > > skip the decoding, to access the raw buffer, you need to parse the
> > > > type to get to the appropriate part of the buffer.
> > > > There are loads of usage examples in the tests and they all work,
> > > > start there and break it as you go.
> > > >
> > > > the issue is the wire level encoding that the client does, the JMS api
> > > > hides this, as do the typed accessors, but you can get direct access
> > > > to the encoded buffers via the core api as you are doing but you need
> > > > to be type aware, for example a string can be utf-8 encoded or it can
> > > > be raw bytes on the wire, depending on the size and chars, the
> > > > encoding handles and hides this detail. But if you go for direct
> > > > access, you need to be aware of the encoding.
> > > >
> > > >
> > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > >
> > > > > getDataBuffer gives same result! Already tried!
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Why you don't use the JMS API for this?
> > > > >
> > > > > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > >
> > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > > > > >
> > > > > > The stack-trace indicates you're invoking the "readString" method
> > > > > > on line
> > > > > > 93 of MailServerActiveMQClient.java, but I don't see that call in
> > > > > > the code you pasted. Therefore, that stack-trace doesn't seem
> > > > > > correct. Can you clarify this?
> > > > > >
> > > > > >
> > > > > > Justin
> > > > > >
> > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > <er...@cgi.com>
> > > > > > wrote:
> > > > > >
> > > > > > > Fyi:
> > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text)
> > > > > > > And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > e.
> > > > > > >
> > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > Aan: users@activemq.apache.org
> > > > > > > Onderwerp: AW: send message
> > > > > > >
> > > > > > >
> > > > > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > > > > you trust the sender and know the content is safe.
> > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou
> > > > > > > que vous ayez l'assurance que le contenu provient d'une source sûre.
> > > > > > >
> > > > > > > While sending / receiving a text message I get this
> > > > > > >
> > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > simpleString,
> > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(
> > > > > > > Nati
> > > > > > > ve
> > > > > > > Method)
> > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > >         at
> > > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > >         at
> > > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > >         at
> > > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > >         at
> > > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > >         at
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > >         at
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > > > > teTe
> > > > > > > stRunner.java:209)
> > > > > > >
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > >
> > > > > > >
> > > > > > > Justin
> > > > > > >
> > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > > > > What I'm doing wrong here? I even don't know ist he mistake in
> > > > > > > > sending or receiving!
> > > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > > convert the buffer to a byte array!
> > > > > > > >
> > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > > > > > > > ActiveMQException {
> > > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > > >              try {
> > > > > > > >                     session.start();
> > > > > > > >                     ClientMessage message = session.createMessage(true);
> > > > > > > >                     message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > > > buf.readableBytes());
> > > > > > > >                     ClientProducer producer =
> > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > >                     producer.send(message);
> > > > > > > >              } finally {
> > > > > > > >                     session.close();
> > > > > > > >              }
> > > > > > > >        }
> > > > > > > >
> > > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > > throws ActiveMQException {
> > > > > > > >              ActiveMQBuffer result;
> > > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > > >              try {
> > > > > > > >                     session.start();
> > > > > > > >                     ClientConsumer consumer =
> > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > >                     ClientMessage message = consumer.receive();
> > > > > > > >                     result =
> > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > >                     message.getBodyBuffer().readBytes(result);
> > > > > > > >              } finally {
> > > > > > > >                     session.close();
> > > > > > > >              }
> > > > > > > >
> > > > > > > >              return result;
> > > > > > > >        }
> > > > > > > >
> > > > > > > >
> > > > > > > >        public void startServer() throws Exception {
> > > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > > >
> > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > >              this.configuration.setPersistenceEnabled(true);
> > > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > >
> > > > > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > > > > >              this.server.start();
> > > > > > > >        }
> > > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
If you do it soon, it should be ready for next 2.18.0.. that I'm
considering sending a HEADS up on dev list for next week, or 2 weeks
from now depending on another task I am working on.

BTW: I meant add the method into ActiveMQBytesMessage into my previous
email, but you probably guessed that.

On Wed, Mar 24, 2021 at 12:53 PM Clebert Suconic
<cl...@gmail.com> wrote:
>
> I have two suggestions for you:
>
> - Why you don't cast BytesMessage, access the internal message on the
> BytesMessage, and add the NettyBuffer directly
>
>
> - Or Even better, why you don't you:
> *  add a new method on BytesMessage, such as writeBytes(NettyBuffer)
> * add a simple test
> * when you want to use that version you do
> ((ActiveMQBytesMessage)message).writeBytes(yourNettyBuffer);
>
> Create a JIRA And send a PR?
>
> I will expedite the merge of your PR personally.. and you would have a
> stable API for it, and you would be contributing to the community to
> the same case you need now?
>
>
> On Wed, Mar 24, 2021 at 8:11 AM Clebert Suconic
> <cl...@gmail.com> wrote:
> >
> > +1, and he does not need a String. He could use a BytesMessage.
> >
> > On Wed, Mar 24, 2021 at 8:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
> > >
> > > One thing to keep in mind is that although the code may be slightly slower,
> > > if it lets you use an API that is more favorable (which might mean better
> > > documented, more portable, more stable across future versions, easier for
> > > others to maintain because they're already familiar with it, or a number of
> > > other potential advantages), that might be a win.
> > >
> > > Only you know your use case and whether the performance advantages of what
> > > you're trying to do actually outweigh the types of advantages I referenced
> > > in the first paragraph. But remember that premature optimization is the
> > > root of all evil, so make sure that your micro-optimization of avoiding the
> > > creation of a String is really a significant enough optimization in the
> > > context of your use case to justify the disadvantages of what you're trying
> > > to do.
> > >
> > > Tim
> > >
> > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic <cl...@gmail.com>
> > > wrote:
> > >
> > > > Not on the API itself.
> > > >
> > > > Try the core api example I sent you... and let me know what is
> > > > different from yours.
> > > >
> > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > I want to use the jms layer, but I've a netty application and I want to
> > > > write the ByteBuf mostly efficent to the queue.
> > > > > I think it makes no sense to convert it back from a native buffer into a
> > > > byte array or stream and tunnel this throught the jvm!
> > > > >
> > > > > Is there a way to use a ByteBuf with jms?
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > You were supposed to call reset right before sending though... but I did
> > > > not need it on my test.. I will post a link...
> > > > >
> > > > > Anyway, if you use the JMS API, the JMS layer is very thin, and I don't
> > > > think it would affect your performance in any way. you could create a
> > > > BytesMessage and all the detail would be hidden away from the internal API.
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > clebert.suconic@gmail.com> wrote:
> > > > > >
> > > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > > >
> > > > > > give me 10 minutes and I will post a link here...
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > Same Issue!
> > > > > > >         public void sendMessageToSmtpQueue(String text) throws
> > > > ActiveMQException {
> > > > > > >                 ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > >                 try {
> > > > > > >                         session.start();
> > > > > > >                         ClientMessage message =
> > > > session.createMessage(true);
> > > > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > > > >                         message.getBodyBuffer().writeString(text);
> > > > > > >                         ClientProducer producer =
> > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                         producer.send(message);
> > > > > > >                 } finally {
> > > > > > >                         session.close();
> > > > > > >                 }
> > > > > > >         }
> > > > > > >
> > > > > > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > > > length=1953068645 is greater than readableBytes=3
> > > > > > >         at
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > >         at
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > >         at
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > >         at
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > > > > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > Method)
> > > > > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > >         at
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > >         at
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > >         at
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > >         at
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > >         at
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > >         at
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > >         at
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > >         at
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > > > stRunner.java:209)
> > > > > > >
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Can you try calling message.getBodyBuffer().resetReaderIndex();
> > > > before the send?
> > > > > > >
> > > > > > > if that does not work I will try your code and see what happens.
> > > > > > > (Let me know if doesn't please)
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com>
> > > > wrote:
> > > > > > > >
> > > > > > > > maybe take inspiration from
> > > > > > > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > > rati
> > > > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > > on/c lient/MessageBufferTest.java that passes a string, but there
> > > > > > > > are corresponding byte[] or buffer variants in the api. If you
> > > > > > > > want to skip the decoding, to access the raw buffer, you need to
> > > > > > > > parse the type to get to the appropriate part of the buffer.
> > > > > > > > There are loads of usage examples in the tests and they all work,
> > > > > > > > start there and break it as you go.
> > > > > > > >
> > > > > > > > the issue is the wire level encoding that the client does, the JMS
> > > > > > > > api hides this, as do the typed accessors, but you can get direct
> > > > > > > > access to the encoded buffers via the core api as you are doing
> > > > > > > > but you need to be type aware, for example a string can be utf-8
> > > > > > > > encoded or it can be raw bytes on the wire, depending on the size
> > > > > > > > and chars, the encoding handles and hides this detail. But if you
> > > > > > > > go for direct access, you need to be aware of the encoding.
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > > > >
> > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > >
> > > > > > > > > or if you really want to use the core API, use the
> > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > jbertram@apache.org> wrote:
> > > > > > > > > >
> > > > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > > > method on line
> > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see that call
> > > > > > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > > > > > seem correct. Can you clarify this?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > > Fyi:
> > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii
> > > > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > > > e.
> > > > > > > > > > >
> > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > attachments unless
> > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez
> > > > aucune pièce
> > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable,
> > > > > > > > > > > ou que vous ayez l'assurance que le contenu provient d'une
> > > > source sûre.
> > > > > > > > > > >
> > > > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > > > >
> > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > > > simpleString,
> > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > >
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > >
> > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > > > > > >         at
> > > > > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > ke0(
> > > > > > > > > > > Nati
> > > > > > > > > > > ve
> > > > > > > > > > > Method)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > > > > > >         at
> > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > > > > > >         at
> > > > > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > Remo
> > > > > > > > > > > teTe
> > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > >
> > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Justin
> > > > > > > > > > >
> > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com>
> > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > > I try to send and receive a netty ByteBuf message, but it
> > > > fails.
> > > > > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > >
> > > > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > >              ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > > > > > > >              try {
> > > > > > > > > > > >                     session.start();
> > > > > > > > > > > >                     ClientMessage message =
> > > > session.createMessage(true);
> > > > > > > > > > > >
> > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > buf.readableBytes());
> > > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > >              } finally {
> > > > > > > > > > > >                     session.close();
> > > > > > > > > > > >              }
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > >              ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > > > > > > >              try {
> > > > > > > > > > > >                     session.start();
> > > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                     ClientMessage message =
> > > > consumer.receive();
> > > > > > > > > > > >                     result =
> > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > > > > > >
> > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > >              } finally {
> > > > > > > > > > > >                     session.close();
> > > > > > > > > > > >              }
> > > > > > > > > > > >
> > > > > > > > > > > >              return result;
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > > > > > > >
> > > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > >
> > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > >
> > > > > > > > > > > >              this.server = new
> > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > > >
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
I have two suggestions for you:

- Why you don't cast BytesMessage, access the internal message on the
BytesMessage, and add the NettyBuffer directly


- Or Even better, why you don't you:
*  add a new method on BytesMessage, such as writeBytes(NettyBuffer)
* add a simple test
* when you want to use that version you do
((ActiveMQBytesMessage)message).writeBytes(yourNettyBuffer);

Create a JIRA And send a PR?

I will expedite the merge of your PR personally.. and you would have a
stable API for it, and you would be contributing to the community to
the same case you need now?


On Wed, Mar 24, 2021 at 8:11 AM Clebert Suconic
<cl...@gmail.com> wrote:
>
> +1, and he does not need a String. He could use a BytesMessage.
>
> On Wed, Mar 24, 2021 at 8:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
> >
> > One thing to keep in mind is that although the code may be slightly slower,
> > if it lets you use an API that is more favorable (which might mean better
> > documented, more portable, more stable across future versions, easier for
> > others to maintain because they're already familiar with it, or a number of
> > other potential advantages), that might be a win.
> >
> > Only you know your use case and whether the performance advantages of what
> > you're trying to do actually outweigh the types of advantages I referenced
> > in the first paragraph. But remember that premature optimization is the
> > root of all evil, so make sure that your micro-optimization of avoiding the
> > creation of a String is really a significant enough optimization in the
> > context of your use case to justify the disadvantages of what you're trying
> > to do.
> >
> > Tim
> >
> > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic <cl...@gmail.com>
> > wrote:
> >
> > > Not on the API itself.
> > >
> > > Try the core api example I sent you... and let me know what is
> > > different from yours.
> > >
> > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > >
> > > > I want to use the jms layer, but I've a netty application and I want to
> > > write the ByteBuf mostly efficent to the queue.
> > > > I think it makes no sense to convert it back from a native buffer into a
> > > byte array or stream and tunnel this throught the jvm!
> > > >
> > > > Is there a way to use a ByteBuf with jms?
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > You were supposed to call reset right before sending though... but I did
> > > not need it on my test.. I will post a link...
> > > >
> > > > Anyway, if you use the JMS API, the JMS layer is very thin, and I don't
> > > think it would affect your performance in any way. you could create a
> > > BytesMessage and all the detail would be hidden away from the internal API.
> > > >
> > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > clebert.suconic@gmail.com> wrote:
> > > > >
> > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > >
> > > > > give me 10 minutes and I will post a link here...
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > Same Issue!
> > > > > >         public void sendMessageToSmtpQueue(String text) throws
> > > ActiveMQException {
> > > > > >                 ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > >                 try {
> > > > > >                         session.start();
> > > > > >                         ClientMessage message =
> > > session.createMessage(true);
> > > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > > >                         message.getBodyBuffer().writeString(text);
> > > > > >                         ClientProducer producer =
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > >                         producer.send(message);
> > > > > >                 } finally {
> > > > > >                         session.close();
> > > > > >                 }
> > > > > >         }
> > > > > >
> > > > > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > > length=1953068645 is greater than readableBytes=3
> > > > > >         at
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > >         at
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > >         at
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > >         at
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > > > > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > > > > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > >         at
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > >         at
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > >         at
> > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > >         at
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > >         at
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > >         at
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > >         at
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > >         at
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > >         at
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > > stRunner.java:209)
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Can you try calling message.getBodyBuffer().resetReaderIndex();
> > > before the send?
> > > > > >
> > > > > > if that does not work I will try your code and see what happens.
> > > > > > (Let me know if doesn't please)
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com>
> > > wrote:
> > > > > > >
> > > > > > > maybe take inspiration from
> > > > > > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > rati
> > > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > on/c lient/MessageBufferTest.java that passes a string, but there
> > > > > > > are corresponding byte[] or buffer variants in the api. If you
> > > > > > > want to skip the decoding, to access the raw buffer, you need to
> > > > > > > parse the type to get to the appropriate part of the buffer.
> > > > > > > There are loads of usage examples in the tests and they all work,
> > > > > > > start there and break it as you go.
> > > > > > >
> > > > > > > the issue is the wire level encoding that the client does, the JMS
> > > > > > > api hides this, as do the typed accessors, but you can get direct
> > > > > > > access to the encoded buffers via the core api as you are doing
> > > > > > > but you need to be type aware, for example a string can be utf-8
> > > > > > > encoded or it can be raw bytes on the wire, depending on the size
> > > > > > > and chars, the encoding handles and hides this detail. But if you
> > > > > > > go for direct access, you need to be aware of the encoding.
> > > > > > >
> > > > > > >
> > > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > > >
> > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > Why you don't use the JMS API for this?
> > > > > > > >
> > > > > > > > or if you really want to use the core API, use the
> > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > jbertram@apache.org> wrote:
> > > > > > > > >
> > > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > > method on line
> > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see that call
> > > > > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > > > > seem correct. Can you clarify this?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > <er...@cgi.com>
> > > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > > Fyi:
> > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii
> > > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > > e.
> > > > > > > > > >
> > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > attachments unless
> > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez
> > > aucune pièce
> > > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable,
> > > > > > > > > > ou que vous ayez l'assurance que le contenu provient d'une
> > > source sûre.
> > > > > > > > > >
> > > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > > >
> > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > > simpleString,
> > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > > > > >         at
> > > > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > ke0(
> > > > > > > > > > Nati
> > > > > > > > > > ve
> > > > > > > > > > Method)
> > > > > > > > > >         at
> > > > > > > > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > > > > >         at
> > > > > > > > > >
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > > > > >         at
> > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > > > > >         at
> > > > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > Remo
> > > > > > > > > > teTe
> > > > > > > > > > stRunner.java:209)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com>
> > > wrote:
> > > > > > > > > >
> > > > > > > > > > > I try to send and receive a netty ByteBuf message, but it
> > > fails.
> > > > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > >
> > > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientMessage message =
> > > session.createMessage(true);
> > > > > > > > > > >
> > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > buf.readableBytes());
> > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     ClientMessage message =
> > > consumer.receive();
> > > > > > > > > > >                     result =
> > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > > > > >
> > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >
> > > > > > > > > > >              return result;
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > > > > > >
> > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > >
> > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > >
> > > > > > > > > > >              this.server = new
> > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > >              this.server.start();
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> > >
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
+1, and he does not need a String. He could use a BytesMessage.

On Wed, Mar 24, 2021 at 8:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
>
> One thing to keep in mind is that although the code may be slightly slower,
> if it lets you use an API that is more favorable (which might mean better
> documented, more portable, more stable across future versions, easier for
> others to maintain because they're already familiar with it, or a number of
> other potential advantages), that might be a win.
>
> Only you know your use case and whether the performance advantages of what
> you're trying to do actually outweigh the types of advantages I referenced
> in the first paragraph. But remember that premature optimization is the
> root of all evil, so make sure that your micro-optimization of avoiding the
> creation of a String is really a significant enough optimization in the
> context of your use case to justify the disadvantages of what you're trying
> to do.
>
> Tim
>
> On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic <cl...@gmail.com>
> wrote:
>
> > Not on the API itself.
> >
> > Try the core api example I sent you... and let me know what is
> > different from yours.
> >
> > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > >
> > > I want to use the jms layer, but I've a netty application and I want to
> > write the ByteBuf mostly efficent to the queue.
> > > I think it makes no sense to convert it back from a native buffer into a
> > byte array or stream and tunnel this throught the jvm!
> > >
> > > Is there a way to use a ByteBuf with jms?
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Dienstag, 23. März 2021 15:00
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > You were supposed to call reset right before sending though... but I did
> > not need it on my test.. I will post a link...
> > >
> > > Anyway, if you use the JMS API, the JMS layer is very thin, and I don't
> > think it would affect your performance in any way. you could create a
> > BytesMessage and all the detail would be hidden away from the internal API.
> > >
> > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > clebert.suconic@gmail.com> wrote:
> > > >
> > > > I'm adding a test doing exactly what you did, and it's working...
> > > >
> > > > give me 10 minutes and I will post a link here...
> > > >
> > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > Same Issue!
> > > > >         public void sendMessageToSmtpQueue(String text) throws
> > ActiveMQException {
> > > > >                 ClientSession session =
> > this.sessionFactory.createSession();
> > > > >                 try {
> > > > >                         session.start();
> > > > >                         ClientMessage message =
> > session.createMessage(true);
> > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > >                         message.getBodyBuffer().writeString(text);
> > > > >                         ClientProducer producer =
> > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                         producer.send(message);
> > > > >                 } finally {
> > > > >                         session.close();
> > > > >                 }
> > > > >         }
> > > > >
> > > > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > length=1953068645 is greater than readableBytes=3
> > > > >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > > > >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > > > >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > >         at
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > >         at
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > >         at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > >         at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > >         at
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > >         at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > >         at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > >         at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > >         at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > >         at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > >         at
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > >         at
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > stRunner.java:209)
> > > > >
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Can you try calling message.getBodyBuffer().resetReaderIndex();
> > before the send?
> > > > >
> > > > > if that does not work I will try your code and see what happens.
> > > > > (Let me know if doesn't please)
> > > > >
> > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com>
> > wrote:
> > > > > >
> > > > > > maybe take inspiration from
> > > > > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > rati
> > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > on/c lient/MessageBufferTest.java that passes a string, but there
> > > > > > are corresponding byte[] or buffer variants in the api. If you
> > > > > > want to skip the decoding, to access the raw buffer, you need to
> > > > > > parse the type to get to the appropriate part of the buffer.
> > > > > > There are loads of usage examples in the tests and they all work,
> > > > > > start there and break it as you go.
> > > > > >
> > > > > > the issue is the wire level encoding that the client does, the JMS
> > > > > > api hides this, as do the typed accessors, but you can get direct
> > > > > > access to the encoded buffers via the core api as you are doing
> > > > > > but you need to be type aware, for example a string can be utf-8
> > > > > > encoded or it can be raw bytes on the wire, depending on the size
> > > > > > and chars, the encoding handles and hides this detail. But if you
> > > > > > go for direct access, you need to be aware of the encoding.
> > > > > >
> > > > > >
> > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Why you don't use the JMS API for this?
> > > > > > >
> > > > > > > or if you really want to use the core API, use the
> > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > >
> > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > jbertram@apache.org> wrote:
> > > > > > > >
> > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > method on line
> > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see that call
> > > > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > > > seem correct. Can you clarify this?
> > > > > > > >
> > > > > > > >
> > > > > > > > Justin
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > <er...@cgi.com>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > > > Fyi:
> > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii
> > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > e.
> > > > > > > > >
> > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > Onderwerp: AW: send message
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > attachments unless
> > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez
> > aucune pièce
> > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable,
> > > > > > > > > ou que vous ayez l'assurance que le contenu provient d'une
> > source sûre.
> > > > > > > > >
> > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > >
> > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > simpleString,
> > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > >         at
> > > > > > > > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > > > >         at
> > > > > > > > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > > > >         at
> > > > > > > > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > >         at
> > > > > > > > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > > > >         at
> > > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > ke0(
> > > > > > > > > Nati
> > > > > > > > > ve
> > > > > > > > > Method)
> > > > > > > > >         at
> > > > > > > > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > > > >         at
> > > > > > > > >
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > > > >         at
> > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > >         at
> > > > > > > > >
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > > > >         at
> > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > > > >         at
> > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > > > >         at
> > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > > > >         at
> > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > > > >         at
> > > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > Remo
> > > > > > > > > teTe
> > > > > > > > > stRunner.java:209)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com>
> > wrote:
> > > > > > > > >
> > > > > > > > > > I try to send and receive a netty ByteBuf message, but it
> > fails.
> > > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > >
> > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > > > throws ActiveMQException {
> > > > > > > > > >              ClientSession session =
> > this.sessionFactory.createSession();
> > > > > > > > > >              try {
> > > > > > > > > >                     session.start();
> > > > > > > > > >                     ClientMessage message =
> > session.createMessage(true);
> > > > > > > > > >
> > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > buf.readableBytes());
> > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                     producer.send(message);
> > > > > > > > > >              } finally {
> > > > > > > > > >                     session.close();
> > > > > > > > > >              }
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > > > > throws ActiveMQException {
> > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > >              ClientSession session =
> > this.sessionFactory.createSession();
> > > > > > > > > >              try {
> > > > > > > > > >                     session.start();
> > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                     ClientMessage message =
> > consumer.receive();
> > > > > > > > > >                     result =
> > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > > > >
> >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > >              } finally {
> > > > > > > > > >                     session.close();
> > > > > > > > > >              }
> > > > > > > > > >
> > > > > > > > > >              return result;
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > > > > >
> > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > >
> > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > >
> > > > > > > > > >              this.server = new
> > ActiveMQServerImpl(this.configuration);
> > > > > > > > > >              this.server.start();
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
> >



-- 
Clebert Suconic

Re: send message

Posted by Francesco Nigro <ni...@gmail.com>.
Just to mention: Netty ByteBuf can use internal Nio Buffers and you can use
that methods to interact with other msgs APIs too (but check you find what
you need).
It would works only if you're not using composite netty buffers or read
only buffers :)

Il giorno mer 24 mar 2021 alle ore 17:56 Justin Bertram <jb...@apache.org>
ha scritto:

> Well said, Tim. I was going to say the same thing about premature
> optimization.
>
>
> Justin
>
> On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
>
> > One thing to keep in mind is that although the code may be slightly
> slower,
> > if it lets you use an API that is more favorable (which might mean better
> > documented, more portable, more stable across future versions, easier for
> > others to maintain because they're already familiar with it, or a number
> of
> > other potential advantages), that might be a win.
> >
> > Only you know your use case and whether the performance advantages of
> what
> > you're trying to do actually outweigh the types of advantages I
> referenced
> > in the first paragraph. But remember that premature optimization is the
> > root of all evil, so make sure that your micro-optimization of avoiding
> the
> > creation of a String is really a significant enough optimization in the
> > context of your use case to justify the disadvantages of what you're
> trying
> > to do.
> >
> > Tim
> >
> > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic <clebert.suconic@gmail.com
> >
> > wrote:
> >
> > > Not on the API itself.
> > >
> > > Try the core api example I sent you... and let me know what is
> > > different from yours.
> > >
> > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > >
> > > > I want to use the jms layer, but I've a netty application and I want
> to
> > > write the ByteBuf mostly efficent to the queue.
> > > > I think it makes no sense to convert it back from a native buffer
> into
> > a
> > > byte array or stream and tunnel this throught the jvm!
> > > >
> > > > Is there a way to use a ByteBuf with jms?
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > You were supposed to call reset right before sending though... but I
> > did
> > > not need it on my test.. I will post a link...
> > > >
> > > > Anyway, if you use the JMS API, the JMS layer is very thin, and I
> don't
> > > think it would affect your performance in any way. you could create a
> > > BytesMessage and all the detail would be hidden away from the internal
> > API.
> > > >
> > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > clebert.suconic@gmail.com> wrote:
> > > > >
> > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > >
> > > > > give me 10 minutes and I will post a link here...
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > Same Issue!
> > > > > >         public void sendMessageToSmtpQueue(String text) throws
> > > ActiveMQException {
> > > > > >                 ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > >                 try {
> > > > > >                         session.start();
> > > > > >                         ClientMessage message =
> > > session.createMessage(true);
> > > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > > >
>  message.getBodyBuffer().resetReaderIndex();
> > > > > >
>  message.getBodyBuffer().writeString(text);
> > > > > >                         ClientProducer producer =
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > >                         producer.send(message);
> > > > > >                 } finally {
> > > > > >                         session.close();
> > > > > >                 }
> > > > > >         }
> > > > > >
> > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> simpleString,
> > > length=1953068645 is greater than readableBytes=3
> > > > > >         at
> > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > >         at
> > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > >         at
> > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > >         at
> > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > >
> >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > >
> >
> .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > > > > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > > > > >         at
> > >
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > >         at
> > >
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > >         at
> > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > >         at
> > >
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > >         at
> > >
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > >         at
> > >
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > >         at
> > >
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > >         at
> > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > >         at
> > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > >         at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > >         at
> > >
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > >         at
> > >
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > >         at
> > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > >         at
> > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > >         at
> > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > >         at
> > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > > stRunner.java:209)
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Can you try calling message.getBodyBuffer().resetReaderIndex();
> > > before the send?
> > > > > >
> > > > > > if that does not work I will try your code and see what happens.
> > > > > > (Let me know if doesn't please)
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <gary.tully@gmail.com
> >
> > > wrote:
> > > > > > >
> > > > > > > maybe take inspiration from
> > > > > > >
> > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > rati
> > > > > > >
> > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > on/c lient/MessageBufferTest.java that passes a string, but
> there
> > > > > > > are corresponding byte[] or buffer variants in the api. If you
> > > > > > > want to skip the decoding, to access the raw buffer, you need
> to
> > > > > > > parse the type to get to the appropriate part of the buffer.
> > > > > > > There are loads of usage examples in the tests and they all
> work,
> > > > > > > start there and break it as you go.
> > > > > > >
> > > > > > > the issue is the wire level encoding that the client does, the
> > JMS
> > > > > > > api hides this, as do the typed accessors, but you can get
> direct
> > > > > > > access to the encoded buffers via the core api as you are doing
> > > > > > > but you need to be type aware, for example a string can be
> utf-8
> > > > > > > encoded or it can be raw bytes on the wire, depending on the
> size
> > > > > > > and chars, the encoding handles and hides this detail. But if
> you
> > > > > > > go for direct access, you need to be aware of the encoding.
> > > > > > >
> > > > > > >
> > > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com>
> wrote:
> > > > > > > >
> > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > Why you don't use the JMS API for this?
> > > > > > > >
> > > > > > > > or if you really want to use the core API, use the
> > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > jbertram@apache.org> wrote:
> > > > > > > > >
> > > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > > method on line
> > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see that
> > call
> > > > > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > > > > seem correct. Can you clarify this?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > <er...@cgi.com>
> > > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > > Fyi:
> > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) =
> "tive"(ascii
> > > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > > e.
> > > > > > > > > >
> > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > Van: Tobias.Wolf@t-systems.com <
> Tobias.Wolf@t-systems.com>
> > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > attachments unless
> > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > n’ouvrez
> > > aucune pièce
> > > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur
> > fiable,
> > > > > > > > > > ou que vous ayez l'assurance que le contenu provient
> d'une
> > > source sûre.
> > > > > > > > > >
> > > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > > >
> > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > > simpleString,
> > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > >
> >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > >
> >
> .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > > > > >         at
> > > > > > > > > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > ke0(
> > > > > > > > > > Nati
> > > > > > > > > > ve
> > > > > > > > > > Method)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > > > > >         at
> > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > > > > >         at
> > > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > Remo
> > > > > > > > > > teTe
> > > > > > > > > > stRunner.java:209)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <
> Tobias.Wolf@t-systems.com
> > >
> > > wrote:
> > > > > > > > > >
> > > > > > > > > > > I try to send and receive a netty ByteBuf message, but
> it
> > > fails.
> > > > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > > I was thinking to use the jms layer, but I'm receiving
> > the
> > > > > > > > > > > data buffer throught a netty buffer and I want to avoid
> > to
> > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > >
> > > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientMessage message =
> > > session.createMessage(true);
> > > > > > > > > > >
> > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > buf.readableBytes());
> > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >        public ActiveMQBuffer
> > receiveMessageFromSmtpQueue()
> > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     ClientMessage message =
> > > consumer.receive();
> > > > > > > > > > >                     result =
> > > > > > > > > > >
> ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > > > > >
> > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >
> > > > > > > > > > >              return result;
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > >              this.configuration = new
> > ConfigurationImpl();
> > > > > > > > > > >
> > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > >
> > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > >
> > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > >
> this.configuration.addQueueConfiguration(new
> > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > >
> > > > > > > > > > >              this.server = new
> > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > >              this.server.start();
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> > >
> >
>

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
If you call session.createQueue("QueueName") the JMS layer will
perform a queueQuery on the server's side. If you actually have the
system to auto-create the queue, the queue would be created...


however... I wouldn't use auto-creation on production systems. I have
seen things getting out of control, and admins not knowing what is
going on when things are wrong. (not being able to pause, delete, and
other admin stuff).

Be careful on enabling auto-creation on the broker. I would pre-create
destinations or use durable subscriptions.. (even on durable
subscriptions I would be particularly careful on allowing clients to
create stuff).. .I would keep the broker under control for the OPs
guy.

On Tue, Mar 30, 2021 at 3:19 PM Clebert Suconic
<cl...@gmail.com> wrote:
>
> if you create se JMS Session with true, then you should pass in
> Session.SESSION_TRANSACTED. (I guess you would receive an exception if
> you don't... if you're not getting an exception you're lucky... and
> I'm not sure what constraints should be applied)...
>
>
> if you pass the following:
>
>
> createSession(true, Session.SESSION_TRANSACTED);
>
> The confirmation of the message would only be received when the
> session.commit is called.
>
>
>
> if you pass in (false, Session.AUTO_ACKNOWLEDGE);
>
>
> The system should block on session.send(message) as long as the
> message is durable; until the message has reached the disk on the
> server's side. (Unless you disable some properties on the
> ConnectionFactory, but the default is to block on send);
>
>
>
> On Tue, Mar 30, 2021 at 11:00 AM <To...@t-systems.com> wrote:
> >
> > Thank you for the answer, I will go this way!
> >
> > Is it neccessary to create the session as "transacted=true" in case I want to be sure that the ByteBuf was stored sucessfully?
> >          session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
> >
> > How can I check with the JMS client if a particular queue does exists and in case not to create it?
> > In core api I do this way:
> >
> >                 ClientSession session = this.sessionFactory.createSession(true, true);
> >                 try {
> >                         QueueQuery queueQuery = session.queueQuery(new SimpleString(ACTIVE_MQ_SMTP_QUEUE));
> >                         if (!queueQuery.isExists())
> >                                 session.createQueue(new QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE).setDurable(true));
> >                 } finally {
> >                         session.close();
> >                 }
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Montag, 29. März 2021 15:40
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > This example here is working with JMS:
> >
> > https://github.com/apache/activemq-artemis/blob/fe3851ff6d243cc0b58872c5431646fbeb410b41/examples/features/standard/large-message/src/main/java/org/apache/activemq/artemis/jms/example/LargeMessageExample.java
> >
> >
> > Basically, instead of passing a BufferedInputStream that worked through a File, you could pass in a NettyByteBufferInputStream, and it should work the same:
> >
> > https://netty.io/4.0/api/io/netty/buffer/ByteBufInputStream.html
> >
> >
> > I was going to suggest you to write a ByteInputStream yourself when I found one already implemented as part of the Netty library.
> >
> > On Fri, Mar 26, 2021 at 10:43 AM Clebert Suconic <cl...@gmail.com> wrote:
> > >
> > > look at message.setInputStream as you are using the Core API.
> > >
> > > if you were using the JMS API there's a property that kind of wraps it
> > > into the CoreMessage through the JMS Message.
> > >
> > > Since you are using the core api directly look into that property.
> > > Just implement an InputStream that will read from your ByteBuffer and
> > > pass it in.
> > >
> > > On Fri, Mar 26, 2021 at 8:48 AM <To...@t-systems.com> wrote:
> > > >
> > > > A example would be great!
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Freitag, 26. März 2021 13:26
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > On your case it would make sense if the streaming was not a file but a biffer.  I get it.
> > > >
> > > > The optimization here wouldn’t be the copy but it would be not needintg to duplicate the 500MB.  We all thought you had a smaller buffer and did not want the copy.
> > > >
> > > > You can pass an InputStream as a property on the streaming.  If you implemented an InputStream that will read from the NettyBuffer.  The body would be read directly into smaller chunks into the Large Message Streaming.
> > > >
> > > >
> > > > I’m not working today.  As a matter of fact I’m using an iPhone
> > > > right  now (pardon any typoes please)
> > > >
> > > > If you can’t figure it out let me know and I will write you an
> > > > example Monday
> > > >
> > > > On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:
> > > >
> > > > > Not he application is a kind of custom mail server and the
> > > > > messages can reach up to 500mb and are received via tcp and a netty smtp handler.
> > > > > Therefore I have a netty direct buffer already and don't want
> > > > > bring the huge messages back into the jvm.
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Donnerstag, 25. März 2021 20:31
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > I assumed the data was already on a file.
> > > > >
> > > > > If you passed the file name.  The receiver would receive a message
> > > > > where you could either do the opposite. (Pass a file name to steam.
> > > > > Or just receive steaming)
> > > > >
> > > > > At that size of message the optimization of the copy between your
> > > > > buffer and a byte array makes little difference.
> > > > >
> > > > > On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > > So you mean I should save the ByteBuffer by myself to a file?
> > > > > >
> > > > > > --> and pass it over the property that would stream the file directly.
> > > > > > (Available on core only)
> > > > > > What do you mean? I understand that I shall pass the name of the
> > > > > > file via a message property, right?
> > > > > > How would the receiver side looks like?
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Donnerstag, 25. März 2021 16:04
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Sending a message this large will make it to be converted as a
> > > > > > large stream and saved as a file on the server anyways...
> > > > > >
> > > > > > The copy between ByteBuffer and a byte array would become
> > > > > > irrelevant at this point.
> > > > > >
> > > > > > If you want to send a large message this big, you could save it
> > > > > > to a file, and pass it over the property that would stream the file directly.
> > > > > > (Available on core only)
> > > > > >
> > > > > > And don't convert a large message between protocols.. use a
> > > > > > single protocol of your choice.
> > > > > >
> > > > > > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > What are you talking about?
> > > > > > > I want to send byte buffers with the size up to 500MB to a queue!
> > > > > > > What do you mean with string and micro optimization!
> > > > > > > The core api fails in my test already with sending/receiving a
> > > > > > > simple
> > > > > > string, yes, a simple test!
> > > > > > > Does it make sense to have a 500mb native netty buffer
> > > > > > > received via wire
> > > > > > and tunnel it back through the jvm?
> > > > > > > I don`t think so!
> > > > > > > Does it make sense to tunnel megabytes of data through a
> > > > > > > stream or even
> > > > > > an byte array through the jvm?
> > > > > > > Where ist the advantage of jms?
> > > > > > > Why shall I not use the existing core api functions when the
> > > > > > > already
> > > > > > support a netty buffer?
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Well said, Tim. I was going to say the same thing about
> > > > > > > premature
> > > > > > optimization.
> > > > > > >
> > > > > > >
> > > > > > > Justin
> > > > > > >
> > > > > > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain
> > > > > > > <tb...@alumni.duke.edu>
> > > > > wrote:
> > > > > > >
> > > > > > > > One thing to keep in mind is that although the code may be
> > > > > > > > slightly slower, if it lets you use an API that is more
> > > > > > > > favorable (which might mean better documented, more
> > > > > > > > portable, more stable across future versions, easier for
> > > > > > > > others to maintain because they're already familiar with it,
> > > > > > > > or a number of other potential advantages),
> > > > > > that might be a win.
> > > > > > > >
> > > > > > > > Only you know your use case and whether the performance
> > > > > > > > advantages of what you're trying to do actually outweigh the
> > > > > > > > types of advantages I referenced in the first paragraph. But
> > > > > > > > remember that premature optimization is the root of all
> > > > > > > > evil, so make sure that your micro-optimization of avoiding
> > > > > > > > the creation of a String is really a significant enough
> > > > > > > > optimization in the context of your use case to justify the disadvantages of what you're trying to do.
> > > > > > > >
> > > > > > > > Tim
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > > > > > > > <cl...@gmail.com>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > > > Not on the API itself.
> > > > > > > > >
> > > > > > > > > Try the core api example I sent you... and let me know
> > > > > > > > > what is different from yours.
> > > > > > > > >
> > > > > > > > > On Tue, Mar 23, 2021 at 10:34 AM
> > > > > > > > > <To...@t-systems.com>
> > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > I want to use the jms layer, but I've a netty
> > > > > > > > > > application and I want to
> > > > > > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > > > > > I think it makes no sense to convert it back from a
> > > > > > > > > > native buffer into
> > > > > > > > a
> > > > > > > > > byte array or stream and tunnel this throught the jvm!
> > > > > > > > > >
> > > > > > > > > > Is there a way to use a ByteBuf with jms?
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > You were supposed to call reset right before sending though...
> > > > > > > > > > but I
> > > > > > > > did
> > > > > > > > > not need it on my test.. I will post a link...
> > > > > > > > > >
> > > > > > > > > > Anyway, if you use the JMS API, the JMS layer is very
> > > > > > > > > > thin, and I don't
> > > > > > > > > think it would affect your performance in any way. you
> > > > > > > > > could create a BytesMessage and all the detail would be
> > > > > > > > > hidden away from the internal
> > > > > > > > API.
> > > > > > > > > >
> > > > > > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > > > > > clebert.suconic@gmail.com> wrote:
> > > > > > > > > > >
> > > > > > > > > > > I'm adding a test doing exactly what you did, and it's
> > > > > working...
> > > > > > > > > > >
> > > > > > > > > > > give me 10 minutes and I will post a link here...
> > > > > > > > > > >
> > > > > > > > > > > On Tue, Mar 23, 2021 at 9:56 AM
> > > > > > > > > > > <To...@t-systems.com>
> > > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Same Issue!
> > > > > > > > > > > >         public void sendMessageToSmtpQueue(String
> > > > > > > > > > > > text) throws
> > > > > > > > > ActiveMQException {
> > > > > > > > > > > >                 ClientSession session =
> > > > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > >                 try {
> > > > > > > > > > > >                         session.start();
> > > > > > > > > > > >                         ClientMessage message =
> > > > > > > > > session.createMessage(true);
> > > > > > > > > > > >
> > > > > >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > > > > > >
> > > > > >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > > > > > >
> > > > > >  message.getBodyBuffer().writeString(text);
> > > > > > > > > > > >                         ClientProducer producer =
> > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                         producer.send(message);
> > > > > > > > > > > >                 } finally {
> > > > > > > > > > > >                         session.close();
> > > > > > > > > > > >                 }
> > > > > > > > > > > >         }
> > > > > > > > > > > >
> > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading
> > > > > > > > > > > > in simpleString,
> > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > > Stri
> > > > > > > > ng
> > > > > > > > (S
> > > > > > > > im
> > > > > > > > pleString.java:185)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > > Stri
> > > > > > > > ng
> > > > > > > > (S
> > > > > > > > im
> > > > > > > > pleString.java:173)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > > rapp
> > > > > > > > er
> > > > > > > > .r
> > > > > > > > ea
> > > > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > > rapp
> > > > > > > > er
> > > > > > > > .r
> > > > > > > > ea
> > > > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> > > > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(Ma
> > > > > > > > ilSe
> > > > > > > > rv
> > > > > > > > er
> > > > > > > > Ac
> > > > > > > > tiveMQClient.java:94)
> > > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> > > > > > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(Mail
> > > > > > > > Serv
> > > > > > > > er
> > > > > > > > Ac
> > > > > > > > ti
> > > > > > > > veMQClientTest.java:37)
> > > > > > > > > > > >         at
> > > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.in
> > > > > > > > > voke
> > > > > > > > > 0(
> > > > > > > > > Na
> > > > > > > > > ti
> > > > > > > > > ve
> > > > > > > > > Method)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > ke(N
> > > > > > > > at
> > > > > > > > iv
> > > > > > > > eM
> > > > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> > > > > > > > invo
> > > > > > > > ke
> > > > > > > > (D
> > > > > > > > el
> > > > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > >         at
> > > > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> > > > > > > > Fram
> > > > > > > > ew
> > > > > > > > or
> > > > > > > > kM
> > > > > > > > ethod.java:50)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> > > > > > > > ecti
> > > > > > > > ve
> > > > > > > > Ca
> > > > > > > > ll
> > > > > > > > able.java:12)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> > > > > > > > amew
> > > > > > > > or
> > > > > > > > kM
> > > > > > > > et
> > > > > > > > hod.java:47)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(
> > > > > > > > Invo
> > > > > > > > ke
> > > > > > > > Me
> > > > > > > > th
> > > > > > > > od.java:17)
> > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:3
> > > > > > > > > 25)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > > 4Cla
> > > > > > > > ss
> > > > > > > > Ru
> > > > > > > > nn
> > > > > > > > er.java:78)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > > 4Cla
> > > > > > > > ss
> > > > > > > > Ru
> > > > > > > > nn
> > > > > > > > er.java:57)
> > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290
> > > > > > > > > )
> > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.jav
> > > > > > > > > a:71
> > > > > > > > > )
> > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.ja
> > > > > > > > > va:2
> > > > > > > > > 88
> > > > > > > > > )
> > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.jav
> > > > > > > > > a:58
> > > > > > > > > )
> > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.jav
> > > > > > > > > a:26
> > > > > > > > > 8)
> > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> > > > > > > > un(J
> > > > > > > > Un
> > > > > > > > it
> > > > > > > > 4T
> > > > > > > > estReference.java:89)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > > > java:41)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > > sts(
> > > > > > > > Re
> > > > > > > > mo
> > > > > > > > te
> > > > > > > > TestRunner.java:541)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > > sts(
> > > > > > > > Re
> > > > > > > > mo
> > > > > > > > te
> > > > > > > > TestRunner.java:763)
> > > > > > > > > > > >         at
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> > > > > > > > emot
> > > > > > > > eT
> > > > > > > > es
> > > > > > > > tR
> > > > > > > > unner.java:463)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > Remo
> > > > > > > > te
> > > > > > > > Te
> > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > >
> > > > > > > > > > > > Can you try calling
> > > > > > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > > > > > before the send?
> > > > > > > > > > > >
> > > > > > > > > > > > if that does not work I will try your code and see
> > > > > > > > > > > > what
> > > > > > happens.
> > > > > > > > > > > > (Let me know if doesn't please)
> > > > > > > > > > > >
> > > > > > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > > > > > > > <ga...@gmail.com>
> > > > > > > > > wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > maybe take inspiration from
> > > > > > > > > > > > >
> > > > > > > > https://github.com/apache/activemq-artemis/blob/master/tests
> > > > > > > > /int
> > > > > > > > eg
> > > > > > > > > > > > > rati
> > > > > > > > > > > > >
> > > > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/int
> > > > > > > > egra
> > > > > > > > ti
> > > > > > > > > > > > > on/c lient/MessageBufferTest.java that passes a
> > > > > > > > > > > > > string, but there are corresponding byte[] or
> > > > > > > > > > > > > buffer variants in the api. If you want to skip
> > > > > > > > > > > > > the decoding, to access the raw buffer, you need
> > > > > > > > > > > > > to parse the type to get to the
> > > > > > appropriate part of the buffer.
> > > > > > > > > > > > > There are loads of usage examples in the tests and
> > > > > > > > > > > > > they all work, start there and break it as you go.
> > > > > > > > > > > > >
> > > > > > > > > > > > > the issue is the wire level encoding that the
> > > > > > > > > > > > > client does, the
> > > > > > > > JMS
> > > > > > > > > > > > > api hides this, as do the typed accessors, but you
> > > > > > > > > > > > > can get direct access to the encoded buffers via
> > > > > > > > > > > > > the core api as you are doing but you need to be
> > > > > > > > > > > > > type aware, for example a string can be utf-8
> > > > > > > > > > > > > encoded or it can be raw bytes on the wire,
> > > > > > > > > > > > > depending on the size and chars, the encoding
> > > > > > > > > > > > > handles and hides this detail. But if you go for
> > > > > > > > > > > > > direct
> > > > > > access, you need to be aware of the encoding.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Tue, 23 Mar 2021 at 07:37,
> > > > > > > > > > > > > <To...@t-systems.com>
> > > > > > wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > or if you really want to use the core API, use
> > > > > > > > > > > > > > the
> > > > > > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram
> > > > > > > > > > > > > > <
> > > > > > > > > jbertram@apache.org> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > The stack-trace indicates you're invoking the
> > > > > > "readString"
> > > > > > > > > > > > > > > method on line
> > > > > > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I
> > > > > > > > > > > > > > > don't see that
> > > > > > > > call
> > > > > > > > > > > > > > > in the code you pasted. Therefore, that
> > > > > > > > > > > > > > > stack-trace doesn't seem correct. Can you clarify this?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Justin
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp,
> > > > > > > > > > > > > > > Erwin <er...@cgi.com>
> > > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Fyi:
> > > > > > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal)
> > > > > > > > > > > > > > > > = "tive"(ascii
> > > > > > > > > > > > > > > > text) And "tive" is likely part of the
> > > > > > > > > > > > > > > > string
> > > > > > "ActiveMQ"?
> > > > > > > > > > > > > > > > e.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > > > > > attachments unless
> > > > > > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > > > > > n’ouvrez
> > > > > > > > > aucune pièce
> > > > > > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un
> > > > > > > > > > > > > > > > expéditeur
> > > > > > > > fiable,
> > > > > > > > > > > > > > > > ou que vous ayez l'assurance que le contenu
> > > > > > > > > > > > > > > > provient d'une
> > > > > > > > > source sûre.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > While sending / receiving a text message I
> > > > > > > > > > > > > > > > get this
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error
> > > > > > > > > > > > > > > > reading in simpleString,
> > > > > > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > > Stri
> > > > > > > > ng
> > > > > > > > (S
> > > > > > > > im
> > > > > > > > pleString.java:185)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > > Stri
> > > > > > > > ng
> > > > > > > > (S
> > > > > > > > im
> > > > > > > > pleString.java:173)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > > rapp
> > > > > > > > er
> > > > > > > > .r
> > > > > > > > ea
> > > > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > > rapp
> > > > > > > > er
> > > > > > > > .r
> > > > > > > > ea
> > > > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(Ma
> > > > > > > > ilSe
> > > > > > > > rv
> > > > > > > > er
> > > > > > > > Ac
> > > > > > > > tiveMQClient.java:93)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiv
> > > > > > > > eMQC
> > > > > > > > li
> > > > > > > > en
> > > > > > > > tT
> > > > > > > > est.java:28)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > > > > > ke0(
> > > > > > > > > > > > > > > > Nati
> > > > > > > > > > > > > > > > ve
> > > > > > > > > > > > > > > > Method)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > ke(N
> > > > > > > > at
> > > > > > > > iv
> > > > > > > > eM
> > > > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> > > > > > > > invo
> > > > > > > > ke
> > > > > > > > (D
> > > > > > > > el
> > > > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> > > > > > > > Fram
> > > > > > > > ew
> > > > > > > > or
> > > > > > > > kM
> > > > > > > > ethod.java:50)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> > > > > > > > ecti
> > > > > > > > ve
> > > > > > > > Ca
> > > > > > > > ll
> > > > > > > > able.java:12)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> > > > > > > > amew
> > > > > > > > or
> > > > > > > > kM
> > > > > > > > et
> > > > > > > > hod.java:47)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(
> > > > > > > > Invo
> > > > > > > > ke
> > > > > > > > Me
> > > > > > > > th
> > > > > > > > od.java:17)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:3
> > > > > > > > > 25)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > > 4Cla
> > > > > > > > ss
> > > > > > > > Ru
> > > > > > > > nn
> > > > > > > > er.java:78)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > > 4Cla
> > > > > > > > ss
> > > > > > > > Ru
> > > > > > > > nn
> > > > > > > > er.java:57)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290
> > > > > > > > > )
> > > > > > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.jav
> > > > > > > > > a:71
> > > > > > > > > )
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.ja
> > > > > > > > > va:2
> > > > > > > > > 88
> > > > > > > > > )
> > > > > > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.jav
> > > > > > > > > a:58
> > > > > > > > > )
> > > > > > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.jav
> > > > > > > > > a:26
> > > > > > > > > 8)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> > > > > > > > un(J
> > > > > > > > Un
> > > > > > > > it
> > > > > > > > 4T
> > > > > > > > estReference.java:89)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > > > java:41)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > > sts(
> > > > > > > > Re
> > > > > > > > mo
> > > > > > > > te
> > > > > > > > TestRunner.java:541)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > > sts(
> > > > > > > > Re
> > > > > > > > mo
> > > > > > > > te
> > > > > > > > TestRunner.java:763)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> > > > > > > > emot
> > > > > > > > eT
> > > > > > > > es
> > > > > > > > tR
> > > > > > > > unner.java:463)
> > > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > >
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > > > > > Remo
> > > > > > > > > > > > > > > > teTe
> > > > > > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Justin
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > > > > > >
> > > > > > > > > wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I try to send and receive a netty ByteBuf
> > > > > > > > > > > > > > > > > message, but it
> > > > > > > > > fails.
> > > > > > > > > > > > > > > > > What I'm doing wrong here? I even don't
> > > > > > > > > > > > > > > > > know ist he mistake in sending or receiving!
> > > > > > > > > > > > > > > > > I was thinking to use the jms layer, but
> > > > > > > > > > > > > > > > > I'm receiving
> > > > > > > > the
> > > > > > > > > > > > > > > > > data buffer throught a netty buffer and I
> > > > > > > > > > > > > > > > > want to avoid
> > > > > > > > to
> > > > > > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >        public void
> > > > > > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > > > >                     ClientMessage message
> > > > > > > > > > > > > > > > > =
> > > > > > > > > session.createMessage(true);
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > > > > buf.readableBytes());
> > > > > > > > > > > > > > > > >                     ClientProducer
> > > > > > > > > > > > > > > > > producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >        public ActiveMQBuffer
> > > > > > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > > > >                     ClientConsumer
> > > > > > > > > > > > > > > > > consumer = session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > > > >                     ClientMessage message
> > > > > > > > > > > > > > > > > =
> > > > > > > > > consumer.receive();
> > > > > > > > > > > > > > > > >                     result =
> > > > > > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBod
> > > > > > > > > > > > > > > > > yBuf
> > > > > > > > > > > > > > > > > fe
> > > > > > > > > > > > > > > > > rS
> > > > > > > > > > > > > > > > > iz
> > > > > > > > > > > > > > > > > e());
> > > > > > > > > > > > > > > > >
> > > > > > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >              return result;
> > > > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > > > > > >              this.configuration = new
> > > > > > > > ConfigurationImpl();
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > this.configuration.addAcceptorConfiguratio
> > > > > > > > > > > > > > > > > n("i
> > > > > > > > > > > > > > > > > n- vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > > > > > >
> > > > > > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > > > > > >
> > > > > > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > this.configuration.addQueueConfiguration(n
> > > > > > > > > > > > > > > > > ew
> > > > > > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >              this.server = new
> > > > > > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --
> > > > > > > > > > > > > > Clebert Suconic
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > --
> > > > > > > > > > > > Clebert Suconic
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > Clebert Suconic
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Clebert Suconic
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > > > >
> > > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > > >
> > > > > --
> > > > > Clebert Suconic
> > > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic


Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
if you create se JMS Session with true, then you should pass in
Session.SESSION_TRANSACTED. (I guess you would receive an exception if
you don't... if you're not getting an exception you're lucky... and
I'm not sure what constraints should be applied)...


if you pass the following:


createSession(true, Session.SESSION_TRANSACTED);

The confirmation of the message would only be received when the
session.commit is called.



if you pass in (false, Session.AUTO_ACKNOWLEDGE);


The system should block on session.send(message) as long as the
message is durable; until the message has reached the disk on the
server's side. (Unless you disable some properties on the
ConnectionFactory, but the default is to block on send);



On Tue, Mar 30, 2021 at 11:00 AM <To...@t-systems.com> wrote:
>
> Thank you for the answer, I will go this way!
>
> Is it neccessary to create the session as "transacted=true" in case I want to be sure that the ByteBuf was stored sucessfully?
>          session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
>
> How can I check with the JMS client if a particular queue does exists and in case not to create it?
> In core api I do this way:
>
>                 ClientSession session = this.sessionFactory.createSession(true, true);
>                 try {
>                         QueueQuery queueQuery = session.queueQuery(new SimpleString(ACTIVE_MQ_SMTP_QUEUE));
>                         if (!queueQuery.isExists())
>                                 session.createQueue(new QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE).setDurable(true));
>                 } finally {
>                         session.close();
>                 }
>
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Montag, 29. März 2021 15:40
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> This example here is working with JMS:
>
> https://github.com/apache/activemq-artemis/blob/fe3851ff6d243cc0b58872c5431646fbeb410b41/examples/features/standard/large-message/src/main/java/org/apache/activemq/artemis/jms/example/LargeMessageExample.java
>
>
> Basically, instead of passing a BufferedInputStream that worked through a File, you could pass in a NettyByteBufferInputStream, and it should work the same:
>
> https://netty.io/4.0/api/io/netty/buffer/ByteBufInputStream.html
>
>
> I was going to suggest you to write a ByteInputStream yourself when I found one already implemented as part of the Netty library.
>
> On Fri, Mar 26, 2021 at 10:43 AM Clebert Suconic <cl...@gmail.com> wrote:
> >
> > look at message.setInputStream as you are using the Core API.
> >
> > if you were using the JMS API there's a property that kind of wraps it
> > into the CoreMessage through the JMS Message.
> >
> > Since you are using the core api directly look into that property.
> > Just implement an InputStream that will read from your ByteBuffer and
> > pass it in.
> >
> > On Fri, Mar 26, 2021 at 8:48 AM <To...@t-systems.com> wrote:
> > >
> > > A example would be great!
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Freitag, 26. März 2021 13:26
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > On your case it would make sense if the streaming was not a file but a biffer.  I get it.
> > >
> > > The optimization here wouldn’t be the copy but it would be not needintg to duplicate the 500MB.  We all thought you had a smaller buffer and did not want the copy.
> > >
> > > You can pass an InputStream as a property on the streaming.  If you implemented an InputStream that will read from the NettyBuffer.  The body would be read directly into smaller chunks into the Large Message Streaming.
> > >
> > >
> > > I’m not working today.  As a matter of fact I’m using an iPhone
> > > right  now (pardon any typoes please)
> > >
> > > If you can’t figure it out let me know and I will write you an
> > > example Monday
> > >
> > > On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:
> > >
> > > > Not he application is a kind of custom mail server and the
> > > > messages can reach up to 500mb and are received via tcp and a netty smtp handler.
> > > > Therefore I have a netty direct buffer already and don't want
> > > > bring the huge messages back into the jvm.
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Donnerstag, 25. März 2021 20:31
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > I assumed the data was already on a file.
> > > >
> > > > If you passed the file name.  The receiver would receive a message
> > > > where you could either do the opposite. (Pass a file name to steam.
> > > > Or just receive steaming)
> > > >
> > > > At that size of message the optimization of the copy between your
> > > > buffer and a byte array makes little difference.
> > > >
> > > > On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
> > > >
> > > > > So you mean I should save the ByteBuffer by myself to a file?
> > > > >
> > > > > --> and pass it over the property that would stream the file directly.
> > > > > (Available on core only)
> > > > > What do you mean? I understand that I shall pass the name of the
> > > > > file via a message property, right?
> > > > > How would the receiver side looks like?
> > > > >
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Donnerstag, 25. März 2021 16:04
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Sending a message this large will make it to be converted as a
> > > > > large stream and saved as a file on the server anyways...
> > > > >
> > > > > The copy between ByteBuffer and a byte array would become
> > > > > irrelevant at this point.
> > > > >
> > > > > If you want to send a large message this big, you could save it
> > > > > to a file, and pass it over the property that would stream the file directly.
> > > > > (Available on core only)
> > > > >
> > > > > And don't convert a large message between protocols.. use a
> > > > > single protocol of your choice.
> > > > >
> > > > > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > What are you talking about?
> > > > > > I want to send byte buffers with the size up to 500MB to a queue!
> > > > > > What do you mean with string and micro optimization!
> > > > > > The core api fails in my test already with sending/receiving a
> > > > > > simple
> > > > > string, yes, a simple test!
> > > > > > Does it make sense to have a 500mb native netty buffer
> > > > > > received via wire
> > > > > and tunnel it back through the jvm?
> > > > > > I don`t think so!
> > > > > > Does it make sense to tunnel megabytes of data through a
> > > > > > stream or even
> > > > > an byte array through the jvm?
> > > > > > Where ist the advantage of jms?
> > > > > > Why shall I not use the existing core api functions when the
> > > > > > already
> > > > > support a netty buffer?
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Well said, Tim. I was going to say the same thing about
> > > > > > premature
> > > > > optimization.
> > > > > >
> > > > > >
> > > > > > Justin
> > > > > >
> > > > > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain
> > > > > > <tb...@alumni.duke.edu>
> > > > wrote:
> > > > > >
> > > > > > > One thing to keep in mind is that although the code may be
> > > > > > > slightly slower, if it lets you use an API that is more
> > > > > > > favorable (which might mean better documented, more
> > > > > > > portable, more stable across future versions, easier for
> > > > > > > others to maintain because they're already familiar with it,
> > > > > > > or a number of other potential advantages),
> > > > > that might be a win.
> > > > > > >
> > > > > > > Only you know your use case and whether the performance
> > > > > > > advantages of what you're trying to do actually outweigh the
> > > > > > > types of advantages I referenced in the first paragraph. But
> > > > > > > remember that premature optimization is the root of all
> > > > > > > evil, so make sure that your micro-optimization of avoiding
> > > > > > > the creation of a String is really a significant enough
> > > > > > > optimization in the context of your use case to justify the disadvantages of what you're trying to do.
> > > > > > >
> > > > > > > Tim
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > > > > > > <cl...@gmail.com>
> > > > > > > wrote:
> > > > > > >
> > > > > > > > Not on the API itself.
> > > > > > > >
> > > > > > > > Try the core api example I sent you... and let me know
> > > > > > > > what is different from yours.
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021 at 10:34 AM
> > > > > > > > <To...@t-systems.com>
> > > > wrote:
> > > > > > > > >
> > > > > > > > > I want to use the jms layer, but I've a netty
> > > > > > > > > application and I want to
> > > > > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > > > > I think it makes no sense to convert it back from a
> > > > > > > > > native buffer into
> > > > > > > a
> > > > > > > > byte array or stream and tunnel this throught the jvm!
> > > > > > > > >
> > > > > > > > > Is there a way to use a ByteBuf with jms?
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > You were supposed to call reset right before sending though...
> > > > > > > > > but I
> > > > > > > did
> > > > > > > > not need it on my test.. I will post a link...
> > > > > > > > >
> > > > > > > > > Anyway, if you use the JMS API, the JMS layer is very
> > > > > > > > > thin, and I don't
> > > > > > > > think it would affect your performance in any way. you
> > > > > > > > could create a BytesMessage and all the detail would be
> > > > > > > > hidden away from the internal
> > > > > > > API.
> > > > > > > > >
> > > > > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > > > > clebert.suconic@gmail.com> wrote:
> > > > > > > > > >
> > > > > > > > > > I'm adding a test doing exactly what you did, and it's
> > > > working...
> > > > > > > > > >
> > > > > > > > > > give me 10 minutes and I will post a link here...
> > > > > > > > > >
> > > > > > > > > > On Tue, Mar 23, 2021 at 9:56 AM
> > > > > > > > > > <To...@t-systems.com>
> > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > Same Issue!
> > > > > > > > > > >         public void sendMessageToSmtpQueue(String
> > > > > > > > > > > text) throws
> > > > > > > > ActiveMQException {
> > > > > > > > > > >                 ClientSession session =
> > > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > >                 try {
> > > > > > > > > > >                         session.start();
> > > > > > > > > > >                         ClientMessage message =
> > > > > > > > session.createMessage(true);
> > > > > > > > > > >
> > > > >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > > > > >
> > > > >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > > > > >
> > > > >  message.getBodyBuffer().writeString(text);
> > > > > > > > > > >                         ClientProducer producer =
> > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                         producer.send(message);
> > > > > > > > > > >                 } finally {
> > > > > > > > > > >                         session.close();
> > > > > > > > > > >                 }
> > > > > > > > > > >         }
> > > > > > > > > > >
> > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading
> > > > > > > > > > > in simpleString,
> > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > Stri
> > > > > > > ng
> > > > > > > (S
> > > > > > > im
> > > > > > > pleString.java:185)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > Stri
> > > > > > > ng
> > > > > > > (S
> > > > > > > im
> > > > > > > pleString.java:173)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > rapp
> > > > > > > er
> > > > > > > .r
> > > > > > > ea
> > > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > rapp
> > > > > > > er
> > > > > > > .r
> > > > > > > ea
> > > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > >
> > > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(Ma
> > > > > > > ilSe
> > > > > > > rv
> > > > > > > er
> > > > > > > Ac
> > > > > > > tiveMQClient.java:94)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > >
> > > > > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(Mail
> > > > > > > Serv
> > > > > > > er
> > > > > > > Ac
> > > > > > > ti
> > > > > > > veMQClientTest.java:37)
> > > > > > > > > > >         at
> > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.in
> > > > > > > > voke
> > > > > > > > 0(
> > > > > > > > Na
> > > > > > > > ti
> > > > > > > > ve
> > > > > > > > Method)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > ke(N
> > > > > > > at
> > > > > > > iv
> > > > > > > eM
> > > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> > > > > > > invo
> > > > > > > ke
> > > > > > > (D
> > > > > > > el
> > > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > >         at
> > > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> > > > > > > Fram
> > > > > > > ew
> > > > > > > or
> > > > > > > kM
> > > > > > > ethod.java:50)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> > > > > > > ecti
> > > > > > > ve
> > > > > > > Ca
> > > > > > > ll
> > > > > > > able.java:12)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> > > > > > > amew
> > > > > > > or
> > > > > > > kM
> > > > > > > et
> > > > > > > hod.java:47)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(
> > > > > > > Invo
> > > > > > > ke
> > > > > > > Me
> > > > > > > th
> > > > > > > od.java:17)
> > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:3
> > > > > > > > 25)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > 4Cla
> > > > > > > ss
> > > > > > > Ru
> > > > > > > nn
> > > > > > > er.java:78)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > 4Cla
> > > > > > > ss
> > > > > > > Ru
> > > > > > > nn
> > > > > > > er.java:57)
> > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290
> > > > > > > > )
> > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.jav
> > > > > > > > a:71
> > > > > > > > )
> > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.ja
> > > > > > > > va:2
> > > > > > > > 88
> > > > > > > > )
> > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.jav
> > > > > > > > a:58
> > > > > > > > )
> > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.jav
> > > > > > > > a:26
> > > > > > > > 8)
> > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> > > > > > > un(J
> > > > > > > Un
> > > > > > > it
> > > > > > > 4T
> > > > > > > estReference.java:89)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > > java:41)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > sts(
> > > > > > > Re
> > > > > > > mo
> > > > > > > te
> > > > > > > TestRunner.java:541)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > sts(
> > > > > > > Re
> > > > > > > mo
> > > > > > > te
> > > > > > > TestRunner.java:763)
> > > > > > > > > > >         at
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> > > > > > > emot
> > > > > > > eT
> > > > > > > es
> > > > > > > tR
> > > > > > > unner.java:463)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > Remo
> > > > > > > te
> > > > > > > Te
> > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > >
> > > > > > > > > > > Can you try calling
> > > > > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > > > > before the send?
> > > > > > > > > > >
> > > > > > > > > > > if that does not work I will try your code and see
> > > > > > > > > > > what
> > > > > happens.
> > > > > > > > > > > (Let me know if doesn't please)
> > > > > > > > > > >
> > > > > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > > > > > > <ga...@gmail.com>
> > > > > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > maybe take inspiration from
> > > > > > > > > > > >
> > > > > > > https://github.com/apache/activemq-artemis/blob/master/tests
> > > > > > > /int
> > > > > > > eg
> > > > > > > > > > > > rati
> > > > > > > > > > > >
> > > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/int
> > > > > > > egra
> > > > > > > ti
> > > > > > > > > > > > on/c lient/MessageBufferTest.java that passes a
> > > > > > > > > > > > string, but there are corresponding byte[] or
> > > > > > > > > > > > buffer variants in the api. If you want to skip
> > > > > > > > > > > > the decoding, to access the raw buffer, you need
> > > > > > > > > > > > to parse the type to get to the
> > > > > appropriate part of the buffer.
> > > > > > > > > > > > There are loads of usage examples in the tests and
> > > > > > > > > > > > they all work, start there and break it as you go.
> > > > > > > > > > > >
> > > > > > > > > > > > the issue is the wire level encoding that the
> > > > > > > > > > > > client does, the
> > > > > > > JMS
> > > > > > > > > > > > api hides this, as do the typed accessors, but you
> > > > > > > > > > > > can get direct access to the encoded buffers via
> > > > > > > > > > > > the core api as you are doing but you need to be
> > > > > > > > > > > > type aware, for example a string can be utf-8
> > > > > > > > > > > > encoded or it can be raw bytes on the wire,
> > > > > > > > > > > > depending on the size and chars, the encoding
> > > > > > > > > > > > handles and hides this detail. But if you go for
> > > > > > > > > > > > direct
> > > > > access, you need to be aware of the encoding.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > On Tue, 23 Mar 2021 at 07:37,
> > > > > > > > > > > > <To...@t-systems.com>
> > > > > wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > > > > >
> > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > >
> > > > > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > > > > >
> > > > > > > > > > > > > or if you really want to use the core API, use
> > > > > > > > > > > > > the
> > > > > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram
> > > > > > > > > > > > > <
> > > > > > > > jbertram@apache.org> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > The stack-trace indicates you're invoking the
> > > > > "readString"
> > > > > > > > > > > > > > method on line
> > > > > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I
> > > > > > > > > > > > > > don't see that
> > > > > > > call
> > > > > > > > > > > > > > in the code you pasted. Therefore, that
> > > > > > > > > > > > > > stack-trace doesn't seem correct. Can you clarify this?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Justin
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp,
> > > > > > > > > > > > > > Erwin <er...@cgi.com>
> > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Fyi:
> > > > > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal)
> > > > > > > > > > > > > > > = "tive"(ascii
> > > > > > > > > > > > > > > text) And "tive" is likely part of the
> > > > > > > > > > > > > > > string
> > > > > "ActiveMQ"?
> > > > > > > > > > > > > > > e.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > > > > attachments unless
> > > > > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > > > > n’ouvrez
> > > > > > > > aucune pièce
> > > > > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un
> > > > > > > > > > > > > > > expéditeur
> > > > > > > fiable,
> > > > > > > > > > > > > > > ou que vous ayez l'assurance que le contenu
> > > > > > > > > > > > > > > provient d'une
> > > > > > > > source sûre.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > While sending / receiving a text message I
> > > > > > > > > > > > > > > get this
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error
> > > > > > > > > > > > > > > reading in simpleString,
> > > > > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > Stri
> > > > > > > ng
> > > > > > > (S
> > > > > > > im
> > > > > > > pleString.java:185)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > > Stri
> > > > > > > ng
> > > > > > > (S
> > > > > > > im
> > > > > > > pleString.java:173)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > rapp
> > > > > > > er
> > > > > > > .r
> > > > > > > ea
> > > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > > rapp
> > > > > > > er
> > > > > > > .r
> > > > > > > ea
> > > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(Ma
> > > > > > > ilSe
> > > > > > > rv
> > > > > > > er
> > > > > > > Ac
> > > > > > > tiveMQClient.java:93)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiv
> > > > > > > eMQC
> > > > > > > li
> > > > > > > en
> > > > > > > tT
> > > > > > > est.java:28)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > > > > ke0(
> > > > > > > > > > > > > > > Nati
> > > > > > > > > > > > > > > ve
> > > > > > > > > > > > > > > Method)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > ke(N
> > > > > > > at
> > > > > > > iv
> > > > > > > eM
> > > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> > > > > > > invo
> > > > > > > ke
> > > > > > > (D
> > > > > > > el
> > > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > > > > >         at
> > > > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> > > > > > > Fram
> > > > > > > ew
> > > > > > > or
> > > > > > > kM
> > > > > > > ethod.java:50)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> > > > > > > ecti
> > > > > > > ve
> > > > > > > Ca
> > > > > > > ll
> > > > > > > able.java:12)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> > > > > > > amew
> > > > > > > or
> > > > > > > kM
> > > > > > > et
> > > > > > > hod.java:47)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(
> > > > > > > Invo
> > > > > > > ke
> > > > > > > Me
> > > > > > > th
> > > > > > > od.java:17)
> > > > > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:3
> > > > > > > > 25)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > 4Cla
> > > > > > > ss
> > > > > > > Ru
> > > > > > > nn
> > > > > > > er.java:78)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > > 4Cla
> > > > > > > ss
> > > > > > > Ru
> > > > > > > nn
> > > > > > > er.java:57)
> > > > > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290
> > > > > > > > )
> > > > > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.jav
> > > > > > > > a:71
> > > > > > > > )
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.ja
> > > > > > > > va:2
> > > > > > > > 88
> > > > > > > > )
> > > > > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.jav
> > > > > > > > a:58
> > > > > > > > )
> > > > > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.jav
> > > > > > > > a:26
> > > > > > > > 8)
> > > > > > > > > > > > > > >         at
> > > > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> > > > > > > un(J
> > > > > > > Un
> > > > > > > it
> > > > > > > 4T
> > > > > > > estReference.java:89)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > > java:41)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > sts(
> > > > > > > Re
> > > > > > > mo
> > > > > > > te
> > > > > > > TestRunner.java:541)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > > sts(
> > > > > > > Re
> > > > > > > mo
> > > > > > > te
> > > > > > > TestRunner.java:763)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> > > > > > > emot
> > > > > > > eT
> > > > > > > es
> > > > > > > tR
> > > > > > > unner.java:463)
> > > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > >
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > > > > Remo
> > > > > > > > > > > > > > > teTe
> > > > > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Justin
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > > > > >
> > > > > > > > wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I try to send and receive a netty ByteBuf
> > > > > > > > > > > > > > > > message, but it
> > > > > > > > fails.
> > > > > > > > > > > > > > > > What I'm doing wrong here? I even don't
> > > > > > > > > > > > > > > > know ist he mistake in sending or receiving!
> > > > > > > > > > > > > > > > I was thinking to use the jms layer, but
> > > > > > > > > > > > > > > > I'm receiving
> > > > > > > the
> > > > > > > > > > > > > > > > data buffer throught a netty buffer and I
> > > > > > > > > > > > > > > > want to avoid
> > > > > > > to
> > > > > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >        public void
> > > > > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > > >                     ClientMessage message
> > > > > > > > > > > > > > > > =
> > > > > > > > session.createMessage(true);
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > > > buf.readableBytes());
> > > > > > > > > > > > > > > >                     ClientProducer
> > > > > > > > > > > > > > > > producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >        public ActiveMQBuffer
> > > > > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > > >                     ClientConsumer
> > > > > > > > > > > > > > > > consumer = session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > > >                     ClientMessage message
> > > > > > > > > > > > > > > > =
> > > > > > > > consumer.receive();
> > > > > > > > > > > > > > > >                     result =
> > > > > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBod
> > > > > > > > > > > > > > > > yBuf
> > > > > > > > > > > > > > > > fe
> > > > > > > > > > > > > > > > rS
> > > > > > > > > > > > > > > > iz
> > > > > > > > > > > > > > > > e());
> > > > > > > > > > > > > > > >
> > > > > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >              return result;
> > > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > > > > >              this.configuration = new
> > > > > > > ConfigurationImpl();
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > this.configuration.addAcceptorConfiguratio
> > > > > > > > > > > > > > > > n("i
> > > > > > > > > > > > > > > > n- vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > > > > >
> > > > > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > > > > >
> > > > > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > this.configuration.addQueueConfiguration(n
> > > > > > > > > > > > > > > > ew
> > > > > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >              this.server = new
> > > > > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > --
> > > > > > > > > > > > > Clebert Suconic
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > Clebert Suconic
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Clebert Suconic
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > > >
> > > > --
> > > > Clebert Suconic
> > > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic


AW: send message

Posted by To...@t-systems.com.
Thank you for the answer, I will go this way!

Is it neccessary to create the session as "transacted=true" in case I want to be sure that the ByteBuf was stored sucessfully?
         session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

How can I check with the JMS client if a particular queue does exists and in case not to create it?
In core api I do this way:

		ClientSession session = this.sessionFactory.createSession(true, true);
		try {
			QueueQuery queueQuery = session.queueQuery(new SimpleString(ACTIVE_MQ_SMTP_QUEUE));
			if (!queueQuery.isExists())
				session.createQueue(new QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE).setDurable(true));
		} finally {
			session.close();
		}


-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Montag, 29. März 2021 15:40
An: users@activemq.apache.org
Betreff: Re: send message

This example here is working with JMS:

https://github.com/apache/activemq-artemis/blob/fe3851ff6d243cc0b58872c5431646fbeb410b41/examples/features/standard/large-message/src/main/java/org/apache/activemq/artemis/jms/example/LargeMessageExample.java


Basically, instead of passing a BufferedInputStream that worked through a File, you could pass in a NettyByteBufferInputStream, and it should work the same:

https://netty.io/4.0/api/io/netty/buffer/ByteBufInputStream.html


I was going to suggest you to write a ByteInputStream yourself when I found one already implemented as part of the Netty library.

On Fri, Mar 26, 2021 at 10:43 AM Clebert Suconic <cl...@gmail.com> wrote:
>
> look at message.setInputStream as you are using the Core API.
>
> if you were using the JMS API there's a property that kind of wraps it 
> into the CoreMessage through the JMS Message.
>
> Since you are using the core api directly look into that property.
> Just implement an InputStream that will read from your ByteBuffer and 
> pass it in.
>
> On Fri, Mar 26, 2021 at 8:48 AM <To...@t-systems.com> wrote:
> >
> > A example would be great!
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Freitag, 26. März 2021 13:26
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > On your case it would make sense if the streaming was not a file but a biffer.  I get it.
> >
> > The optimization here wouldn’t be the copy but it would be not needintg to duplicate the 500MB.  We all thought you had a smaller buffer and did not want the copy.
> >
> > You can pass an InputStream as a property on the streaming.  If you implemented an InputStream that will read from the NettyBuffer.  The body would be read directly into smaller chunks into the Large Message Streaming.
> >
> >
> > I’m not working today.  As a matter of fact I’m using an iPhone 
> > right  now (pardon any typoes please)
> >
> > If you can’t figure it out let me know and I will write you an 
> > example Monday
> >
> > On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:
> >
> > > Not he application is a kind of custom mail server and the 
> > > messages can reach up to 500mb and are received via tcp and a netty smtp handler.
> > > Therefore I have a netty direct buffer already and don't want 
> > > bring the huge messages back into the jvm.
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Donnerstag, 25. März 2021 20:31
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > I assumed the data was already on a file.
> > >
> > > If you passed the file name.  The receiver would receive a message 
> > > where you could either do the opposite. (Pass a file name to steam.
> > > Or just receive steaming)
> > >
> > > At that size of message the optimization of the copy between your 
> > > buffer and a byte array makes little difference.
> > >
> > > On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
> > >
> > > > So you mean I should save the ByteBuffer by myself to a file?
> > > >
> > > > --> and pass it over the property that would stream the file directly.
> > > > (Available on core only)
> > > > What do you mean? I understand that I shall pass the name of the 
> > > > file via a message property, right?
> > > > How would the receiver side looks like?
> > > >
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Donnerstag, 25. März 2021 16:04
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > Sending a message this large will make it to be converted as a 
> > > > large stream and saved as a file on the server anyways...
> > > >
> > > > The copy between ByteBuffer and a byte array would become 
> > > > irrelevant at this point.
> > > >
> > > > If you want to send a large message this big, you could save it 
> > > > to a file, and pass it over the property that would stream the file directly.
> > > > (Available on core only)
> > > >
> > > > And don't convert a large message between protocols.. use a 
> > > > single protocol of your choice.
> > > >
> > > > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > What are you talking about?
> > > > > I want to send byte buffers with the size up to 500MB to a queue!
> > > > > What do you mean with string and micro optimization!
> > > > > The core api fails in my test already with sending/receiving a 
> > > > > simple
> > > > string, yes, a simple test!
> > > > > Does it make sense to have a 500mb native netty buffer 
> > > > > received via wire
> > > > and tunnel it back through the jvm?
> > > > > I don`t think so!
> > > > > Does it make sense to tunnel megabytes of data through a 
> > > > > stream or even
> > > > an byte array through the jvm?
> > > > > Where ist the advantage of jms?
> > > > > Why shall I not use the existing core api functions when the 
> > > > > already
> > > > support a netty buffer?
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Well said, Tim. I was going to say the same thing about 
> > > > > premature
> > > > optimization.
> > > > >
> > > > >
> > > > > Justin
> > > > >
> > > > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain 
> > > > > <tb...@alumni.duke.edu>
> > > wrote:
> > > > >
> > > > > > One thing to keep in mind is that although the code may be 
> > > > > > slightly slower, if it lets you use an API that is more 
> > > > > > favorable (which might mean better documented, more 
> > > > > > portable, more stable across future versions, easier for 
> > > > > > others to maintain because they're already familiar with it, 
> > > > > > or a number of other potential advantages),
> > > > that might be a win.
> > > > > >
> > > > > > Only you know your use case and whether the performance 
> > > > > > advantages of what you're trying to do actually outweigh the 
> > > > > > types of advantages I referenced in the first paragraph. But 
> > > > > > remember that premature optimization is the root of all 
> > > > > > evil, so make sure that your micro-optimization of avoiding 
> > > > > > the creation of a String is really a significant enough 
> > > > > > optimization in the context of your use case to justify the disadvantages of what you're trying to do.
> > > > > >
> > > > > > Tim
> > > > > >
> > > > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic 
> > > > > > <cl...@gmail.com>
> > > > > > wrote:
> > > > > >
> > > > > > > Not on the API itself.
> > > > > > >
> > > > > > > Try the core api example I sent you... and let me know 
> > > > > > > what is different from yours.
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 10:34 AM 
> > > > > > > <To...@t-systems.com>
> > > wrote:
> > > > > > > >
> > > > > > > > I want to use the jms layer, but I've a netty 
> > > > > > > > application and I want to
> > > > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > > > I think it makes no sense to convert it back from a 
> > > > > > > > native buffer into
> > > > > > a
> > > > > > > byte array or stream and tunnel this throught the jvm!
> > > > > > > >
> > > > > > > > Is there a way to use a ByteBuf with jms?
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > You were supposed to call reset right before sending though...
> > > > > > > > but I
> > > > > > did
> > > > > > > not need it on my test.. I will post a link...
> > > > > > > >
> > > > > > > > Anyway, if you use the JMS API, the JMS layer is very 
> > > > > > > > thin, and I don't
> > > > > > > think it would affect your performance in any way. you 
> > > > > > > could create a BytesMessage and all the detail would be 
> > > > > > > hidden away from the internal
> > > > > > API.
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > > > clebert.suconic@gmail.com> wrote:
> > > > > > > > >
> > > > > > > > > I'm adding a test doing exactly what you did, and it's
> > > working...
> > > > > > > > >
> > > > > > > > > give me 10 minutes and I will post a link here...
> > > > > > > > >
> > > > > > > > > On Tue, Mar 23, 2021 at 9:56 AM 
> > > > > > > > > <To...@t-systems.com>
> > > > wrote:
> > > > > > > > > >
> > > > > > > > > > Same Issue!
> > > > > > > > > >         public void sendMessageToSmtpQueue(String 
> > > > > > > > > > text) throws
> > > > > > > ActiveMQException {
> > > > > > > > > >                 ClientSession session =
> > > > > > > this.sessionFactory.createSession();
> > > > > > > > > >                 try {
> > > > > > > > > >                         session.start();
> > > > > > > > > >                         ClientMessage message =
> > > > > > > session.createMessage(true);
> > > > > > > > > >
> > > >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > > > >
> > > >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > > > >
> > > >  message.getBodyBuffer().writeString(text);
> > > > > > > > > >                         ClientProducer producer =
> > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                         producer.send(message);
> > > > > > > > > >                 } finally {
> > > > > > > > > >                         session.close();
> > > > > > > > > >                 }
> > > > > > > > > >         }
> > > > > > > > > >
> > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading 
> > > > > > > > > > in simpleString,
> > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > Stri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:185)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > Stri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:173)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > rapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > rapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > >
> > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(Ma
> > > > > > ilSe
> > > > > > rv
> > > > > > er
> > > > > > Ac
> > > > > > tiveMQClient.java:94)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > >
> > > > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(Mail
> > > > > > Serv
> > > > > > er
> > > > > > Ac
> > > > > > ti
> > > > > > veMQClientTest.java:37)
> > > > > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.in
> > > > > > > voke
> > > > > > > 0(
> > > > > > > Na
> > > > > > > ti
> > > > > > > ve
> > > > > > > Method)
> > > > > > > > > >         at
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > ke(N
> > > > > > at
> > > > > > iv
> > > > > > eM
> > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > >         at
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> > > > > > invo
> > > > > > ke
> > > > > > (D
> > > > > > el
> > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > >         at
> > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> > > > > > Fram
> > > > > > ew
> > > > > > or
> > > > > > kM
> > > > > > ethod.java:50)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> > > > > > ecti
> > > > > > ve
> > > > > > Ca
> > > > > > ll
> > > > > > able.java:12)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> > > > > > amew
> > > > > > or
> > > > > > kM
> > > > > > et
> > > > > > hod.java:47)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(
> > > > > > Invo
> > > > > > ke
> > > > > > Me
> > > > > > th
> > > > > > od.java:17)
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:3
> > > > > > > 25)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > 4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:78)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > 4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:57)
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.jav
> > > > > > > a:71
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.ja
> > > > > > > va:2
> > > > > > > 88
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.jav
> > > > > > > a:58
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.jav
> > > > > > > a:26
> > > > > > > 8)
> > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> > > > > > un(J
> > > > > > Un
> > > > > > it
> > > > > > 4T
> > > > > > estReference.java:89)
> > > > > > > > > >         at
> > > > > > >
> > > > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > java:41)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > sts(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:541)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > sts(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:763)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> > > > > > emot
> > > > > > eT
> > > > > > es
> > > > > > tR
> > > > > > unner.java:463)
> > > > > > > > > >         at
> > > > > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > Remo
> > > > > > te
> > > > > > Te
> > > > > > > > > > stRunner.java:209)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > Can you try calling
> > > > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > > > before the send?
> > > > > > > > > >
> > > > > > > > > > if that does not work I will try your code and see 
> > > > > > > > > > what
> > > > happens.
> > > > > > > > > > (Let me know if doesn't please)
> > > > > > > > > >
> > > > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully 
> > > > > > > > > > <ga...@gmail.com>
> > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > maybe take inspiration from
> > > > > > > > > > >
> > > > > > https://github.com/apache/activemq-artemis/blob/master/tests
> > > > > > /int
> > > > > > eg
> > > > > > > > > > > rati
> > > > > > > > > > >
> > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/int
> > > > > > egra
> > > > > > ti
> > > > > > > > > > > on/c lient/MessageBufferTest.java that passes a 
> > > > > > > > > > > string, but there are corresponding byte[] or 
> > > > > > > > > > > buffer variants in the api. If you want to skip 
> > > > > > > > > > > the decoding, to access the raw buffer, you need 
> > > > > > > > > > > to parse the type to get to the
> > > > appropriate part of the buffer.
> > > > > > > > > > > There are loads of usage examples in the tests and 
> > > > > > > > > > > they all work, start there and break it as you go.
> > > > > > > > > > >
> > > > > > > > > > > the issue is the wire level encoding that the 
> > > > > > > > > > > client does, the
> > > > > > JMS
> > > > > > > > > > > api hides this, as do the typed accessors, but you 
> > > > > > > > > > > can get direct access to the encoded buffers via 
> > > > > > > > > > > the core api as you are doing but you need to be 
> > > > > > > > > > > type aware, for example a string can be utf-8 
> > > > > > > > > > > encoded or it can be raw bytes on the wire, 
> > > > > > > > > > > depending on the size and chars, the encoding 
> > > > > > > > > > > handles and hides this detail. But if you go for 
> > > > > > > > > > > direct
> > > > access, you need to be aware of the encoding.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > On Tue, 23 Mar 2021 at 07:37, 
> > > > > > > > > > > <To...@t-systems.com>
> > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > > > >
> > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > >
> > > > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > > > >
> > > > > > > > > > > > or if you really want to use the core API, use 
> > > > > > > > > > > > the
> > > > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > > > >
> > > > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram 
> > > > > > > > > > > > <
> > > > > > > jbertram@apache.org> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > The stack-trace indicates you're invoking the
> > > > "readString"
> > > > > > > > > > > > > method on line
> > > > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I 
> > > > > > > > > > > > > don't see that
> > > > > > call
> > > > > > > > > > > > > in the code you pasted. Therefore, that 
> > > > > > > > > > > > > stack-trace doesn't seem correct. Can you clarify this?
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Justin
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, 
> > > > > > > > > > > > > Erwin <er...@cgi.com>
> > > > > > > > > > > > > wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > > Fyi:
> > > > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) 
> > > > > > > > > > > > > > = "tive"(ascii
> > > > > > > > > > > > > > text) And "tive" is likely part of the 
> > > > > > > > > > > > > > string
> > > > "ActiveMQ"?
> > > > > > > > > > > > > > e.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com 
> > > > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > > > attachments unless
> > > > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > > > n’ouvrez
> > > > > > > aucune pièce
> > > > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un 
> > > > > > > > > > > > > > expéditeur
> > > > > > fiable,
> > > > > > > > > > > > > > ou que vous ayez l'assurance que le contenu 
> > > > > > > > > > > > > > provient d'une
> > > > > > > source sûre.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > While sending / receiving a text message I 
> > > > > > > > > > > > > > get this
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error 
> > > > > > > > > > > > > > reading in simpleString,
> > > > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > Stri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:185)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimple
> > > > > > Stri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:173)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > rapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferW
> > > > > > rapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(Ma
> > > > > > ilSe
> > > > > > rv
> > > > > > er
> > > > > > Ac
> > > > > > tiveMQClient.java:93)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiv
> > > > > > eMQC
> > > > > > li
> > > > > > en
> > > > > > tT
> > > > > > est.java:28)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > > > ke0(
> > > > > > > > > > > > > > Nati
> > > > > > > > > > > > > > ve
> > > > > > > > > > > > > > Method)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > ke(N
> > > > > > at
> > > > > > iv
> > > > > > eM
> > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> > > > > > invo
> > > > > > ke
> > > > > > (D
> > > > > > el
> > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > > > >         at
> > > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> > > > > > Fram
> > > > > > ew
> > > > > > or
> > > > > > kM
> > > > > > ethod.java:50)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> > > > > > ecti
> > > > > > ve
> > > > > > Ca
> > > > > > ll
> > > > > > able.java:12)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> > > > > > amew
> > > > > > or
> > > > > > kM
> > > > > > et
> > > > > > hod.java:47)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(
> > > > > > Invo
> > > > > > ke
> > > > > > Me
> > > > > > th
> > > > > > od.java:17)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:3
> > > > > > > 25)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > 4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:78)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> > > > > > 4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:57)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.jav
> > > > > > > a:71
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.ja
> > > > > > > va:2
> > > > > > > 88
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.jav
> > > > > > > a:58
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.jav
> > > > > > > a:26
> > > > > > > 8)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> > > > > > un(J
> > > > > > Un
> > > > > > it
> > > > > > 4T
> > > > > > estReference.java:89)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > java:41)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > sts(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:541)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> > > > > > sts(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:763)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> > > > > > emot
> > > > > > eT
> > > > > > es
> > > > > > tR
> > > > > > unner.java:463)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > > > Remo
> > > > > > > > > > > > > > teTe
> > > > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Justin
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM 
> > > > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > > > >
> > > > > > > wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I try to send and receive a netty ByteBuf 
> > > > > > > > > > > > > > > message, but it
> > > > > > > fails.
> > > > > > > > > > > > > > > What I'm doing wrong here? I even don't 
> > > > > > > > > > > > > > > know ist he mistake in sending or receiving!
> > > > > > > > > > > > > > > I was thinking to use the jms layer, but 
> > > > > > > > > > > > > > > I'm receiving
> > > > > > the
> > > > > > > > > > > > > > > data buffer throught a netty buffer and I 
> > > > > > > > > > > > > > > want to avoid
> > > > > > to
> > > > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >        public void 
> > > > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > >                     ClientMessage message 
> > > > > > > > > > > > > > > =
> > > > > > > session.createMessage(true);
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > > buf.readableBytes());
> > > > > > > > > > > > > > >                     ClientProducer 
> > > > > > > > > > > > > > > producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >        public ActiveMQBuffer
> > > > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > >                     ClientConsumer 
> > > > > > > > > > > > > > > consumer = session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > >                     ClientMessage message 
> > > > > > > > > > > > > > > =
> > > > > > > consumer.receive();
> > > > > > > > > > > > > > >                     result = 
> > > > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBod
> > > > > > > > > > > > > > > yBuf
> > > > > > > > > > > > > > > fe
> > > > > > > > > > > > > > > rS
> > > > > > > > > > > > > > > iz
> > > > > > > > > > > > > > > e());
> > > > > > > > > > > > > > >
> > > > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >              return result;
> > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > > > >              this.configuration = new
> > > > > > ConfigurationImpl();
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > this.configuration.addAcceptorConfiguratio
> > > > > > > > > > > > > > > n("i
> > > > > > > > > > > > > > > n- vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > > > >
> > > > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > > > >
> > > > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > this.configuration.addQueueConfiguration(n
> > > > > > > > > > > > > > > ew 
> > > > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >              this.server = new
> > > > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > --
> > > > > > > > > > > > Clebert Suconic
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Clebert Suconic
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > > >
> > > --
> > > Clebert Suconic
> > >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
This example here is working with JMS:

https://github.com/apache/activemq-artemis/blob/fe3851ff6d243cc0b58872c5431646fbeb410b41/examples/features/standard/large-message/src/main/java/org/apache/activemq/artemis/jms/example/LargeMessageExample.java


Basically, instead of passing a BufferedInputStream that worked
through a File, you could pass in a NettyByteBufferInputStream, and it
should work the same:

https://netty.io/4.0/api/io/netty/buffer/ByteBufInputStream.html


I was going to suggest you to write a ByteInputStream yourself when I
found one already implemented as part of the Netty library.

On Fri, Mar 26, 2021 at 10:43 AM Clebert Suconic
<cl...@gmail.com> wrote:
>
> look at message.setInputStream as you are using the Core API.
>
> if you were using the JMS API there's a property that kind of wraps it
> into the CoreMessage through the JMS Message.
>
> Since you are using the core api directly look into that property.
> Just implement an InputStream that will read from your ByteBuffer and
> pass it in.
>
> On Fri, Mar 26, 2021 at 8:48 AM <To...@t-systems.com> wrote:
> >
> > A example would be great!
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Freitag, 26. März 2021 13:26
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > On your case it would make sense if the streaming was not a file but a biffer.  I get it.
> >
> > The optimization here wouldn’t be the copy but it would be not needintg to duplicate the 500MB.  We all thought you had a smaller buffer and did not want the copy.
> >
> > You can pass an InputStream as a property on the streaming.  If you implemented an InputStream that will read from the NettyBuffer.  The body would be read directly into smaller chunks into the Large Message Streaming.
> >
> >
> > I’m not working today.  As a matter of fact I’m using an iPhone right  now (pardon any typoes please)
> >
> > If you can’t figure it out let me know and I will write you an example Monday
> >
> > On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:
> >
> > > Not he application is a kind of custom mail server and the messages
> > > can reach up to 500mb and are received via tcp and a netty smtp handler.
> > > Therefore I have a netty direct buffer already and don't want bring
> > > the huge messages back into the jvm.
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Donnerstag, 25. März 2021 20:31
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > I assumed the data was already on a file.
> > >
> > > If you passed the file name.  The receiver would receive a message
> > > where you could either do the opposite. (Pass a file name to steam.
> > > Or just receive steaming)
> > >
> > > At that size of message the optimization of the copy between your
> > > buffer and a byte array makes little difference.
> > >
> > > On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
> > >
> > > > So you mean I should save the ByteBuffer by myself to a file?
> > > >
> > > > --> and pass it over the property that would stream the file directly.
> > > > (Available on core only)
> > > > What do you mean? I understand that I shall pass the name of the
> > > > file via a message property, right?
> > > > How would the receiver side looks like?
> > > >
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Donnerstag, 25. März 2021 16:04
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > Sending a message this large will make it to be converted as a large
> > > > stream and saved as a file on the server anyways...
> > > >
> > > > The copy between ByteBuffer and a byte array would become irrelevant
> > > > at this point.
> > > >
> > > > If you want to send a large message this big, you could save it to a
> > > > file, and pass it over the property that would stream the file directly.
> > > > (Available on core only)
> > > >
> > > > And don't convert a large message between protocols.. use a single
> > > > protocol of your choice.
> > > >
> > > > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > What are you talking about?
> > > > > I want to send byte buffers with the size up to 500MB to a queue!
> > > > > What do you mean with string and micro optimization!
> > > > > The core api fails in my test already with sending/receiving a
> > > > > simple
> > > > string, yes, a simple test!
> > > > > Does it make sense to have a 500mb native netty buffer received
> > > > > via wire
> > > > and tunnel it back through the jvm?
> > > > > I don`t think so!
> > > > > Does it make sense to tunnel megabytes of data through a stream or
> > > > > even
> > > > an byte array through the jvm?
> > > > > Where ist the advantage of jms?
> > > > > Why shall I not use the existing core api functions when the
> > > > > already
> > > > support a netty buffer?
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Well said, Tim. I was going to say the same thing about premature
> > > > optimization.
> > > > >
> > > > >
> > > > > Justin
> > > > >
> > > > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu>
> > > wrote:
> > > > >
> > > > > > One thing to keep in mind is that although the code may be
> > > > > > slightly slower, if it lets you use an API that is more
> > > > > > favorable (which might mean better documented, more portable,
> > > > > > more stable across future versions, easier for others to
> > > > > > maintain because they're already familiar with it, or a number
> > > > > > of other potential advantages),
> > > > that might be a win.
> > > > > >
> > > > > > Only you know your use case and whether the performance
> > > > > > advantages of what you're trying to do actually outweigh the
> > > > > > types of advantages I referenced in the first paragraph. But
> > > > > > remember that premature optimization is the root of all evil, so
> > > > > > make sure that your micro-optimization of avoiding the creation
> > > > > > of a String is really a significant enough optimization in the
> > > > > > context of your use case to justify the disadvantages of what you're trying to do.
> > > > > >
> > > > > > Tim
> > > > > >
> > > > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > > > > > <cl...@gmail.com>
> > > > > > wrote:
> > > > > >
> > > > > > > Not on the API itself.
> > > > > > >
> > > > > > > Try the core api example I sent you... and let me know what is
> > > > > > > different from yours.
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com>
> > > wrote:
> > > > > > > >
> > > > > > > > I want to use the jms layer, but I've a netty application
> > > > > > > > and I want to
> > > > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > > > I think it makes no sense to convert it back from a native
> > > > > > > > buffer into
> > > > > > a
> > > > > > > byte array or stream and tunnel this throught the jvm!
> > > > > > > >
> > > > > > > > Is there a way to use a ByteBuf with jms?
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > You were supposed to call reset right before sending though...
> > > > > > > > but I
> > > > > > did
> > > > > > > not need it on my test.. I will post a link...
> > > > > > > >
> > > > > > > > Anyway, if you use the JMS API, the JMS layer is very thin,
> > > > > > > > and I don't
> > > > > > > think it would affect your performance in any way. you could
> > > > > > > create a BytesMessage and all the detail would be hidden away
> > > > > > > from the internal
> > > > > > API.
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > > > clebert.suconic@gmail.com> wrote:
> > > > > > > > >
> > > > > > > > > I'm adding a test doing exactly what you did, and it's
> > > working...
> > > > > > > > >
> > > > > > > > > give me 10 minutes and I will post a link here...
> > > > > > > > >
> > > > > > > > > On Tue, Mar 23, 2021 at 9:56 AM
> > > > > > > > > <To...@t-systems.com>
> > > > wrote:
> > > > > > > > > >
> > > > > > > > > > Same Issue!
> > > > > > > > > >         public void sendMessageToSmtpQueue(String text)
> > > > > > > > > > throws
> > > > > > > ActiveMQException {
> > > > > > > > > >                 ClientSession session =
> > > > > > > this.sessionFactory.createSession();
> > > > > > > > > >                 try {
> > > > > > > > > >                         session.start();
> > > > > > > > > >                         ClientMessage message =
> > > > > > > session.createMessage(true);
> > > > > > > > > >
> > > >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > > > >
> > > >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > > > >
> > > >  message.getBodyBuffer().writeString(text);
> > > > > > > > > >                         ClientProducer producer =
> > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                         producer.send(message);
> > > > > > > > > >                 } finally {
> > > > > > > > > >                         session.close();
> > > > > > > > > >                 }
> > > > > > > > > >         }
> > > > > > > > > >
> > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > > simpleString,
> > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:185)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:173)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > >
> > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailSe
> > > > > > rv
> > > > > > er
> > > > > > Ac
> > > > > > tiveMQClient.java:94)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > >
> > > > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServ
> > > > > > er
> > > > > > Ac
> > > > > > ti
> > > > > > veMQClientTest.java:37)
> > > > > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke
> > > > > > > 0(
> > > > > > > Na
> > > > > > > ti
> > > > > > > ve
> > > > > > > Method)
> > > > > > > > > >         at
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(N
> > > > > > at
> > > > > > iv
> > > > > > eM
> > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > >         at
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invo
> > > > > > ke
> > > > > > (D
> > > > > > el
> > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > >         at
> > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Fram
> > > > > > ew
> > > > > > or
> > > > > > kM
> > > > > > ethod.java:50)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflecti
> > > > > > ve
> > > > > > Ca
> > > > > > ll
> > > > > > able.java:12)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framew
> > > > > > or
> > > > > > kM
> > > > > > et
> > > > > > hod.java:47)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invo
> > > > > > ke
> > > > > > Me
> > > > > > th
> > > > > > od.java:17)
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:78)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:57)
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:2
> > > > > > > 88
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58
> > > > > > > )
> > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:26
> > > > > > > 8)
> > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J
> > > > > > Un
> > > > > > it
> > > > > > 4T
> > > > > > estReference.java:89)
> > > > > > > > > >         at
> > > > > > >
> > > > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > java:41)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:541)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:763)
> > > > > > > > > >         at
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Remot
> > > > > > eT
> > > > > > es
> > > > > > tR
> > > > > > unner.java:463)
> > > > > > > > > >         at
> > > > > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > > > te
> > > > > > Te
> > > > > > > > > > stRunner.java:209)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > Can you try calling
> > > > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > > > before the send?
> > > > > > > > > >
> > > > > > > > > > if that does not work I will try your code and see what
> > > > happens.
> > > > > > > > > > (Let me know if doesn't please)
> > > > > > > > > >
> > > > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > > > > > <ga...@gmail.com>
> > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > maybe take inspiration from
> > > > > > > > > > >
> > > > > > https://github.com/apache/activemq-artemis/blob/master/tests/int
> > > > > > eg
> > > > > > > > > > > rati
> > > > > > > > > > >
> > > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integra
> > > > > > ti
> > > > > > > > > > > on/c lient/MessageBufferTest.java that passes a
> > > > > > > > > > > string, but there are corresponding byte[] or buffer
> > > > > > > > > > > variants in the api. If you want to skip the decoding,
> > > > > > > > > > > to access the raw buffer, you need to parse the type
> > > > > > > > > > > to get to the
> > > > appropriate part of the buffer.
> > > > > > > > > > > There are loads of usage examples in the tests and
> > > > > > > > > > > they all work, start there and break it as you go.
> > > > > > > > > > >
> > > > > > > > > > > the issue is the wire level encoding that the client
> > > > > > > > > > > does, the
> > > > > > JMS
> > > > > > > > > > > api hides this, as do the typed accessors, but you can
> > > > > > > > > > > get direct access to the encoded buffers via the core
> > > > > > > > > > > api as you are doing but you need to be type aware,
> > > > > > > > > > > for example a string can be utf-8 encoded or it can be
> > > > > > > > > > > raw bytes on the wire, depending on the size and
> > > > > > > > > > > chars, the encoding handles and hides this detail. But
> > > > > > > > > > > if you go for direct
> > > > access, you need to be aware of the encoding.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > On Tue, 23 Mar 2021 at 07:37,
> > > > > > > > > > > <To...@t-systems.com>
> > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > > > >
> > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > >
> > > > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > > > >
> > > > > > > > > > > > or if you really want to use the core API, use the
> > > > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > > > >
> > > > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > > > > jbertram@apache.org> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > The stack-trace indicates you're invoking the
> > > > "readString"
> > > > > > > > > > > > > method on line
> > > > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't
> > > > > > > > > > > > > see that
> > > > > > call
> > > > > > > > > > > > > in the code you pasted. Therefore, that
> > > > > > > > > > > > > stack-trace doesn't seem correct. Can you clarify this?
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Justin
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > > > > wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > > Fyi:
> > > > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) =
> > > > > > > > > > > > > > "tive"(ascii
> > > > > > > > > > > > > > text) And "tive" is likely part of the string
> > > > "ActiveMQ"?
> > > > > > > > > > > > > > e.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > > > attachments unless
> > > > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > > > n’ouvrez
> > > > > > > aucune pièce
> > > > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un
> > > > > > > > > > > > > > expéditeur
> > > > > > fiable,
> > > > > > > > > > > > > > ou que vous ayez l'assurance que le contenu
> > > > > > > > > > > > > > provient d'une
> > > > > > > source sûre.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > While sending / receiving a text message I get
> > > > > > > > > > > > > > this
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error
> > > > > > > > > > > > > > reading in simpleString,
> > > > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:185)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > > ng
> > > > > > (S
> > > > > > im
> > > > > > pleString.java:173)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > > er
> > > > > > .r
> > > > > > ea
> > > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailSe
> > > > > > rv
> > > > > > er
> > > > > > Ac
> > > > > > tiveMQClient.java:93)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQC
> > > > > > li
> > > > > > en
> > > > > > tT
> > > > > > est.java:28)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > > > ke0(
> > > > > > > > > > > > > > Nati
> > > > > > > > > > > > > > ve
> > > > > > > > > > > > > > Method)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(N
> > > > > > at
> > > > > > iv
> > > > > > eM
> > > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invo
> > > > > > ke
> > > > > > (D
> > > > > > el
> > > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > > > >         at
> > > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Fram
> > > > > > ew
> > > > > > or
> > > > > > kM
> > > > > > ethod.java:50)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflecti
> > > > > > ve
> > > > > > Ca
> > > > > > ll
> > > > > > able.java:12)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framew
> > > > > > or
> > > > > > kM
> > > > > > et
> > > > > > hod.java:47)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invo
> > > > > > ke
> > > > > > Me
> > > > > > th
> > > > > > od.java:17)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:78)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > > ss
> > > > > > Ru
> > > > > > nn
> > > > > > er.java:57)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:2
> > > > > > > 88
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58
> > > > > > > )
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:26
> > > > > > > 8)
> > > > > > > > > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J
> > > > > > Un
> > > > > > it
> > > > > > 4T
> > > > > > estReference.java:89)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > > java:41)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:541)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > > Re
> > > > > > mo
> > > > > > te
> > > > > > TestRunner.java:763)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Remot
> > > > > > eT
> > > > > > es
> > > > > > tR
> > > > > > unner.java:463)
> > > > > > > > > > > > > >         at
> > > > > > > > > > > > > >
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > > > Remo
> > > > > > > > > > > > > > teTe
> > > > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Justin
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > > > >
> > > > > > > wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I try to send and receive a netty ByteBuf
> > > > > > > > > > > > > > > message, but it
> > > > > > > fails.
> > > > > > > > > > > > > > > What I'm doing wrong here? I even don't know
> > > > > > > > > > > > > > > ist he mistake in sending or receiving!
> > > > > > > > > > > > > > > I was thinking to use the jms layer, but I'm
> > > > > > > > > > > > > > > receiving
> > > > > > the
> > > > > > > > > > > > > > > data buffer throught a netty buffer and I want
> > > > > > > > > > > > > > > to avoid
> > > > > > to
> > > > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >        public void
> > > > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > >                     ClientMessage message =
> > > > > > > session.createMessage(true);
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > > buf.readableBytes());
> > > > > > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >        public ActiveMQBuffer
> > > > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > > > >              ClientSession session =
> > > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > > >                     ClientMessage message =
> > > > > > > consumer.receive();
> > > > > > > > > > > > > > >                     result =
> > > > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBuf
> > > > > > > > > > > > > > > fe
> > > > > > > > > > > > > > > rS
> > > > > > > > > > > > > > > iz
> > > > > > > > > > > > > > > e());
> > > > > > > > > > > > > > >
> > > > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > > >              }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >              return result;
> > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > > > >              this.configuration = new
> > > > > > ConfigurationImpl();
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > this.configuration.addAcceptorConfiguration("i
> > > > > > > > > > > > > > > n- vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > > > >
> > > > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > > > >
> > > > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >              this.server = new
> > > > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > > > >        }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > --
> > > > > > > > > > > > Clebert Suconic
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Clebert Suconic
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > > >
> > > --
> > > Clebert Suconic
> > >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
look at message.setInputStream as you are using the Core API.

if you were using the JMS API there's a property that kind of wraps it
into the CoreMessage through the JMS Message.

Since you are using the core api directly look into that property.
Just implement an InputStream that will read from your ByteBuffer and
pass it in.

On Fri, Mar 26, 2021 at 8:48 AM <To...@t-systems.com> wrote:
>
> A example would be great!
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Freitag, 26. März 2021 13:26
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> On your case it would make sense if the streaming was not a file but a biffer.  I get it.
>
> The optimization here wouldn’t be the copy but it would be not needintg to duplicate the 500MB.  We all thought you had a smaller buffer and did not want the copy.
>
> You can pass an InputStream as a property on the streaming.  If you implemented an InputStream that will read from the NettyBuffer.  The body would be read directly into smaller chunks into the Large Message Streaming.
>
>
> I’m not working today.  As a matter of fact I’m using an iPhone right  now (pardon any typoes please)
>
> If you can’t figure it out let me know and I will write you an example Monday
>
> On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:
>
> > Not he application is a kind of custom mail server and the messages
> > can reach up to 500mb and are received via tcp and a netty smtp handler.
> > Therefore I have a netty direct buffer already and don't want bring
> > the huge messages back into the jvm.
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Donnerstag, 25. März 2021 20:31
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > I assumed the data was already on a file.
> >
> > If you passed the file name.  The receiver would receive a message
> > where you could either do the opposite. (Pass a file name to steam.
> > Or just receive steaming)
> >
> > At that size of message the optimization of the copy between your
> > buffer and a byte array makes little difference.
> >
> > On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
> >
> > > So you mean I should save the ByteBuffer by myself to a file?
> > >
> > > --> and pass it over the property that would stream the file directly.
> > > (Available on core only)
> > > What do you mean? I understand that I shall pass the name of the
> > > file via a message property, right?
> > > How would the receiver side looks like?
> > >
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Donnerstag, 25. März 2021 16:04
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > Sending a message this large will make it to be converted as a large
> > > stream and saved as a file on the server anyways...
> > >
> > > The copy between ByteBuffer and a byte array would become irrelevant
> > > at this point.
> > >
> > > If you want to send a large message this big, you could save it to a
> > > file, and pass it over the property that would stream the file directly.
> > > (Available on core only)
> > >
> > > And don't convert a large message between protocols.. use a single
> > > protocol of your choice.
> > >
> > > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > > >
> > > > What are you talking about?
> > > > I want to send byte buffers with the size up to 500MB to a queue!
> > > > What do you mean with string and micro optimization!
> > > > The core api fails in my test already with sending/receiving a
> > > > simple
> > > string, yes, a simple test!
> > > > Does it make sense to have a 500mb native netty buffer received
> > > > via wire
> > > and tunnel it back through the jvm?
> > > > I don`t think so!
> > > > Does it make sense to tunnel megabytes of data through a stream or
> > > > even
> > > an byte array through the jvm?
> > > > Where ist the advantage of jms?
> > > > Why shall I not use the existing core api functions when the
> > > > already
> > > support a netty buffer?
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Justin Bertram <jb...@apache.org>
> > > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > Well said, Tim. I was going to say the same thing about premature
> > > optimization.
> > > >
> > > >
> > > > Justin
> > > >
> > > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu>
> > wrote:
> > > >
> > > > > One thing to keep in mind is that although the code may be
> > > > > slightly slower, if it lets you use an API that is more
> > > > > favorable (which might mean better documented, more portable,
> > > > > more stable across future versions, easier for others to
> > > > > maintain because they're already familiar with it, or a number
> > > > > of other potential advantages),
> > > that might be a win.
> > > > >
> > > > > Only you know your use case and whether the performance
> > > > > advantages of what you're trying to do actually outweigh the
> > > > > types of advantages I referenced in the first paragraph. But
> > > > > remember that premature optimization is the root of all evil, so
> > > > > make sure that your micro-optimization of avoiding the creation
> > > > > of a String is really a significant enough optimization in the
> > > > > context of your use case to justify the disadvantages of what you're trying to do.
> > > > >
> > > > > Tim
> > > > >
> > > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > > > > <cl...@gmail.com>
> > > > > wrote:
> > > > >
> > > > > > Not on the API itself.
> > > > > >
> > > > > > Try the core api example I sent you... and let me know what is
> > > > > > different from yours.
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com>
> > wrote:
> > > > > > >
> > > > > > > I want to use the jms layer, but I've a netty application
> > > > > > > and I want to
> > > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > > I think it makes no sense to convert it back from a native
> > > > > > > buffer into
> > > > > a
> > > > > > byte array or stream and tunnel this throught the jvm!
> > > > > > >
> > > > > > > Is there a way to use a ByteBuf with jms?
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > You were supposed to call reset right before sending though...
> > > > > > > but I
> > > > > did
> > > > > > not need it on my test.. I will post a link...
> > > > > > >
> > > > > > > Anyway, if you use the JMS API, the JMS layer is very thin,
> > > > > > > and I don't
> > > > > > think it would affect your performance in any way. you could
> > > > > > create a BytesMessage and all the detail would be hidden away
> > > > > > from the internal
> > > > > API.
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > > clebert.suconic@gmail.com> wrote:
> > > > > > > >
> > > > > > > > I'm adding a test doing exactly what you did, and it's
> > working...
> > > > > > > >
> > > > > > > > give me 10 minutes and I will post a link here...
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021 at 9:56 AM
> > > > > > > > <To...@t-systems.com>
> > > wrote:
> > > > > > > > >
> > > > > > > > > Same Issue!
> > > > > > > > >         public void sendMessageToSmtpQueue(String text)
> > > > > > > > > throws
> > > > > > ActiveMQException {
> > > > > > > > >                 ClientSession session =
> > > > > > this.sessionFactory.createSession();
> > > > > > > > >                 try {
> > > > > > > > >                         session.start();
> > > > > > > > >                         ClientMessage message =
> > > > > > session.createMessage(true);
> > > > > > > > >
> > >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > > >
> > >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > > >
> > >  message.getBodyBuffer().writeString(text);
> > > > > > > > >                         ClientProducer producer =
> > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > >                         producer.send(message);
> > > > > > > > >                 } finally {
> > > > > > > > >                         session.close();
> > > > > > > > >                 }
> > > > > > > > >         }
> > > > > > > > >
> > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > simpleString,
> > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > >         at
> > > > > >
> > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > ng
> > > > > (S
> > > > > im
> > > > > pleString.java:185)
> > > > > > > > >         at
> > > > > >
> > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > ng
> > > > > (S
> > > > > im
> > > > > pleString.java:173)
> > > > > > > > >         at
> > > > > >
> > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > er
> > > > > .r
> > > > > ea
> > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > >         at
> > > > > >
> > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > er
> > > > > .r
> > > > > ea
> > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > >
> > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailSe
> > > > > rv
> > > > > er
> > > > > Ac
> > > > > tiveMQClient.java:94)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > >
> > > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServ
> > > > > er
> > > > > Ac
> > > > > ti
> > > > > veMQClientTest.java:37)
> > > > > > > > >         at
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke
> > > > > > 0(
> > > > > > Na
> > > > > > ti
> > > > > > ve
> > > > > > Method)
> > > > > > > > >         at
> > > > > >
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(N
> > > > > at
> > > > > iv
> > > > > eM
> > > > > ethodAccessorImpl.java:62)
> > > > > > > > >         at
> > > > > >
> > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invo
> > > > > ke
> > > > > (D
> > > > > el
> > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > >         at
> > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > >         at
> > > > > >
> > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Fram
> > > > > ew
> > > > > or
> > > > > kM
> > > > > ethod.java:50)
> > > > > > > > >         at
> > > > > >
> > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflecti
> > > > > ve
> > > > > Ca
> > > > > ll
> > > > > able.java:12)
> > > > > > > > >         at
> > > > > >
> > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framew
> > > > > or
> > > > > kM
> > > > > et
> > > > > hod.java:47)
> > > > > > > > >         at
> > > > > >
> > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invo
> > > > > ke
> > > > > Me
> > > > > th
> > > > > od.java:17)
> > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > >         at
> > > > > >
> > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > ss
> > > > > Ru
> > > > > nn
> > > > > er.java:78)
> > > > > > > > >         at
> > > > > >
> > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > ss
> > > > > Ru
> > > > > nn
> > > > > er.java:57)
> > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71
> > > > > > )
> > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:2
> > > > > > 88
> > > > > > )
> > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58
> > > > > > )
> > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:26
> > > > > > 8)
> > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > >         at
> > > > > >
> > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J
> > > > > Un
> > > > > it
> > > > > 4T
> > > > > estReference.java:89)
> > > > > > > > >         at
> > > > > >
> > > > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > java:41)
> > > > > > > > >         at
> > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > Re
> > > > > mo
> > > > > te
> > > > > TestRunner.java:541)
> > > > > > > > >         at
> > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > Re
> > > > > mo
> > > > > te
> > > > > TestRunner.java:763)
> > > > > > > > >         at
> > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Remot
> > > > > eT
> > > > > es
> > > > > tR
> > > > > unner.java:463)
> > > > > > > > >         at
> > > > > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > > te
> > > > > Te
> > > > > > > > > stRunner.java:209)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > Can you try calling
> > > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > > before the send?
> > > > > > > > >
> > > > > > > > > if that does not work I will try your code and see what
> > > happens.
> > > > > > > > > (Let me know if doesn't please)
> > > > > > > > >
> > > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > > > > <ga...@gmail.com>
> > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > maybe take inspiration from
> > > > > > > > > >
> > > > > https://github.com/apache/activemq-artemis/blob/master/tests/int
> > > > > eg
> > > > > > > > > > rati
> > > > > > > > > >
> > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integra
> > > > > ti
> > > > > > > > > > on/c lient/MessageBufferTest.java that passes a
> > > > > > > > > > string, but there are corresponding byte[] or buffer
> > > > > > > > > > variants in the api. If you want to skip the decoding,
> > > > > > > > > > to access the raw buffer, you need to parse the type
> > > > > > > > > > to get to the
> > > appropriate part of the buffer.
> > > > > > > > > > There are loads of usage examples in the tests and
> > > > > > > > > > they all work, start there and break it as you go.
> > > > > > > > > >
> > > > > > > > > > the issue is the wire level encoding that the client
> > > > > > > > > > does, the
> > > > > JMS
> > > > > > > > > > api hides this, as do the typed accessors, but you can
> > > > > > > > > > get direct access to the encoded buffers via the core
> > > > > > > > > > api as you are doing but you need to be type aware,
> > > > > > > > > > for example a string can be utf-8 encoded or it can be
> > > > > > > > > > raw bytes on the wire, depending on the size and
> > > > > > > > > > chars, the encoding handles and hides this detail. But
> > > > > > > > > > if you go for direct
> > > access, you need to be aware of the encoding.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > On Tue, 23 Mar 2021 at 07:37,
> > > > > > > > > > <To...@t-systems.com>
> > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > > >
> > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > >
> > > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > > >
> > > > > > > > > > > or if you really want to use the core API, use the
> > > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > > >
> > > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > > > jbertram@apache.org> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > The stack-trace indicates you're invoking the
> > > "readString"
> > > > > > > > > > > > method on line
> > > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't
> > > > > > > > > > > > see that
> > > > > call
> > > > > > > > > > > > in the code you pasted. Therefore, that
> > > > > > > > > > > > stack-trace doesn't seem correct. Can you clarify this?
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Justin
> > > > > > > > > > > >
> > > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > > Fyi:
> > > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) =
> > > > > > > > > > > > > "tive"(ascii
> > > > > > > > > > > > > text) And "tive" is likely part of the string
> > > "ActiveMQ"?
> > > > > > > > > > > > > e.
> > > > > > > > > > > > >
> > > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > > attachments unless
> > > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > > n’ouvrez
> > > > > > aucune pièce
> > > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un
> > > > > > > > > > > > > expéditeur
> > > > > fiable,
> > > > > > > > > > > > > ou que vous ayez l'assurance que le contenu
> > > > > > > > > > > > > provient d'une
> > > > > > source sûre.
> > > > > > > > > > > > >
> > > > > > > > > > > > > While sending / receiving a text message I get
> > > > > > > > > > > > > this
> > > > > > > > > > > > >
> > > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error
> > > > > > > > > > > > > reading in simpleString,
> > > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > ng
> > > > > (S
> > > > > im
> > > > > pleString.java:185)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > > ng
> > > > > (S
> > > > > im
> > > > > pleString.java:173)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > er
> > > > > .r
> > > > > ea
> > > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > > er
> > > > > .r
> > > > > ea
> > > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > >
> > > > > >
> > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailSe
> > > > > rv
> > > > > er
> > > > > Ac
> > > > > tiveMQClient.java:93)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > > >
> > > > > >
> > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQC
> > > > > li
> > > > > en
> > > > > tT
> > > > > est.java:28)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > > ke0(
> > > > > > > > > > > > > Nati
> > > > > > > > > > > > > ve
> > > > > > > > > > > > > Method)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(N
> > > > > at
> > > > > iv
> > > > > eM
> > > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invo
> > > > > ke
> > > > > (D
> > > > > el
> > > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > > >         at
> > > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Fram
> > > > > ew
> > > > > or
> > > > > kM
> > > > > ethod.java:50)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflecti
> > > > > ve
> > > > > Ca
> > > > > ll
> > > > > able.java:12)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framew
> > > > > or
> > > > > kM
> > > > > et
> > > > > hod.java:47)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invo
> > > > > ke
> > > > > Me
> > > > > th
> > > > > od.java:17)
> > > > > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > ss
> > > > > Ru
> > > > > nn
> > > > > er.java:78)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > > ss
> > > > > Ru
> > > > > nn
> > > > > er.java:57)
> > > > > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71
> > > > > > )
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:2
> > > > > > 88
> > > > > > )
> > > > > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58
> > > > > > )
> > > > > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:26
> > > > > > 8)
> > > > > > > > > > > > >         at
> > > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J
> > > > > Un
> > > > > it
> > > > > 4T
> > > > > estReference.java:89)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > > java:41)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > Re
> > > > > mo
> > > > > te
> > > > > TestRunner.java:541)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > > Re
> > > > > mo
> > > > > te
> > > > > TestRunner.java:763)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Remot
> > > > > eT
> > > > > es
> > > > > tR
> > > > > unner.java:463)
> > > > > > > > > > > > >         at
> > > > > > > > > > > > >
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > > Remo
> > > > > > > > > > > > > teTe
> > > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > > >
> > > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Justin
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > > >
> > > > > > wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > > I try to send and receive a netty ByteBuf
> > > > > > > > > > > > > > message, but it
> > > > > > fails.
> > > > > > > > > > > > > > What I'm doing wrong here? I even don't know
> > > > > > > > > > > > > > ist he mistake in sending or receiving!
> > > > > > > > > > > > > > I was thinking to use the jms layer, but I'm
> > > > > > > > > > > > > > receiving
> > > > > the
> > > > > > > > > > > > > > data buffer throught a netty buffer and I want
> > > > > > > > > > > > > > to avoid
> > > > > to
> > > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >        public void
> > > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > > >              ClientSession session =
> > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > >                     ClientMessage message =
> > > > > > session.createMessage(true);
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > buf.readableBytes());
> > > > > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > >              }
> > > > > > > > > > > > > >        }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >        public ActiveMQBuffer
> > > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > > >              ClientSession session =
> > > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > > >              try {
> > > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > > >                     ClientMessage message =
> > > > > > consumer.receive();
> > > > > > > > > > > > > >                     result =
> > > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBuf
> > > > > > > > > > > > > > fe
> > > > > > > > > > > > > > rS
> > > > > > > > > > > > > > iz
> > > > > > > > > > > > > > e());
> > > > > > > > > > > > > >
> > > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > > >              }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >              return result;
> > > > > > > > > > > > > >        }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > > >              this.configuration = new
> > > > > ConfigurationImpl();
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > this.configuration.addAcceptorConfiguration("i
> > > > > > > > > > > > > > n- vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > > >
> > > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > > >
> > > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >              this.server = new
> > > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > > >        }
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > Clebert Suconic
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > > >
> > > > >
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> > >
> > --
> > Clebert Suconic
> >
> --
> Clebert Suconic



-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
A example would be great!

-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Freitag, 26. März 2021 13:26
An: users@activemq.apache.org
Betreff: Re: send message

On your case it would make sense if the streaming was not a file but a biffer.  I get it.

The optimization here wouldn’t be the copy but it would be not needintg to duplicate the 500MB.  We all thought you had a smaller buffer and did not want the copy.

You can pass an InputStream as a property on the streaming.  If you implemented an InputStream that will read from the NettyBuffer.  The body would be read directly into smaller chunks into the Large Message Streaming.


I’m not working today.  As a matter of fact I’m using an iPhone right  now (pardon any typoes please)

If you can’t figure it out let me know and I will write you an example Monday

On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:

> Not he application is a kind of custom mail server and the messages 
> can reach up to 500mb and are received via tcp and a netty smtp handler.
> Therefore I have a netty direct buffer already and don't want bring 
> the huge messages back into the jvm.
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Donnerstag, 25. März 2021 20:31
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> I assumed the data was already on a file.
>
> If you passed the file name.  The receiver would receive a message 
> where you could either do the opposite. (Pass a file name to steam.  
> Or just receive steaming)
>
> At that size of message the optimization of the copy between your 
> buffer and a byte array makes little difference.
>
> On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
>
> > So you mean I should save the ByteBuffer by myself to a file?
> >
> > --> and pass it over the property that would stream the file directly.
> > (Available on core only)
> > What do you mean? I understand that I shall pass the name of the 
> > file via a message property, right?
> > How would the receiver side looks like?
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Donnerstag, 25. März 2021 16:04
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Sending a message this large will make it to be converted as a large 
> > stream and saved as a file on the server anyways...
> >
> > The copy between ByteBuffer and a byte array would become irrelevant 
> > at this point.
> >
> > If you want to send a large message this big, you could save it to a 
> > file, and pass it over the property that would stream the file directly.
> > (Available on core only)
> >
> > And don't convert a large message between protocols.. use a single 
> > protocol of your choice.
> >
> > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > >
> > > What are you talking about?
> > > I want to send byte buffers with the size up to 500MB to a queue!
> > > What do you mean with string and micro optimization!
> > > The core api fails in my test already with sending/receiving a 
> > > simple
> > string, yes, a simple test!
> > > Does it make sense to have a 500mb native netty buffer received 
> > > via wire
> > and tunnel it back through the jvm?
> > > I don`t think so!
> > > Does it make sense to tunnel megabytes of data through a stream or 
> > > even
> > an byte array through the jvm?
> > > Where ist the advantage of jms?
> > > Why shall I not use the existing core api functions when the 
> > > already
> > support a netty buffer?
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Justin Bertram <jb...@apache.org>
> > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > Well said, Tim. I was going to say the same thing about premature
> > optimization.
> > >
> > >
> > > Justin
> > >
> > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu>
> wrote:
> > >
> > > > One thing to keep in mind is that although the code may be 
> > > > slightly slower, if it lets you use an API that is more 
> > > > favorable (which might mean better documented, more portable, 
> > > > more stable across future versions, easier for others to 
> > > > maintain because they're already familiar with it, or a number 
> > > > of other potential advantages),
> > that might be a win.
> > > >
> > > > Only you know your use case and whether the performance 
> > > > advantages of what you're trying to do actually outweigh the 
> > > > types of advantages I referenced in the first paragraph. But 
> > > > remember that premature optimization is the root of all evil, so 
> > > > make sure that your micro-optimization of avoiding the creation 
> > > > of a String is really a significant enough optimization in the 
> > > > context of your use case to justify the disadvantages of what you're trying to do.
> > > >
> > > > Tim
> > > >
> > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic 
> > > > <cl...@gmail.com>
> > > > wrote:
> > > >
> > > > > Not on the API itself.
> > > > >
> > > > > Try the core api example I sent you... and let me know what is 
> > > > > different from yours.
> > > > >
> > > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com>
> wrote:
> > > > > >
> > > > > > I want to use the jms layer, but I've a netty application 
> > > > > > and I want to
> > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > I think it makes no sense to convert it back from a native 
> > > > > > buffer into
> > > > a
> > > > > byte array or stream and tunnel this throught the jvm!
> > > > > >
> > > > > > Is there a way to use a ByteBuf with jms?
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > You were supposed to call reset right before sending though...
> > > > > > but I
> > > > did
> > > > > not need it on my test.. I will post a link...
> > > > > >
> > > > > > Anyway, if you use the JMS API, the JMS layer is very thin, 
> > > > > > and I don't
> > > > > think it would affect your performance in any way. you could 
> > > > > create a BytesMessage and all the detail would be hidden away 
> > > > > from the internal
> > > > API.
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > clebert.suconic@gmail.com> wrote:
> > > > > > >
> > > > > > > I'm adding a test doing exactly what you did, and it's
> working...
> > > > > > >
> > > > > > > give me 10 minutes and I will post a link here...
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 9:56 AM 
> > > > > > > <To...@t-systems.com>
> > wrote:
> > > > > > > >
> > > > > > > > Same Issue!
> > > > > > > >         public void sendMessageToSmtpQueue(String text) 
> > > > > > > > throws
> > > > > ActiveMQException {
> > > > > > > >                 ClientSession session =
> > > > > this.sessionFactory.createSession();
> > > > > > > >                 try {
> > > > > > > >                         session.start();
> > > > > > > >                         ClientMessage message =
> > > > > session.createMessage(true);
> > > > > > > >
> >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > >
> >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > >
> >  message.getBodyBuffer().writeString(text);
> > > > > > > >                         ClientProducer producer =
> > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > >                         producer.send(message);
> > > > > > > >                 } finally {
> > > > > > > >                         session.close();
> > > > > > > >                 }
> > > > > > > >         }
> > > > > > > >
> > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > > > > > simpleString,
> > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > ng
> > > > (S
> > > > im
> > > > pleString.java:185)
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > ng
> > > > (S
> > > > im
> > > > pleString.java:173)
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > er
> > > > .r
> > > > ea
> > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > er
> > > > .r
> > > > ea
> > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > >
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailSe
> > > > rv
> > > > er
> > > > Ac
> > > > tiveMQClient.java:94)
> > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > >
> > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServ
> > > > er
> > > > Ac
> > > > ti
> > > > veMQClientTest.java:37)
> > > > > > > >         at
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke
> > > > > 0(
> > > > > Na
> > > > > ti
> > > > > ve
> > > > > Method)
> > > > > > > >         at
> > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(N
> > > > at
> > > > iv
> > > > eM
> > > > ethodAccessorImpl.java:62)
> > > > > > > >         at
> > > > >
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invo
> > > > ke
> > > > (D
> > > > el
> > > > egatingMethodAccessorImpl.java:43)
> > > > > > > >         at
> > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Fram
> > > > ew
> > > > or
> > > > kM
> > > > ethod.java:50)
> > > > > > > >         at
> > > > >
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflecti
> > > > ve
> > > > Ca
> > > > ll
> > > > able.java:12)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framew
> > > > or
> > > > kM
> > > > et
> > > > hod.java:47)
> > > > > > > >         at
> > > > >
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invo
> > > > ke
> > > > Me
> > > > th
> > > > od.java:17)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > ss
> > > > Ru
> > > > nn
> > > > er.java:78)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > ss
> > > > Ru
> > > > nn
> > > > er.java:57)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71
> > > > > )
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:2
> > > > > 88
> > > > > )
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58
> > > > > )
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:26
> > > > > 8)
> > > > > > > >         at
> > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J
> > > > Un
> > > > it
> > > > 4T
> > > > estReference.java:89)
> > > > > > > >         at
> > > > >
> > > >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > java:41)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > Re
> > > > mo
> > > > te
> > > > TestRunner.java:541)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > Re
> > > > mo
> > > > te
> > > > TestRunner.java:763)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Remot
> > > > eT
> > > > es
> > > > tR
> > > > unner.java:463)
> > > > > > > >         at
> > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > te
> > > > Te
> > > > > > > > stRunner.java:209)
> > > > > > > >
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > Can you try calling
> > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > before the send?
> > > > > > > >
> > > > > > > > if that does not work I will try your code and see what
> > happens.
> > > > > > > > (Let me know if doesn't please)
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully 
> > > > > > > > <ga...@gmail.com>
> > > > > wrote:
> > > > > > > > >
> > > > > > > > > maybe take inspiration from
> > > > > > > > >
> > > > https://github.com/apache/activemq-artemis/blob/master/tests/int
> > > > eg
> > > > > > > > > rati
> > > > > > > > >
> > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integra
> > > > ti
> > > > > > > > > on/c lient/MessageBufferTest.java that passes a 
> > > > > > > > > string, but there are corresponding byte[] or buffer 
> > > > > > > > > variants in the api. If you want to skip the decoding, 
> > > > > > > > > to access the raw buffer, you need to parse the type 
> > > > > > > > > to get to the
> > appropriate part of the buffer.
> > > > > > > > > There are loads of usage examples in the tests and 
> > > > > > > > > they all work, start there and break it as you go.
> > > > > > > > >
> > > > > > > > > the issue is the wire level encoding that the client 
> > > > > > > > > does, the
> > > > JMS
> > > > > > > > > api hides this, as do the typed accessors, but you can 
> > > > > > > > > get direct access to the encoded buffers via the core 
> > > > > > > > > api as you are doing but you need to be type aware, 
> > > > > > > > > for example a string can be utf-8 encoded or it can be 
> > > > > > > > > raw bytes on the wire, depending on the size and 
> > > > > > > > > chars, the encoding handles and hides this detail. But 
> > > > > > > > > if you go for direct
> > access, you need to be aware of the encoding.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > On Tue, 23 Mar 2021 at 07:37, 
> > > > > > > > > <To...@t-systems.com>
> > wrote:
> > > > > > > > > >
> > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > >
> > > > > > > > > > or if you really want to use the core API, use the
> > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > > jbertram@apache.org> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The stack-trace indicates you're invoking the
> > "readString"
> > > > > > > > > > > method on line
> > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't 
> > > > > > > > > > > see that
> > > > call
> > > > > > > > > > > in the code you pasted. Therefore, that 
> > > > > > > > > > > stack-trace doesn't seem correct. Can you clarify this?
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Justin
> > > > > > > > > > >
> > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> > > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > > Fyi:
> > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = 
> > > > > > > > > > > > "tive"(ascii
> > > > > > > > > > > > text) And "tive" is likely part of the string
> > "ActiveMQ"?
> > > > > > > > > > > > e.
> > > > > > > > > > > >
> > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com 
> > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > attachments unless
> > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > n’ouvrez
> > > > > aucune pièce
> > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un 
> > > > > > > > > > > > expéditeur
> > > > fiable,
> > > > > > > > > > > > ou que vous ayez l'assurance que le contenu 
> > > > > > > > > > > > provient d'une
> > > > > source sûre.
> > > > > > > > > > > >
> > > > > > > > > > > > While sending / receiving a text message I get 
> > > > > > > > > > > > this
> > > > > > > > > > > >
> > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error 
> > > > > > > > > > > > reading in simpleString,
> > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > ng
> > > > (S
> > > > im
> > > > pleString.java:185)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleStri
> > > > ng
> > > > (S
> > > > im
> > > > pleString.java:173)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > er
> > > > .r
> > > > ea
> > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapp
> > > > er
> > > > .r
> > > > ea
> > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > >         at 
> > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > >
> > > > >
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailSe
> > > > rv
> > > > er
> > > > Ac
> > > > tiveMQClient.java:93)
> > > > > > > > > > > >         at 
> > > > > > > > > > > > com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > >
> > > > >
> > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQC
> > > > li
> > > > en
> > > > tT
> > > > est.java:28)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > ke0(
> > > > > > > > > > > > Nati
> > > > > > > > > > > > ve
> > > > > > > > > > > > Method)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(N
> > > > at
> > > > iv
> > > > eM
> > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invo
> > > > ke
> > > > (D
> > > > el
> > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > >         at
> > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Fram
> > > > ew
> > > > or
> > > > kM
> > > > ethod.java:50)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflecti
> > > > ve
> > > > Ca
> > > > ll
> > > > able.java:12)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framew
> > > > or
> > > > kM
> > > > et
> > > > hod.java:47)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invo
> > > > ke
> > > > Me
> > > > th
> > > > od.java:17)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > ss
> > > > Ru
> > > > nn
> > > > er.java:78)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Cla
> > > > ss
> > > > Ru
> > > > nn
> > > > er.java:57)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71
> > > > > )
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:2
> > > > > 88
> > > > > )
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58
> > > > > )
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:26
> > > > > 8)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J
> > > > Un
> > > > it
> > > > 4T
> > > > estReference.java:89)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > java:41)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > Re
> > > > mo
> > > > te
> > > > TestRunner.java:541)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> > > > Re
> > > > mo
> > > > te
> > > > TestRunner.java:763)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(Remot
> > > > eT
> > > > es
> > > > tR
> > > > unner.java:463)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > Remo
> > > > > > > > > > > > teTe
> > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > >
> > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Justin
> > > > > > > > > > > >
> > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM 
> > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > >
> > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > > I try to send and receive a netty ByteBuf 
> > > > > > > > > > > > > message, but it
> > > > > fails.
> > > > > > > > > > > > > What I'm doing wrong here? I even don't know 
> > > > > > > > > > > > > ist he mistake in sending or receiving!
> > > > > > > > > > > > > I was thinking to use the jms layer, but I'm 
> > > > > > > > > > > > > receiving
> > > > the
> > > > > > > > > > > > > data buffer throught a netty buffer and I want 
> > > > > > > > > > > > > to avoid
> > > > to
> > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > >
> > > > > > > > > > > > >        public void 
> > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > >              ClientSession session =
> > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > >              try {
> > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > >                     ClientMessage message =
> > > > > session.createMessage(true);
> > > > > > > > > > > > >
> > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > buf.readableBytes());
> > > > > > > > > > > > >                     ClientProducer producer = 
> > > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > >              }
> > > > > > > > > > > > >        }
> > > > > > > > > > > > >
> > > > > > > > > > > > >        public ActiveMQBuffer
> > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > >              ClientSession session =
> > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > >              try {
> > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > >                     ClientConsumer consumer = 
> > > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > >                     ClientMessage message =
> > > > > consumer.receive();
> > > > > > > > > > > > >                     result = 
> > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBuf
> > > > > > > > > > > > > fe
> > > > > > > > > > > > > rS
> > > > > > > > > > > > > iz
> > > > > > > > > > > > > e());
> > > > > > > > > > > > >
> > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > >              }
> > > > > > > > > > > > >
> > > > > > > > > > > > >              return result;
> > > > > > > > > > > > >        }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > >              this.configuration = new
> > > > ConfigurationImpl();
> > > > > > > > > > > > >
> > > > > > > > > > > > > this.configuration.addAcceptorConfiguration("i
> > > > > > > > > > > > > n- vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > >
> > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > >
> > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > >
> > > > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > >
> > > > > > > > > > > > >              this.server = new
> > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > >        }
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > > >
> > > >
> >
> >
> >
> > --
> > Clebert Suconic
> >
> --
> Clebert Suconic
>
--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
On your case it would make sense if the streaming was not a file but a
biffer.  I get it.

The optimization here wouldn’t be the copy but it would be not needintg to
duplicate the 500MB.  We all thought you had a smaller buffer and did not
want the copy.

You can pass an InputStream as a property on the streaming.  If you
implemented an InputStream that will read from the NettyBuffer.  The body
would be read directly into smaller chunks into the Large Message
Streaming.


I’m not working today.  As a matter of fact I’m using an iPhone right  now
(pardon any typoes please)

If you can’t figure it out let me know and I will write you an example
Monday

On Fri, Mar 26, 2021 at 3:35 AM <To...@t-systems.com> wrote:

> Not he application is a kind of custom mail server and the messages can
> reach up to 500mb and are received via tcp and a netty smtp handler.
> Therefore I have a netty direct buffer already and don't want bring the
> huge messages back into the jvm.
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Donnerstag, 25. März 2021 20:31
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> I assumed the data was already on a file.
>
> If you passed the file name.  The receiver would receive a message where
> you could either do the opposite. (Pass a file name to steam.  Or just
> receive steaming)
>
> At that size of message the optimization of the copy between your buffer
> and a byte array makes little difference.
>
> On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:
>
> > So you mean I should save the ByteBuffer by myself to a file?
> >
> > --> and pass it over the property that would stream the file directly.
> > (Available on core only)
> > What do you mean? I understand that I shall pass the name of the file
> > via a message property, right?
> > How would the receiver side looks like?
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Donnerstag, 25. März 2021 16:04
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Sending a message this large will make it to be converted as a large
> > stream and saved as a file on the server anyways...
> >
> > The copy between ByteBuffer and a byte array would become irrelevant
> > at this point.
> >
> > If you want to send a large message this big, you could save it to a
> > file, and pass it over the property that would stream the file directly.
> > (Available on core only)
> >
> > And don't convert a large message between protocols.. use a single
> > protocol of your choice.
> >
> > On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> > >
> > > What are you talking about?
> > > I want to send byte buffers with the size up to 500MB to a queue!
> > > What do you mean with string and micro optimization!
> > > The core api fails in my test already with sending/receiving a
> > > simple
> > string, yes, a simple test!
> > > Does it make sense to have a 500mb native netty buffer received via
> > > wire
> > and tunnel it back through the jvm?
> > > I don`t think so!
> > > Does it make sense to tunnel megabytes of data through a stream or
> > > even
> > an byte array through the jvm?
> > > Where ist the advantage of jms?
> > > Why shall I not use the existing core api functions when the already
> > support a netty buffer?
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Justin Bertram <jb...@apache.org>
> > > Gesendet: Mittwoch, 24. März 2021 17:56
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > Well said, Tim. I was going to say the same thing about premature
> > optimization.
> > >
> > >
> > > Justin
> > >
> > > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu>
> wrote:
> > >
> > > > One thing to keep in mind is that although the code may be
> > > > slightly slower, if it lets you use an API that is more favorable
> > > > (which might mean better documented, more portable, more stable
> > > > across future versions, easier for others to maintain because
> > > > they're already familiar with it, or a number of other potential
> > > > advantages),
> > that might be a win.
> > > >
> > > > Only you know your use case and whether the performance advantages
> > > > of what you're trying to do actually outweigh the types of
> > > > advantages I referenced in the first paragraph. But remember that
> > > > premature optimization is the root of all evil, so make sure that
> > > > your micro-optimization of avoiding the creation of a String is
> > > > really a significant enough optimization in the context of your
> > > > use case to justify the disadvantages of what you're trying to do.
> > > >
> > > > Tim
> > > >
> > > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > > > <cl...@gmail.com>
> > > > wrote:
> > > >
> > > > > Not on the API itself.
> > > > >
> > > > > Try the core api example I sent you... and let me know what is
> > > > > different from yours.
> > > > >
> > > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com>
> wrote:
> > > > > >
> > > > > > I want to use the jms layer, but I've a netty application and
> > > > > > I want to
> > > > > write the ByteBuf mostly efficent to the queue.
> > > > > > I think it makes no sense to convert it back from a native
> > > > > > buffer into
> > > > a
> > > > > byte array or stream and tunnel this throught the jvm!
> > > > > >
> > > > > > Is there a way to use a ByteBuf with jms?
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > You were supposed to call reset right before sending though...
> > > > > > but I
> > > > did
> > > > > not need it on my test.. I will post a link...
> > > > > >
> > > > > > Anyway, if you use the JMS API, the JMS layer is very thin,
> > > > > > and I don't
> > > > > think it would affect your performance in any way. you could
> > > > > create a BytesMessage and all the detail would be hidden away
> > > > > from the internal
> > > > API.
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > > clebert.suconic@gmail.com> wrote:
> > > > > > >
> > > > > > > I'm adding a test doing exactly what you did, and it's
> working...
> > > > > > >
> > > > > > > give me 10 minutes and I will post a link here...
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com>
> > wrote:
> > > > > > > >
> > > > > > > > Same Issue!
> > > > > > > >         public void sendMessageToSmtpQueue(String text)
> > > > > > > > throws
> > > > > ActiveMQException {
> > > > > > > >                 ClientSession session =
> > > > > this.sessionFactory.createSession();
> > > > > > > >                 try {
> > > > > > > >                         session.start();
> > > > > > > >                         ClientMessage message =
> > > > > session.createMessage(true);
> > > > > > > >
> >  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > > >
> >  message.getBodyBuffer().resetReaderIndex();
> > > > > > > >
> >  message.getBodyBuffer().writeString(text);
> > > > > > > >                         ClientProducer producer =
> > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > >                         producer.send(message);
> > > > > > > >                 } finally {
> > > > > > > >                         session.close();
> > > > > > > >                 }
> > > > > > > >         }
> > > > > > > >
> > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > simpleString,
> > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > > (S
> > > > im
> > > > pleString.java:185)
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > > (S
> > > > im
> > > > pleString.java:173)
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > > .r
> > > > ea
> > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > >         at
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > > .r
> > > > ea
> > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > >
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServ
> > > > er
> > > > Ac
> > > > tiveMQClient.java:94)
> > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > >
> > > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServer
> > > > Ac
> > > > ti
> > > > veMQClientTest.java:37)
> > > > > > > >         at
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(
> > > > > Na
> > > > > ti
> > > > > ve
> > > > > Method)
> > > > > > > >         at
> > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nat
> > > > iv
> > > > eM
> > > > ethodAccessorImpl.java:62)
> > > > > > > >         at
> > > > >
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
> > > > (D
> > > > el
> > > > egatingMethodAccessorImpl.java:43)
> > > > > > > >         at
> > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framew
> > > > or
> > > > kM
> > > > ethod.java:50)
> > > > > > > >         at
> > > > >
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflective
> > > > Ca
> > > > ll
> > > > able.java:12)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framewor
> > > > kM
> > > > et
> > > > hod.java:47)
> > > > > > > >         at
> > > > >
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invoke
> > > > Me
> > > > th
> > > > od.java:17)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > > Ru
> > > > nn
> > > > er.java:78)
> > > > > > > >         at
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > > Ru
> > > > nn
> > > > er.java:57)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288
> > > > > )
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > >         at
> > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUn
> > > > it
> > > > 4T
> > > > estReference.java:89)
> > > > > > > >         at
> > > > >
> > > >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > java:41)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > > mo
> > > > te
> > > > TestRunner.java:541)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > > mo
> > > > te
> > > > TestRunner.java:763)
> > > > > > > >         at
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteT
> > > > es
> > > > tR
> > > > unner.java:463)
> > > > > > > >         at
> > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remote
> > > > Te
> > > > > > > > stRunner.java:209)
> > > > > > > >
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > Can you try calling
> > > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > > before the send?
> > > > > > > >
> > > > > > > > if that does not work I will try your code and see what
> > happens.
> > > > > > > > (Let me know if doesn't please)
> > > > > > > >
> > > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > > > <ga...@gmail.com>
> > > > > wrote:
> > > > > > > > >
> > > > > > > > > maybe take inspiration from
> > > > > > > > >
> > > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > > > rati
> > > > > > > > >
> > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > > > on/c lient/MessageBufferTest.java that passes a string,
> > > > > > > > > but there are corresponding byte[] or buffer variants in
> > > > > > > > > the api. If you want to skip the decoding, to access the
> > > > > > > > > raw buffer, you need to parse the type to get to the
> > appropriate part of the buffer.
> > > > > > > > > There are loads of usage examples in the tests and they
> > > > > > > > > all work, start there and break it as you go.
> > > > > > > > >
> > > > > > > > > the issue is the wire level encoding that the client
> > > > > > > > > does, the
> > > > JMS
> > > > > > > > > api hides this, as do the typed accessors, but you can
> > > > > > > > > get direct access to the encoded buffers via the core
> > > > > > > > > api as you are doing but you need to be type aware, for
> > > > > > > > > example a string can be utf-8 encoded or it can be raw
> > > > > > > > > bytes on the wire, depending on the size and chars, the
> > > > > > > > > encoding handles and hides this detail. But if you go
> > > > > > > > > for direct
> > access, you need to be aware of the encoding.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > On Tue, 23 Mar 2021 at 07:37,
> > > > > > > > > <To...@t-systems.com>
> > wrote:
> > > > > > > > > >
> > > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > > >
> > > > > > > > > > or if you really want to use the core API, use the
> > > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > > jbertram@apache.org> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The stack-trace indicates you're invoking the
> > "readString"
> > > > > > > > > > > method on line
> > > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see
> > > > > > > > > > > that
> > > > call
> > > > > > > > > > > in the code you pasted. Therefore, that stack-trace
> > > > > > > > > > > doesn't seem correct. Can you clarify this?
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Justin
> > > > > > > > > > >
> > > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > > Fyi:
> > > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) =
> > > > > > > > > > > > "tive"(ascii
> > > > > > > > > > > > text) And "tive" is likely part of the string
> > "ActiveMQ"?
> > > > > > > > > > > > e.
> > > > > > > > > > > >
> > > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > > attachments unless
> > > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > > n’ouvrez
> > > > > aucune pièce
> > > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un
> > > > > > > > > > > > expéditeur
> > > > fiable,
> > > > > > > > > > > > ou que vous ayez l'assurance que le contenu
> > > > > > > > > > > > provient d'une
> > > > > source sûre.
> > > > > > > > > > > >
> > > > > > > > > > > > While sending / receiving a text message I get
> > > > > > > > > > > > this
> > > > > > > > > > > >
> > > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading
> > > > > > > > > > > > in simpleString,
> > > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > > (S
> > > > im
> > > > pleString.java:185)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > > (S
> > > > im
> > > > pleString.java:173)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > > .r
> > > > ea
> > > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > > .r
> > > > ea
> > > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > >
> > > > >
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServ
> > > > er
> > > > Ac
> > > > tiveMQClient.java:93)
> > > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > > >
> > > > >
> > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQCli
> > > > en
> > > > tT
> > > > est.java:28)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > > ke0(
> > > > > > > > > > > > Nati
> > > > > > > > > > > > ve
> > > > > > > > > > > > Method)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nat
> > > > iv
> > > > eM
> > > > ethodAccessorImpl.java:62)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
> > > > (D
> > > > el
> > > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > > >         at
> > > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framew
> > > > or
> > > > kM
> > > > ethod.java:50)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflective
> > > > Ca
> > > > ll
> > > > able.java:12)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framewor
> > > > kM
> > > > et
> > > > hod.java:47)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invoke
> > > > Me
> > > > th
> > > > od.java:17)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > > Ru
> > > > nn
> > > > er.java:78)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > > Ru
> > > > nn
> > > > er.java:57)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288
> > > > > )
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > > > >         at
> > > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUn
> > > > it
> > > > 4T
> > > > estReference.java:89)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > > java:41)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > > mo
> > > > te
> > > > TestRunner.java:541)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > > mo
> > > > te
> > > > TestRunner.java:763)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteT
> > > > es
> > > > tR
> > > > unner.java:463)
> > > > > > > > > > > >         at
> > > > > > > > > > > >
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > > Remo
> > > > > > > > > > > > teTe
> > > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > > >
> > > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Justin
> > > > > > > > > > > >
> > > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > > >
> > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > > I try to send and receive a netty ByteBuf
> > > > > > > > > > > > > message, but it
> > > > > fails.
> > > > > > > > > > > > > What I'm doing wrong here? I even don't know ist
> > > > > > > > > > > > > he mistake in sending or receiving!
> > > > > > > > > > > > > I was thinking to use the jms layer, but I'm
> > > > > > > > > > > > > receiving
> > > > the
> > > > > > > > > > > > > data buffer throught a netty buffer and I want
> > > > > > > > > > > > > to avoid
> > > > to
> > > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > > >
> > > > > > > > > > > > >        public void
> > > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > > >              ClientSession session =
> > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > >              try {
> > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > >                     ClientMessage message =
> > > > > session.createMessage(true);
> > > > > > > > > > > > >
> > > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > > buf.readableBytes());
> > > > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > >              }
> > > > > > > > > > > > >        }
> > > > > > > > > > > > >
> > > > > > > > > > > > >        public ActiveMQBuffer
> > > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > > >              ClientSession session =
> > > > > this.sessionFactory.createSession();
> > > > > > > > > > > > >              try {
> > > > > > > > > > > > >                     session.start();
> > > > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > > >                     ClientMessage message =
> > > > > consumer.receive();
> > > > > > > > > > > > >                     result =
> > > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBuffe
> > > > > > > > > > > > > rS
> > > > > > > > > > > > > iz
> > > > > > > > > > > > > e());
> > > > > > > > > > > > >
> > > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > > >              } finally {
> > > > > > > > > > > > >                     session.close();
> > > > > > > > > > > > >              }
> > > > > > > > > > > > >
> > > > > > > > > > > > >              return result;
> > > > > > > > > > > > >        }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > > >              this.configuration = new
> > > > ConfigurationImpl();
> > > > > > > > > > > > >
> > > > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-
> > > > > > > > > > > > > vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > > >
> > > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > > >
> > > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > > >
> > > > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > > >
> > > > > > > > > > > > >              this.server = new
> > > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > > >        }
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Clebert Suconic
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > > >
> > > >
> >
> >
> >
> > --
> > Clebert Suconic
> >
> --
> Clebert Suconic
>
-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
Not he application is a kind of custom mail server and the messages can reach up to 500mb and are received via tcp and a netty smtp handler.
Therefore I have a netty direct buffer already and don't want bring the huge messages back into the jvm.

-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Donnerstag, 25. März 2021 20:31
An: users@activemq.apache.org
Betreff: Re: send message

I assumed the data was already on a file.

If you passed the file name.  The receiver would receive a message where you could either do the opposite. (Pass a file name to steam.  Or just receive steaming)

At that size of message the optimization of the copy between your buffer and a byte array makes little difference.

On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:

> So you mean I should save the ByteBuffer by myself to a file?
>
> --> and pass it over the property that would stream the file directly.
> (Available on core only)
> What do you mean? I understand that I shall pass the name of the file 
> via a message property, right?
> How would the receiver side looks like?
>
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Donnerstag, 25. März 2021 16:04
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> Sending a message this large will make it to be converted as a large 
> stream and saved as a file on the server anyways...
>
> The copy between ByteBuffer and a byte array would become irrelevant 
> at this point.
>
> If you want to send a large message this big, you could save it to a 
> file, and pass it over the property that would stream the file directly.
> (Available on core only)
>
> And don't convert a large message between protocols.. use a single 
> protocol of your choice.
>
> On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> >
> > What are you talking about?
> > I want to send byte buffers with the size up to 500MB to a queue!
> > What do you mean with string and micro optimization!
> > The core api fails in my test already with sending/receiving a 
> > simple
> string, yes, a simple test!
> > Does it make sense to have a 500mb native netty buffer received via 
> > wire
> and tunnel it back through the jvm?
> > I don`t think so!
> > Does it make sense to tunnel megabytes of data through a stream or 
> > even
> an byte array through the jvm?
> > Where ist the advantage of jms?
> > Why shall I not use the existing core api functions when the already
> support a netty buffer?
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Justin Bertram <jb...@apache.org>
> > Gesendet: Mittwoch, 24. März 2021 17:56
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Well said, Tim. I was going to say the same thing about premature
> optimization.
> >
> >
> > Justin
> >
> > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
> >
> > > One thing to keep in mind is that although the code may be 
> > > slightly slower, if it lets you use an API that is more favorable 
> > > (which might mean better documented, more portable, more stable 
> > > across future versions, easier for others to maintain because 
> > > they're already familiar with it, or a number of other potential 
> > > advantages),
> that might be a win.
> > >
> > > Only you know your use case and whether the performance advantages 
> > > of what you're trying to do actually outweigh the types of 
> > > advantages I referenced in the first paragraph. But remember that 
> > > premature optimization is the root of all evil, so make sure that 
> > > your micro-optimization of avoiding the creation of a String is 
> > > really a significant enough optimization in the context of your 
> > > use case to justify the disadvantages of what you're trying to do.
> > >
> > > Tim
> > >
> > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic 
> > > <cl...@gmail.com>
> > > wrote:
> > >
> > > > Not on the API itself.
> > > >
> > > > Try the core api example I sent you... and let me know what is 
> > > > different from yours.
> > > >
> > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > I want to use the jms layer, but I've a netty application and 
> > > > > I want to
> > > > write the ByteBuf mostly efficent to the queue.
> > > > > I think it makes no sense to convert it back from a native 
> > > > > buffer into
> > > a
> > > > byte array or stream and tunnel this throught the jvm!
> > > > >
> > > > > Is there a way to use a ByteBuf with jms?
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > You were supposed to call reset right before sending though...
> > > > > but I
> > > did
> > > > not need it on my test.. I will post a link...
> > > > >
> > > > > Anyway, if you use the JMS API, the JMS layer is very thin, 
> > > > > and I don't
> > > > think it would affect your performance in any way. you could 
> > > > create a BytesMessage and all the detail would be hidden away 
> > > > from the internal
> > > API.
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > clebert.suconic@gmail.com> wrote:
> > > > > >
> > > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > > >
> > > > > > give me 10 minutes and I will post a link here...
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com>
> wrote:
> > > > > > >
> > > > > > > Same Issue!
> > > > > > >         public void sendMessageToSmtpQueue(String text) 
> > > > > > > throws
> > > > ActiveMQException {
> > > > > > >                 ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > >                 try {
> > > > > > >                         session.start();
> > > > > > >                         ClientMessage message =
> > > > session.createMessage(true);
> > > > > > >
>  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > >
>  message.getBodyBuffer().resetReaderIndex();
> > > > > > >
>  message.getBodyBuffer().writeString(text);
> > > > > > >                         ClientProducer producer =
> > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                         producer.send(message);
> > > > > > >                 } finally {
> > > > > > >                         session.close();
> > > > > > >                 }
> > > > > > >         }
> > > > > > >
> > > > > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > > > > simpleString,
> > > > length=1953068645 is greater than readableBytes=3
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > (S
> > > im
> > > pleString.java:185)
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > (S
> > > im
> > > pleString.java:173)
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > .r
> > > ea
> > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > .r
> > > ea
> > > dString(ChannelBufferWrapper.java:98)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > >
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServ
> > > er
> > > Ac
> > > tiveMQClient.java:94)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > >
> > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServer
> > > Ac
> > > ti
> > > veMQClientTest.java:37)
> > > > > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(
> > > > Na
> > > > ti
> > > > ve
> > > > Method)
> > > > > > >         at
> > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nat
> > > iv
> > > eM
> > > ethodAccessorImpl.java:62)
> > > > > > >         at
> > > >
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
> > > (D
> > > el
> > > egatingMethodAccessorImpl.java:43)
> > > > > > >         at
> > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > >         at
> > > >
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framew
> > > or
> > > kM
> > > ethod.java:50)
> > > > > > >         at
> > > >
> > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflective
> > > Ca
> > > ll
> > > able.java:12)
> > > > > > >         at
> > > >
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framewor
> > > kM
> > > et
> > > hod.java:47)
> > > > > > >         at
> > > >
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invoke
> > > Me
> > > th
> > > od.java:17)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > >         at
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > Ru
> > > nn
> > > er.java:78)
> > > > > > >         at
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > Ru
> > > nn
> > > er.java:57)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288
> > > > )
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > >         at
> > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUn
> > > it
> > > 4T
> > > estReference.java:89)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > java:41)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > mo
> > > te
> > > TestRunner.java:541)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > mo
> > > te
> > > TestRunner.java:763)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteT
> > > es
> > > tR
> > > unner.java:463)
> > > > > > >         at
> > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remote
> > > Te
> > > > > > > stRunner.java:209)
> > > > > > >
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Can you try calling
> > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > before the send?
> > > > > > >
> > > > > > > if that does not work I will try your code and see what
> happens.
> > > > > > > (Let me know if doesn't please)
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully 
> > > > > > > <ga...@gmail.com>
> > > > wrote:
> > > > > > > >
> > > > > > > > maybe take inspiration from
> > > > > > > >
> > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > > rati
> > > > > > > >
> > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > > on/c lient/MessageBufferTest.java that passes a string, 
> > > > > > > > but there are corresponding byte[] or buffer variants in 
> > > > > > > > the api. If you want to skip the decoding, to access the 
> > > > > > > > raw buffer, you need to parse the type to get to the
> appropriate part of the buffer.
> > > > > > > > There are loads of usage examples in the tests and they 
> > > > > > > > all work, start there and break it as you go.
> > > > > > > >
> > > > > > > > the issue is the wire level encoding that the client 
> > > > > > > > does, the
> > > JMS
> > > > > > > > api hides this, as do the typed accessors, but you can 
> > > > > > > > get direct access to the encoded buffers via the core 
> > > > > > > > api as you are doing but you need to be type aware, for 
> > > > > > > > example a string can be utf-8 encoded or it can be raw 
> > > > > > > > bytes on the wire, depending on the size and chars, the 
> > > > > > > > encoding handles and hides this detail. But if you go 
> > > > > > > > for direct
> access, you need to be aware of the encoding.
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, 23 Mar 2021 at 07:37, 
> > > > > > > > <To...@t-systems.com>
> wrote:
> > > > > > > > >
> > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > >
> > > > > > > > > or if you really want to use the core API, use the
> > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > jbertram@apache.org> wrote:
> > > > > > > > > >
> > > > > > > > > > The stack-trace indicates you're invoking the
> "readString"
> > > > > > > > > > method on line
> > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see 
> > > > > > > > > > that
> > > call
> > > > > > > > > > in the code you pasted. Therefore, that stack-trace 
> > > > > > > > > > doesn't seem correct. Can you clarify this?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > > Fyi:
> > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = 
> > > > > > > > > > > "tive"(ascii
> > > > > > > > > > > text) And "tive" is likely part of the string
> "ActiveMQ"?
> > > > > > > > > > > e.
> > > > > > > > > > >
> > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > Van: Tobias.Wolf@t-systems.com 
> > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > attachments unless
> > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > n’ouvrez
> > > > aucune pièce
> > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un 
> > > > > > > > > > > expéditeur
> > > fiable,
> > > > > > > > > > > ou que vous ayez l'assurance que le contenu 
> > > > > > > > > > > provient d'une
> > > > source sûre.
> > > > > > > > > > >
> > > > > > > > > > > While sending / receiving a text message I get 
> > > > > > > > > > > this
> > > > > > > > > > >
> > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading 
> > > > > > > > > > > in simpleString,
> > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > (S
> > > im
> > > pleString.java:185)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString
> > > (S
> > > im
> > > pleString.java:173)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > .r
> > > ea
> > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper
> > > .r
> > > ea
> > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > >
> > > >
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServ
> > > er
> > > Ac
> > > tiveMQClient.java:93)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > >
> > > >
> > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQCli
> > > en
> > > tT
> > > est.java:28)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > ke0(
> > > > > > > > > > > Nati
> > > > > > > > > > > ve
> > > > > > > > > > > Method)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nat
> > > iv
> > > eM
> > > ethodAccessorImpl.java:62)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
> > > (D
> > > el
> > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > >         at
> > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framew
> > > or
> > > kM
> > > ethod.java:50)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.internal.runners.model.ReflectiveCallable.run(Reflective
> > > Ca
> > > ll
> > > able.java:12)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(Framewor
> > > kM
> > > et
> > > hod.java:47)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(Invoke
> > > Me
> > > th
> > > od.java:17)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > Ru
> > > nn
> > > er.java:78)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4Class
> > > Ru
> > > nn
> > > er.java:57)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288
> > > > )
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUn
> > > it
> > > 4T
> > > estReference.java:89)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > java:41)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > mo
> > > te
> > > TestRunner.java:541)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Re
> > > mo
> > > te
> > > TestRunner.java:763)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteT
> > > es
> > > tR
> > > unner.java:463)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > Remo
> > > > > > > > > > > teTe
> > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > >
> > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Justin
> > > > > > > > > > >
> > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM 
> > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > >
> > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > > I try to send and receive a netty ByteBuf 
> > > > > > > > > > > > message, but it
> > > > fails.
> > > > > > > > > > > > What I'm doing wrong here? I even don't know ist 
> > > > > > > > > > > > he mistake in sending or receiving!
> > > > > > > > > > > > I was thinking to use the jms layer, but I'm 
> > > > > > > > > > > > receiving
> > > the
> > > > > > > > > > > > data buffer throught a netty buffer and I want 
> > > > > > > > > > > > to avoid
> > > to
> > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > >
> > > > > > > > > > > >        public void 
> > > > > > > > > > > > sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > >              ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > > > > > > >              try {
> > > > > > > > > > > >                     session.start();
> > > > > > > > > > > >                     ClientMessage message =
> > > > session.createMessage(true);
> > > > > > > > > > > >
> > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > buf.readableBytes());
> > > > > > > > > > > >                     ClientProducer producer = 
> > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > >              } finally {
> > > > > > > > > > > >                     session.close();
> > > > > > > > > > > >              }
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > > >        public ActiveMQBuffer
> > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > >              ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > > > > > > >              try {
> > > > > > > > > > > >                     session.start();
> > > > > > > > > > > >                     ClientConsumer consumer = 
> > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                     ClientMessage message =
> > > > consumer.receive();
> > > > > > > > > > > >                     result = 
> > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBuffe
> > > > > > > > > > > > rS
> > > > > > > > > > > > iz
> > > > > > > > > > > > e());
> > > > > > > > > > > >
> > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > >              } finally {
> > > > > > > > > > > >                     session.close();
> > > > > > > > > > > >              }
> > > > > > > > > > > >
> > > > > > > > > > > >              return result;
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > >              this.configuration = new
> > > ConfigurationImpl();
> > > > > > > > > > > >
> > > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-
> > > > > > > > > > > > vm ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > >
> > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > >
> > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > >
> > > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > >
> > > > > > > > > > > >              this.server = new
> > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > > >
> > >
>
>
>
> --
> Clebert Suconic
>
--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
I assumed the data was already on a file.

If you passed the file name.  The receiver would receive a message where
you could either do the opposite. (Pass a file name to steam.  Or just
receive steaming)

At that size of message the optimization of the copy between your buffer
and a byte array makes little difference.

On Thu, Mar 25, 2021 at 11:12 AM <To...@t-systems.com> wrote:

> So you mean I should save the ByteBuffer by myself to a file?
>
> --> and pass it over the property that would stream the file directly.
> (Available on core only)
> What do you mean? I understand that I shall pass the name of the file via
> a message property, right?
> How would the receiver side looks like?
>
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Donnerstag, 25. März 2021 16:04
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> Sending a message this large will make it to be converted as a large
> stream and saved as a file on the server anyways...
>
> The copy between ByteBuffer and a byte array would become irrelevant at
> this point.
>
> If you want to send a large message this big, you could save it to a file,
> and pass it over the property that would stream the file directly.
> (Available on core only)
>
> And don't convert a large message between protocols.. use a single
> protocol of your choice.
>
> On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
> >
> > What are you talking about?
> > I want to send byte buffers with the size up to 500MB to a queue!
> > What do you mean with string and micro optimization!
> > The core api fails in my test already with sending/receiving a simple
> string, yes, a simple test!
> > Does it make sense to have a 500mb native netty buffer received via wire
> and tunnel it back through the jvm?
> > I don`t think so!
> > Does it make sense to tunnel megabytes of data through a stream or even
> an byte array through the jvm?
> > Where ist the advantage of jms?
> > Why shall I not use the existing core api functions when the already
> support a netty buffer?
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Justin Bertram <jb...@apache.org>
> > Gesendet: Mittwoch, 24. März 2021 17:56
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Well said, Tim. I was going to say the same thing about premature
> optimization.
> >
> >
> > Justin
> >
> > On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
> >
> > > One thing to keep in mind is that although the code may be slightly
> > > slower, if it lets you use an API that is more favorable (which
> > > might mean better documented, more portable, more stable across
> > > future versions, easier for others to maintain because they're
> > > already familiar with it, or a number of other potential advantages),
> that might be a win.
> > >
> > > Only you know your use case and whether the performance advantages
> > > of what you're trying to do actually outweigh the types of
> > > advantages I referenced in the first paragraph. But remember that
> > > premature optimization is the root of all evil, so make sure that
> > > your micro-optimization of avoiding the creation of a String is
> > > really a significant enough optimization in the context of your use
> > > case to justify the disadvantages of what you're trying to do.
> > >
> > > Tim
> > >
> > > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > > <cl...@gmail.com>
> > > wrote:
> > >
> > > > Not on the API itself.
> > > >
> > > > Try the core api example I sent you... and let me know what is
> > > > different from yours.
> > > >
> > > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > I want to use the jms layer, but I've a netty application and I
> > > > > want to
> > > > write the ByteBuf mostly efficent to the queue.
> > > > > I think it makes no sense to convert it back from a native
> > > > > buffer into
> > > a
> > > > byte array or stream and tunnel this throught the jvm!
> > > > >
> > > > > Is there a way to use a ByteBuf with jms?
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > You were supposed to call reset right before sending though...
> > > > > but I
> > > did
> > > > not need it on my test.. I will post a link...
> > > > >
> > > > > Anyway, if you use the JMS API, the JMS layer is very thin, and
> > > > > I don't
> > > > think it would affect your performance in any way. you could
> > > > create a BytesMessage and all the detail would be hidden away from
> > > > the internal
> > > API.
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > > clebert.suconic@gmail.com> wrote:
> > > > > >
> > > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > > >
> > > > > > give me 10 minutes and I will post a link here...
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com>
> wrote:
> > > > > > >
> > > > > > > Same Issue!
> > > > > > >         public void sendMessageToSmtpQueue(String text)
> > > > > > > throws
> > > > ActiveMQException {
> > > > > > >                 ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > >                 try {
> > > > > > >                         session.start();
> > > > > > >                         ClientMessage message =
> > > > session.createMessage(true);
> > > > > > >
>  message.setType(ClientMessage.TEXT_TYPE);
> > > > > > >
>  message.getBodyBuffer().resetReaderIndex();
> > > > > > >
>  message.getBodyBuffer().writeString(text);
> > > > > > >                         ClientProducer producer =
> > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                         producer.send(message);
> > > > > > >                 } finally {
> > > > > > >                         session.close();
> > > > > > >                 }
> > > > > > >         }
> > > > > > >
> > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > simpleString,
> > > > length=1953068645 is greater than readableBytes=3
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > > im
> > > pleString.java:185)
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > > im
> > > pleString.java:173)
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > > ea
> > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > >         at
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > > ea
> > > dString(ChannelBufferWrapper.java:98)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > >
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServer
> > > Ac
> > > tiveMQClient.java:94)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > >
> > > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerAc
> > > ti
> > > veMQClientTest.java:37)
> > > > > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Na
> > > > ti
> > > > ve
> > > > Method)
> > > > > > >         at
> > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nativ
> > > eM
> > > ethodAccessorImpl.java:62)
> > > > > > >         at
> > > >
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(D
> > > el
> > > egatingMethodAccessorImpl.java:43)
> > > > > > >         at
> > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > >         at
> > > >
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framewor
> > > kM
> > > ethod.java:50)
> > > > > > >         at
> > > >
> > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCa
> > > ll
> > > able.java:12)
> > > > > > >         at
> > > >
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkM
> > > et
> > > hod.java:47)
> > > > > > >         at
> > > >
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMe
> > > th
> > > od.java:17)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > >         at
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > > nn
> > > er.java:78)
> > > > > > >         at
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > > nn
> > > er.java:57)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > >         at
> > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > >         at
> > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit
> > > 4T
> > > estReference.java:89)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > java:41)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > > te
> > > TestRunner.java:541)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > > te
> > > TestRunner.java:763)
> > > > > > >         at
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTes
> > > tR
> > > unner.java:463)
> > > > > > >         at
> > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > > > stRunner.java:209)
> > > > > > >
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Can you try calling
> > > > > > > message.getBodyBuffer().resetReaderIndex();
> > > > before the send?
> > > > > > >
> > > > > > > if that does not work I will try your code and see what
> happens.
> > > > > > > (Let me know if doesn't please)
> > > > > > >
> > > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > > <ga...@gmail.com>
> > > > wrote:
> > > > > > > >
> > > > > > > > maybe take inspiration from
> > > > > > > >
> > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > > rati
> > > > > > > >
> > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > > on/c lient/MessageBufferTest.java that passes a string,
> > > > > > > > but there are corresponding byte[] or buffer variants in
> > > > > > > > the api. If you want to skip the decoding, to access the
> > > > > > > > raw buffer, you need to parse the type to get to the
> appropriate part of the buffer.
> > > > > > > > There are loads of usage examples in the tests and they
> > > > > > > > all work, start there and break it as you go.
> > > > > > > >
> > > > > > > > the issue is the wire level encoding that the client does,
> > > > > > > > the
> > > JMS
> > > > > > > > api hides this, as do the typed accessors, but you can get
> > > > > > > > direct access to the encoded buffers via the core api as
> > > > > > > > you are doing but you need to be type aware, for example a
> > > > > > > > string can be utf-8 encoded or it can be raw bytes on the
> > > > > > > > wire, depending on the size and chars, the encoding
> > > > > > > > handles and hides this detail. But if you go for direct
> access, you need to be aware of the encoding.
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com>
> wrote:
> > > > > > > > >
> > > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > Why you don't use the JMS API for this?
> > > > > > > > >
> > > > > > > > > or if you really want to use the core API, use the
> > > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > > jbertram@apache.org> wrote:
> > > > > > > > > >
> > > > > > > > > > The stack-trace indicates you're invoking the
> "readString"
> > > > > > > > > > method on line
> > > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see
> > > > > > > > > > that
> > > call
> > > > > > > > > > in the code you pasted. Therefore, that stack-trace
> > > > > > > > > > doesn't seem correct. Can you clarify this?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > > <er...@cgi.com>
> > > > > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > > Fyi:
> > > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) =
> > > > > > > > > > > "tive"(ascii
> > > > > > > > > > > text) And "tive" is likely part of the string
> "ActiveMQ"?
> > > > > > > > > > > e.
> > > > > > > > > > >
> > > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > > attachments unless
> > > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > > n’ouvrez
> > > > aucune pièce
> > > > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur
> > > fiable,
> > > > > > > > > > > ou que vous ayez l'assurance que le contenu provient
> > > > > > > > > > > d'une
> > > > source sûre.
> > > > > > > > > > >
> > > > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > > > >
> > > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading
> > > > > > > > > > > in simpleString,
> > > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > > im
> > > pleString.java:185)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > > im
> > > pleString.java:173)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > > ea
> > > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > > ea
> > > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > >
> > > >
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServer
> > > Ac
> > > tiveMQClient.java:93)
> > > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > > >
> > > >
> > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClien
> > > tT
> > > est.java:28)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > > ke0(
> > > > > > > > > > > Nati
> > > > > > > > > > > ve
> > > > > > > > > > > Method)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nativ
> > > eM
> > > ethodAccessorImpl.java:62)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(D
> > > el
> > > egatingMethodAccessorImpl.java:43)
> > > > > > > > > > >         at
> > > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framewor
> > > kM
> > > ethod.java:50)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCa
> > > ll
> > > able.java:12)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkM
> > > et
> > > hod.java:47)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMe
> > > th
> > > od.java:17)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > > nn
> > > er.java:78)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > > nn
> > > er.java:57)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > > >         at
> > > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit
> > > 4T
> > > estReference.java:89)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > > java:41)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > > te
> > > TestRunner.java:541)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > > te
> > > TestRunner.java:763)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTes
> > > tR
> > > unner.java:463)
> > > > > > > > > > >         at
> > > > > > > > > > >
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > > Remo
> > > > > > > > > > > teTe
> > > > > > > > > > > stRunner.java:209)
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > > Betreff: Re: send message
> > > > > > > > > > >
> > > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Justin
> > > > > > > > > > >
> > > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > > <Tobias.Wolf@t-systems.com
> > > >
> > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > > I try to send and receive a netty ByteBuf message,
> > > > > > > > > > > > but it
> > > > fails.
> > > > > > > > > > > > What I'm doing wrong here? I even don't know ist
> > > > > > > > > > > > he mistake in sending or receiving!
> > > > > > > > > > > > I was thinking to use the jms layer, but I'm
> > > > > > > > > > > > receiving
> > > the
> > > > > > > > > > > > data buffer throught a netty buffer and I want to
> > > > > > > > > > > > avoid
> > > to
> > > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > > >
> > > > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > > >              ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > > > > > > >              try {
> > > > > > > > > > > >                     session.start();
> > > > > > > > > > > >                     ClientMessage message =
> > > > session.createMessage(true);
> > > > > > > > > > > >
> > > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > > buf.readableBytes());
> > > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > > >              } finally {
> > > > > > > > > > > >                     session.close();
> > > > > > > > > > > >              }
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > > >        public ActiveMQBuffer
> > > receiveMessageFromSmtpQueue()
> > > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > > >              ClientSession session =
> > > > this.sessionFactory.createSession();
> > > > > > > > > > > >              try {
> > > > > > > > > > > >                     session.start();
> > > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > > >                     ClientMessage message =
> > > > consumer.receive();
> > > > > > > > > > > >                     result =
> > > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferS
> > > > > > > > > > > > iz
> > > > > > > > > > > > e());
> > > > > > > > > > > >
> > > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > > >              } finally {
> > > > > > > > > > > >                     session.close();
> > > > > > > > > > > >              }
> > > > > > > > > > > >
> > > > > > > > > > > >              return result;
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > > >              this.configuration = new
> > > ConfigurationImpl();
> > > > > > > > > > > >
> > > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm
> > > > > > > > > > > > ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > > >
> > > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > > >
> > > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > > >
> > > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > > >
> > > > > > > > > > > >              this.server = new
> > > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > > >              this.server.start();
> > > > > > > > > > > >        }
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Clebert Suconic
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > > >
> > >
>
>
>
> --
> Clebert Suconic
>
-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
So you mean I should save the ByteBuffer by myself to a file?

--> and pass it over the property that would stream the file directly. (Available on core only)
What do you mean? I understand that I shall pass the name of the file via a message property, right?
How would the receiver side looks like?


-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Donnerstag, 25. März 2021 16:04
An: users@activemq.apache.org
Betreff: Re: send message

Sending a message this large will make it to be converted as a large stream and saved as a file on the server anyways...

The copy between ByteBuffer and a byte array would become irrelevant at this point.

If you want to send a large message this big, you could save it to a file, and pass it over the property that would stream the file directly. (Available on core only)

And don't convert a large message between protocols.. use a single protocol of your choice.

On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
>
> What are you talking about?
> I want to send byte buffers with the size up to 500MB to a queue!
> What do you mean with string and micro optimization!
> The core api fails in my test already with sending/receiving a simple string, yes, a simple test!
> Does it make sense to have a 500mb native netty buffer received via wire and tunnel it back through the jvm?
> I don`t think so!
> Does it make sense to tunnel megabytes of data through a stream or even an byte array through the jvm?
> Where ist the advantage of jms?
> Why shall I not use the existing core api functions when the already support a netty buffer?
>
> -----Ursprüngliche Nachricht-----
> Von: Justin Bertram <jb...@apache.org>
> Gesendet: Mittwoch, 24. März 2021 17:56
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> Well said, Tim. I was going to say the same thing about premature optimization.
>
>
> Justin
>
> On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
>
> > One thing to keep in mind is that although the code may be slightly 
> > slower, if it lets you use an API that is more favorable (which 
> > might mean better documented, more portable, more stable across 
> > future versions, easier for others to maintain because they're 
> > already familiar with it, or a number of other potential advantages), that might be a win.
> >
> > Only you know your use case and whether the performance advantages 
> > of what you're trying to do actually outweigh the types of 
> > advantages I referenced in the first paragraph. But remember that 
> > premature optimization is the root of all evil, so make sure that 
> > your micro-optimization of avoiding the creation of a String is 
> > really a significant enough optimization in the context of your use 
> > case to justify the disadvantages of what you're trying to do.
> >
> > Tim
> >
> > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic 
> > <cl...@gmail.com>
> > wrote:
> >
> > > Not on the API itself.
> > >
> > > Try the core api example I sent you... and let me know what is 
> > > different from yours.
> > >
> > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > >
> > > > I want to use the jms layer, but I've a netty application and I 
> > > > want to
> > > write the ByteBuf mostly efficent to the queue.
> > > > I think it makes no sense to convert it back from a native 
> > > > buffer into
> > a
> > > byte array or stream and tunnel this throught the jvm!
> > > >
> > > > Is there a way to use a ByteBuf with jms?
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > You were supposed to call reset right before sending though... 
> > > > but I
> > did
> > > not need it on my test.. I will post a link...
> > > >
> > > > Anyway, if you use the JMS API, the JMS layer is very thin, and 
> > > > I don't
> > > think it would affect your performance in any way. you could 
> > > create a BytesMessage and all the detail would be hidden away from 
> > > the internal
> > API.
> > > >
> > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > clebert.suconic@gmail.com> wrote:
> > > > >
> > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > >
> > > > > give me 10 minutes and I will post a link here...
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > Same Issue!
> > > > > >         public void sendMessageToSmtpQueue(String text) 
> > > > > > throws
> > > ActiveMQException {
> > > > > >                 ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > >                 try {
> > > > > >                         session.start();
> > > > > >                         ClientMessage message =
> > > session.createMessage(true);
> > > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > > >                         message.getBodyBuffer().writeString(text);
> > > > > >                         ClientProducer producer =
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > >                         producer.send(message);
> > > > > >                 } finally {
> > > > > >                         session.close();
> > > > > >                 }
> > > > > >         }
> > > > > >
> > > > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > > > simpleString,
> > > length=1953068645 is greater than readableBytes=3
> > > > > >         at
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > im
> > pleString.java:185)
> > > > > >         at
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > im
> > pleString.java:173)
> > > > > >         at
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > ea
> > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > >         at
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > ea
> > dString(ChannelBufferWrapper.java:98)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > >
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServer
> > Ac
> > tiveMQClient.java:94)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > >
> > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerAc
> > ti
> > veMQClientTest.java:37)
> > > > > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Na
> > > ti
> > > ve
> > > Method)
> > > > > >         at
> > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nativ
> > eM
> > ethodAccessorImpl.java:62)
> > > > > >         at
> > >
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(D
> > el
> > egatingMethodAccessorImpl.java:43)
> > > > > >         at
> > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > >         at
> > >
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framewor
> > kM
> > ethod.java:50)
> > > > > >         at
> > >
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCa
> > ll
> > able.java:12)
> > > > > >         at
> > >
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkM
> > et
> > hod.java:47)
> > > > > >         at
> > >
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMe
> > th
> > od.java:17)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > >         at
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > nn
> > er.java:78)
> > > > > >         at
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > nn
> > er.java:57)
> > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > >         at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit
> > 4T
> > estReference.java:89)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > java:41)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > te
> > TestRunner.java:541)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > te
> > TestRunner.java:763)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTes
> > tR
> > unner.java:463)
> > > > > >         at
> > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > > stRunner.java:209)
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Can you try calling
> > > > > > message.getBodyBuffer().resetReaderIndex();
> > > before the send?
> > > > > >
> > > > > > if that does not work I will try your code and see what happens.
> > > > > > (Let me know if doesn't please)
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully 
> > > > > > <ga...@gmail.com>
> > > wrote:
> > > > > > >
> > > > > > > maybe take inspiration from
> > > > > > >
> > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > rati
> > > > > > >
> > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > on/c lient/MessageBufferTest.java that passes a string, 
> > > > > > > but there are corresponding byte[] or buffer variants in 
> > > > > > > the api. If you want to skip the decoding, to access the 
> > > > > > > raw buffer, you need to parse the type to get to the appropriate part of the buffer.
> > > > > > > There are loads of usage examples in the tests and they 
> > > > > > > all work, start there and break it as you go.
> > > > > > >
> > > > > > > the issue is the wire level encoding that the client does, 
> > > > > > > the
> > JMS
> > > > > > > api hides this, as do the typed accessors, but you can get 
> > > > > > > direct access to the encoded buffers via the core api as 
> > > > > > > you are doing but you need to be type aware, for example a 
> > > > > > > string can be utf-8 encoded or it can be raw bytes on the 
> > > > > > > wire, depending on the size and chars, the encoding 
> > > > > > > handles and hides this detail. But if you go for direct access, you need to be aware of the encoding.
> > > > > > >
> > > > > > >
> > > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > > >
> > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > Why you don't use the JMS API for this?
> > > > > > > >
> > > > > > > > or if you really want to use the core API, use the
> > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > jbertram@apache.org> wrote:
> > > > > > > > >
> > > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > > method on line
> > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see 
> > > > > > > > > that
> > call
> > > > > > > > > in the code you pasted. Therefore, that stack-trace 
> > > > > > > > > doesn't seem correct. Can you clarify this?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> > > > > > > > > <er...@cgi.com>
> > > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > > Fyi:
> > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = 
> > > > > > > > > > "tive"(ascii
> > > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > > e.
> > > > > > > > > >
> > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > Van: Tobias.Wolf@t-systems.com 
> > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > attachments unless
> > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > n’ouvrez
> > > aucune pièce
> > > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur
> > fiable,
> > > > > > > > > > ou que vous ayez l'assurance que le contenu provient 
> > > > > > > > > > d'une
> > > source sûre.
> > > > > > > > > >
> > > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > > >
> > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading 
> > > > > > > > > > in simpleString,
> > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > im
> > pleString.java:185)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(S
> > im
> > pleString.java:173)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > ea
> > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.r
> > ea
> > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > >
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServer
> > Ac
> > tiveMQClient.java:93)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > >
> > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClien
> > tT
> > est.java:28)
> > > > > > > > > >         at
> > > > > > > > > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > ke0(
> > > > > > > > > > Nati
> > > > > > > > > > ve
> > > > > > > > > > Method)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Nativ
> > eM
> > ethodAccessorImpl.java:62)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(D
> > el
> > egatingMethodAccessorImpl.java:43)
> > > > > > > > > >         at
> > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framewor
> > kM
> > ethod.java:50)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCa
> > ll
> > able.java:12)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkM
> > et
> > hod.java:47)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMe
> > th
> > od.java:17)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > nn
> > er.java:78)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > nn
> > er.java:57)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit
> > 4T
> > estReference.java:89)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > java:41)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > te
> > TestRunner.java:541)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > te
> > TestRunner.java:763)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTes
> > tR
> > unner.java:463)
> > > > > > > > > >         at
> > > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > Remo
> > > > > > > > > > teTe
> > > > > > > > > > stRunner.java:209)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM 
> > > > > > > > > > <Tobias.Wolf@t-systems.com
> > >
> > > wrote:
> > > > > > > > > >
> > > > > > > > > > > I try to send and receive a netty ByteBuf message, 
> > > > > > > > > > > but it
> > > fails.
> > > > > > > > > > > What I'm doing wrong here? I even don't know ist 
> > > > > > > > > > > he mistake in sending or receiving!
> > > > > > > > > > > I was thinking to use the jms layer, but I'm 
> > > > > > > > > > > receiving
> > the
> > > > > > > > > > > data buffer throught a netty buffer and I want to 
> > > > > > > > > > > avoid
> > to
> > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > >
> > > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientMessage message =
> > > session.createMessage(true);
> > > > > > > > > > >
> > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > buf.readableBytes());
> > > > > > > > > > >                     ClientProducer producer = 
> > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >        public ActiveMQBuffer
> > receiveMessageFromSmtpQueue()
> > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientConsumer consumer = 
> > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     ClientMessage message =
> > > consumer.receive();
> > > > > > > > > > >                     result = 
> > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferS
> > > > > > > > > > > iz
> > > > > > > > > > > e());
> > > > > > > > > > >
> > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >
> > > > > > > > > > >              return result;
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > >              this.configuration = new
> > ConfigurationImpl();
> > > > > > > > > > >
> > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm
> > > > > > > > > > > ", ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > >
> > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > >
> > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > >
> > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > >
> > > > > > > > > > >              this.server = new
> > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > >              this.server.start();
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> > >
> >



--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
Sending a message this large will make it to be converted as a large
stream and saved as a file on the server anyways...

The copy between ByteBuffer and a byte array would become irrelevant
at this point.

If you want to send a large message this big, you could save it to a
file, and pass it over the property that would stream the file
directly. (Available on core only)

And don't convert a large message between protocols.. use a single
protocol of your choice.

On Thu, Mar 25, 2021 at 3:44 AM <To...@t-systems.com> wrote:
>
> What are you talking about?
> I want to send byte buffers with the size up to 500MB to a queue!
> What do you mean with string and micro optimization!
> The core api fails in my test already with sending/receiving a simple string, yes, a simple test!
> Does it make sense to have a 500mb native netty buffer received via wire and tunnel it back through the jvm?
> I don`t think so!
> Does it make sense to tunnel megabytes of data through a stream or even an byte array through the jvm?
> Where ist the advantage of jms?
> Why shall I not use the existing core api functions when the already support a netty buffer?
>
> -----Ursprüngliche Nachricht-----
> Von: Justin Bertram <jb...@apache.org>
> Gesendet: Mittwoch, 24. März 2021 17:56
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> Well said, Tim. I was going to say the same thing about premature optimization.
>
>
> Justin
>
> On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:
>
> > One thing to keep in mind is that although the code may be slightly
> > slower, if it lets you use an API that is more favorable (which might
> > mean better documented, more portable, more stable across future
> > versions, easier for others to maintain because they're already
> > familiar with it, or a number of other potential advantages), that might be a win.
> >
> > Only you know your use case and whether the performance advantages of
> > what you're trying to do actually outweigh the types of advantages I
> > referenced in the first paragraph. But remember that premature
> > optimization is the root of all evil, so make sure that your
> > micro-optimization of avoiding the creation of a String is really a
> > significant enough optimization in the context of your use case to
> > justify the disadvantages of what you're trying to do.
> >
> > Tim
> >
> > On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic
> > <cl...@gmail.com>
> > wrote:
> >
> > > Not on the API itself.
> > >
> > > Try the core api example I sent you... and let me know what is
> > > different from yours.
> > >
> > > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > > >
> > > > I want to use the jms layer, but I've a netty application and I
> > > > want to
> > > write the ByteBuf mostly efficent to the queue.
> > > > I think it makes no sense to convert it back from a native buffer
> > > > into
> > a
> > > byte array or stream and tunnel this throught the jvm!
> > > >
> > > > Is there a way to use a ByteBuf with jms?
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 15:00
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > You were supposed to call reset right before sending though... but
> > > > I
> > did
> > > not need it on my test.. I will post a link...
> > > >
> > > > Anyway, if you use the JMS API, the JMS layer is very thin, and I
> > > > don't
> > > think it would affect your performance in any way. you could create
> > > a BytesMessage and all the detail would be hidden away from the
> > > internal
> > API.
> > > >
> > > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > > clebert.suconic@gmail.com> wrote:
> > > > >
> > > > > I'm adding a test doing exactly what you did, and it's working...
> > > > >
> > > > > give me 10 minutes and I will post a link here...
> > > > >
> > > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > Same Issue!
> > > > > >         public void sendMessageToSmtpQueue(String text) throws
> > > ActiveMQException {
> > > > > >                 ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > >                 try {
> > > > > >                         session.start();
> > > > > >                         ClientMessage message =
> > > session.createMessage(true);
> > > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > > >                         message.getBodyBuffer().writeString(text);
> > > > > >                         ClientProducer producer =
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > >                         producer.send(message);
> > > > > >                 } finally {
> > > > > >                         session.close();
> > > > > >                 }
> > > > > >         }
> > > > > >
> > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > simpleString,
> > > length=1953068645 is greater than readableBytes=3
> > > > > >         at
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> > pleString.java:185)
> > > > > >         at
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> > pleString.java:173)
> > > > > >         at
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > >         at
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> > dString(ChannelBufferWrapper.java:98)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > >
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerAc
> > tiveMQClient.java:94)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > >
> > .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActi
> > veMQClientTest.java:37)
> > > > > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Nati
> > > ve
> > > Method)
> > > > > >         at
> > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeM
> > ethodAccessorImpl.java:62)
> > > > > >         at
> > >
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Del
> > egatingMethodAccessorImpl.java:43)
> > > > > >         at
> > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > >         at
> > >
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkM
> > ethod.java:50)
> > > > > >         at
> > >
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCall
> > able.java:12)
> > > > > >         at
> > >
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMet
> > hod.java:47)
> > > > > >         at
> > >
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMeth
> > od.java:17)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > >         at
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> > er.java:78)
> > > > > >         at
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> > er.java:57)
> > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > >         at
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > >         at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4T
> > estReference.java:89)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > java:41)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> > TestRunner.java:541)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> > TestRunner.java:763)
> > > > > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestR
> > unner.java:463)
> > > > > >         at
> > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > > stRunner.java:209)
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Can you try calling
> > > > > > message.getBodyBuffer().resetReaderIndex();
> > > before the send?
> > > > > >
> > > > > > if that does not work I will try your code and see what happens.
> > > > > > (Let me know if doesn't please)
> > > > > >
> > > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully
> > > > > > <ga...@gmail.com>
> > > wrote:
> > > > > > >
> > > > > > > maybe take inspiration from
> > > > > > >
> > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > > rati
> > > > > > >
> > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > > on/c lient/MessageBufferTest.java that passes a string, but
> > > > > > > there are corresponding byte[] or buffer variants in the
> > > > > > > api. If you want to skip the decoding, to access the raw
> > > > > > > buffer, you need to parse the type to get to the appropriate part of the buffer.
> > > > > > > There are loads of usage examples in the tests and they all
> > > > > > > work, start there and break it as you go.
> > > > > > >
> > > > > > > the issue is the wire level encoding that the client does,
> > > > > > > the
> > JMS
> > > > > > > api hides this, as do the typed accessors, but you can get
> > > > > > > direct access to the encoded buffers via the core api as you
> > > > > > > are doing but you need to be type aware, for example a
> > > > > > > string can be utf-8 encoded or it can be raw bytes on the
> > > > > > > wire, depending on the size and chars, the encoding handles
> > > > > > > and hides this detail. But if you go for direct access, you need to be aware of the encoding.
> > > > > > >
> > > > > > >
> > > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > > >
> > > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > Why you don't use the JMS API for this?
> > > > > > > >
> > > > > > > > or if you really want to use the core API, use the
> > > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > > jbertram@apache.org> wrote:
> > > > > > > > >
> > > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > > method on line
> > > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see
> > > > > > > > > that
> > call
> > > > > > > > > in the code you pasted. Therefore, that stack-trace
> > > > > > > > > doesn't seem correct. Can you clarify this?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > > <er...@cgi.com>
> > > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > > Fyi:
> > > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) =
> > > > > > > > > > "tive"(ascii
> > > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > > e.
> > > > > > > > > >
> > > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > > Van: Tobias.Wolf@t-systems.com
> > > > > > > > > > <To...@t-systems.com>
> > > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > > Onderwerp: AW: send message
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > > attachments unless
> > > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> > n’ouvrez
> > > aucune pièce
> > > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur
> > fiable,
> > > > > > > > > > ou que vous ayez l'assurance que le contenu provient
> > > > > > > > > > d'une
> > > source sûre.
> > > > > > > > > >
> > > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > > >
> > > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > > simpleString,
> > > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> > pleString.java:185)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> > pleString.java:173)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> > dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> > dString(ChannelBufferWrapper.java:98)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > >
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerAc
> > tiveMQClient.java:93)
> > > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > > >
> > >
> > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientT
> > est.java:28)
> > > > > > > > > >         at
> > > > > > > > > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > > ke0(
> > > > > > > > > > Nati
> > > > > > > > > > ve
> > > > > > > > > > Method)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeM
> > ethodAccessorImpl.java:62)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Del
> > egatingMethodAccessorImpl.java:43)
> > > > > > > > > >         at
> > > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkM
> > ethod.java:50)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCall
> > able.java:12)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMet
> > hod.java:47)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMeth
> > od.java:17)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> > er.java:78)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> > er.java:57)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > > >         at
> > > > > > > > > >
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > > >         at
> > > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4T
> > estReference.java:89)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > java:41)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> > TestRunner.java:541)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> > TestRunner.java:763)
> > > > > > > > > >         at
> > > > > > > > > >
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestR
> > unner.java:463)
> > > > > > > > > >         at
> > > > > > > > > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > > Remo
> > > > > > > > > > teTe
> > > > > > > > > > stRunner.java:209)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > > Betreff: Re: send message
> > > > > > > > > >
> > > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Justin
> > > > > > > > > >
> > > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM
> > > > > > > > > > <Tobias.Wolf@t-systems.com
> > >
> > > wrote:
> > > > > > > > > >
> > > > > > > > > > > I try to send and receive a netty ByteBuf message,
> > > > > > > > > > > but it
> > > fails.
> > > > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > > I was thinking to use the jms layer, but I'm
> > > > > > > > > > > receiving
> > the
> > > > > > > > > > > data buffer throught a netty buffer and I want to
> > > > > > > > > > > avoid
> > to
> > > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > > >
> > > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf
> > > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientMessage message =
> > > session.createMessage(true);
> > > > > > > > > > >
> > > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > > buf.readableBytes());
> > > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     producer.send(message);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >        public ActiveMQBuffer
> > receiveMessageFromSmtpQueue()
> > > > > > > > > > > throws ActiveMQException {
> > > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > > >              ClientSession session =
> > > this.sessionFactory.createSession();
> > > > > > > > > > >              try {
> > > > > > > > > > >                     session.start();
> > > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > > >                     ClientMessage message =
> > > consumer.receive();
> > > > > > > > > > >                     result =
> > > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSiz
> > > > > > > > > > > e());
> > > > > > > > > > >
> > >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > > >              } finally {
> > > > > > > > > > >                     session.close();
> > > > > > > > > > >              }
> > > > > > > > > > >
> > > > > > > > > > >              return result;
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > > >              this.configuration = new
> > ConfigurationImpl();
> > > > > > > > > > >
> > > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > > >
> > > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > > >
> > this.configuration.setSecurityEnabled(false);
> > > > > > > > > > >
> > > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > > >
> > > > > > > > > > >              this.server = new
> > > ActiveMQServerImpl(this.configuration);
> > > > > > > > > > >              this.server.start();
> > > > > > > > > > >        }
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Clebert Suconic
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> > >
> >



-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
What are you talking about?
I want to send byte buffers with the size up to 500MB to a queue!
What do you mean with string and micro optimization!
The core api fails in my test already with sending/receiving a simple string, yes, a simple test!
Does it make sense to have a 500mb native netty buffer received via wire and tunnel it back through the jvm?
I don`t think so!
Does it make sense to tunnel megabytes of data through a stream or even an byte array through the jvm?
Where ist the advantage of jms?
Why shall I not use the existing core api functions when the already support a netty buffer?

-----Ursprüngliche Nachricht-----
Von: Justin Bertram <jb...@apache.org> 
Gesendet: Mittwoch, 24. März 2021 17:56
An: users@activemq.apache.org
Betreff: Re: send message

Well said, Tim. I was going to say the same thing about premature optimization.


Justin

On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:

> One thing to keep in mind is that although the code may be slightly 
> slower, if it lets you use an API that is more favorable (which might 
> mean better documented, more portable, more stable across future 
> versions, easier for others to maintain because they're already 
> familiar with it, or a number of other potential advantages), that might be a win.
>
> Only you know your use case and whether the performance advantages of 
> what you're trying to do actually outweigh the types of advantages I 
> referenced in the first paragraph. But remember that premature 
> optimization is the root of all evil, so make sure that your 
> micro-optimization of avoiding the creation of a String is really a 
> significant enough optimization in the context of your use case to 
> justify the disadvantages of what you're trying to do.
>
> Tim
>
> On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic 
> <cl...@gmail.com>
> wrote:
>
> > Not on the API itself.
> >
> > Try the core api example I sent you... and let me know what is 
> > different from yours.
> >
> > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > >
> > > I want to use the jms layer, but I've a netty application and I 
> > > want to
> > write the ByteBuf mostly efficent to the queue.
> > > I think it makes no sense to convert it back from a native buffer 
> > > into
> a
> > byte array or stream and tunnel this throught the jvm!
> > >
> > > Is there a way to use a ByteBuf with jms?
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Dienstag, 23. März 2021 15:00
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > You were supposed to call reset right before sending though... but 
> > > I
> did
> > not need it on my test.. I will post a link...
> > >
> > > Anyway, if you use the JMS API, the JMS layer is very thin, and I 
> > > don't
> > think it would affect your performance in any way. you could create 
> > a BytesMessage and all the detail would be hidden away from the 
> > internal
> API.
> > >
> > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > clebert.suconic@gmail.com> wrote:
> > > >
> > > > I'm adding a test doing exactly what you did, and it's working...
> > > >
> > > > give me 10 minutes and I will post a link here...
> > > >
> > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > Same Issue!
> > > > >         public void sendMessageToSmtpQueue(String text) throws
> > ActiveMQException {
> > > > >                 ClientSession session =
> > this.sessionFactory.createSession();
> > > > >                 try {
> > > > >                         session.start();
> > > > >                         ClientMessage message =
> > session.createMessage(true);
> > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > >                         message.getBodyBuffer().writeString(text);
> > > > >                         ClientProducer producer =
> > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                         producer.send(message);
> > > > >                 } finally {
> > > > >                         session.close();
> > > > >                 }
> > > > >         }
> > > > >
> > > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > > simpleString,
> > length=1953068645 is greater than readableBytes=3
> > > > >         at
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> pleString.java:185)
> > > > >         at
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> pleString.java:173)
> > > > >         at
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> dStringInternal(ChannelBufferWrapper.java:113)
> > > > >         at
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> dString(ChannelBufferWrapper.java:98)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerAc
> tiveMQClient.java:94)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> >
> .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActi
> veMQClientTest.java:37)
> > > > >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Nati
> > ve
> > Method)
> > > > >         at
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeM
> ethodAccessorImpl.java:62)
> > > > >         at
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Del
> egatingMethodAccessorImpl.java:43)
> > > > >         at
> java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > >         at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkM
> ethod.java:50)
> > > > >         at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCall
> able.java:12)
> > > > >         at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMet
> hod.java:47)
> > > > >         at
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMeth
> od.java:17)
> > > > >         at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> er.java:78)
> > > > >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> er.java:57)
> > > > >         at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > >         at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > >         at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > >         at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > >         at
> org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4T
> estReference.java:89)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> java:41)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> TestRunner.java:541)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> TestRunner.java:763)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestR
> unner.java:463)
> > > > >         at
> > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > stRunner.java:209)
> > > > >
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Can you try calling 
> > > > > message.getBodyBuffer().resetReaderIndex();
> > before the send?
> > > > >
> > > > > if that does not work I will try your code and see what happens.
> > > > > (Let me know if doesn't please)
> > > > >
> > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully 
> > > > > <ga...@gmail.com>
> > wrote:
> > > > > >
> > > > > > maybe take inspiration from
> > > > > >
> https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > rati
> > > > > >
> on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > on/c lient/MessageBufferTest.java that passes a string, but 
> > > > > > there are corresponding byte[] or buffer variants in the 
> > > > > > api. If you want to skip the decoding, to access the raw 
> > > > > > buffer, you need to parse the type to get to the appropriate part of the buffer.
> > > > > > There are loads of usage examples in the tests and they all 
> > > > > > work, start there and break it as you go.
> > > > > >
> > > > > > the issue is the wire level encoding that the client does, 
> > > > > > the
> JMS
> > > > > > api hides this, as do the typed accessors, but you can get 
> > > > > > direct access to the encoded buffers via the core api as you 
> > > > > > are doing but you need to be type aware, for example a 
> > > > > > string can be utf-8 encoded or it can be raw bytes on the 
> > > > > > wire, depending on the size and chars, the encoding handles 
> > > > > > and hides this detail. But if you go for direct access, you need to be aware of the encoding.
> > > > > >
> > > > > >
> > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Why you don't use the JMS API for this?
> > > > > > >
> > > > > > > or if you really want to use the core API, use the
> > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > >
> > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > jbertram@apache.org> wrote:
> > > > > > > >
> > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > method on line
> > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see 
> > > > > > > > that
> call
> > > > > > > > in the code you pasted. Therefore, that stack-trace 
> > > > > > > > doesn't seem correct. Can you clarify this?
> > > > > > > >
> > > > > > > >
> > > > > > > > Justin
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> > > > > > > > <er...@cgi.com>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > > > Fyi:
> > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = 
> > > > > > > > > "tive"(ascii
> > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > e.
> > > > > > > > >
> > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > Van: Tobias.Wolf@t-systems.com 
> > > > > > > > > <To...@t-systems.com>
> > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > Onderwerp: AW: send message
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > attachments unless
> > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> n’ouvrez
> > aucune pièce
> > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur
> fiable,
> > > > > > > > > ou que vous ayez l'assurance que le contenu provient 
> > > > > > > > > d'une
> > source sûre.
> > > > > > > > >
> > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > >
> > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > > > > > > simpleString,
> > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> pleString.java:185)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(Sim
> pleString.java:173)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> dStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.rea
> dString(ChannelBufferWrapper.java:98)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerAc
> tiveMQClient.java:93)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> >
> .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientT
> est.java:28)
> > > > > > > > >         at
> > > > > > > > >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > ke0(
> > > > > > > > > Nati
> > > > > > > > > ve
> > > > > > > > > Method)
> > > > > > > > >         at
> > > > > > > > >
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeM
> ethodAccessorImpl.java:62)
> > > > > > > > >         at
> > > > > > > > >
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Del
> egatingMethodAccessorImpl.java:43)
> > > > > > > > >         at
> > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkM
> ethod.java:50)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCall
> able.java:12)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMet
> hod.java:47)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMeth
> od.java:17)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> er.java:78)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn
> er.java:57)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4T
> estReference.java:89)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> java:41)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> TestRunner.java:541)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
> TestRunner.java:763)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestR
> unner.java:463)
> > > > > > > > >         at
> > > > > > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > Remo
> > > > > > > > > teTe
> > > > > > > > > stRunner.java:209)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM 
> > > > > > > > > <Tobias.Wolf@t-systems.com
> >
> > wrote:
> > > > > > > > >
> > > > > > > > > > I try to send and receive a netty ByteBuf message, 
> > > > > > > > > > but it
> > fails.
> > > > > > > > > > What I'm doing wrong here? I even don't know ist he 
> > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > I was thinking to use the jms layer, but I'm 
> > > > > > > > > > receiving
> the
> > > > > > > > > > data buffer throught a netty buffer and I want to 
> > > > > > > > > > avoid
> to
> > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > >
> > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf 
> > > > > > > > > > buf) throws ActiveMQException {
> > > > > > > > > >              ClientSession session =
> > this.sessionFactory.createSession();
> > > > > > > > > >              try {
> > > > > > > > > >                     session.start();
> > > > > > > > > >                     ClientMessage message =
> > session.createMessage(true);
> > > > > > > > > >
> > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > buf.readableBytes());
> > > > > > > > > >                     ClientProducer producer = 
> > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                     producer.send(message);
> > > > > > > > > >              } finally {
> > > > > > > > > >                     session.close();
> > > > > > > > > >              }
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > > >        public ActiveMQBuffer
> receiveMessageFromSmtpQueue()
> > > > > > > > > > throws ActiveMQException {
> > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > >              ClientSession session =
> > this.sessionFactory.createSession();
> > > > > > > > > >              try {
> > > > > > > > > >                     session.start();
> > > > > > > > > >                     ClientConsumer consumer = 
> > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                     ClientMessage message =
> > consumer.receive();
> > > > > > > > > >                     result = 
> > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSiz
> > > > > > > > > > e());
> > > > > > > > > >
> >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > >              } finally {
> > > > > > > > > >                     session.close();
> > > > > > > > > >              }
> > > > > > > > > >
> > > > > > > > > >              return result;
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > >              this.configuration = new
> ConfigurationImpl();
> > > > > > > > > >
> > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > >
> > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > >
> this.configuration.setSecurityEnabled(false);
> > > > > > > > > >              
> > > > > > > > > > this.configuration.addQueueConfiguration(new
> > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > >
> > > > > > > > > >              this.server = new
> > ActiveMQServerImpl(this.configuration);
> > > > > > > > > >              this.server.start();
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
> >
>

Re: send message

Posted by Justin Bertram <jb...@apache.org>.
Well said, Tim. I was going to say the same thing about premature
optimization.


Justin

On Wed, Mar 24, 2021 at 7:04 AM Tim Bain <tb...@alumni.duke.edu> wrote:

> One thing to keep in mind is that although the code may be slightly slower,
> if it lets you use an API that is more favorable (which might mean better
> documented, more portable, more stable across future versions, easier for
> others to maintain because they're already familiar with it, or a number of
> other potential advantages), that might be a win.
>
> Only you know your use case and whether the performance advantages of what
> you're trying to do actually outweigh the types of advantages I referenced
> in the first paragraph. But remember that premature optimization is the
> root of all evil, so make sure that your micro-optimization of avoiding the
> creation of a String is really a significant enough optimization in the
> context of your use case to justify the disadvantages of what you're trying
> to do.
>
> Tim
>
> On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic <cl...@gmail.com>
> wrote:
>
> > Not on the API itself.
> >
> > Try the core api example I sent you... and let me know what is
> > different from yours.
> >
> > On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> > >
> > > I want to use the jms layer, but I've a netty application and I want to
> > write the ByteBuf mostly efficent to the queue.
> > > I think it makes no sense to convert it back from a native buffer into
> a
> > byte array or stream and tunnel this throught the jvm!
> > >
> > > Is there a way to use a ByteBuf with jms?
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Dienstag, 23. März 2021 15:00
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > You were supposed to call reset right before sending though... but I
> did
> > not need it on my test.. I will post a link...
> > >
> > > Anyway, if you use the JMS API, the JMS layer is very thin, and I don't
> > think it would affect your performance in any way. you could create a
> > BytesMessage and all the detail would be hidden away from the internal
> API.
> > >
> > > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> > clebert.suconic@gmail.com> wrote:
> > > >
> > > > I'm adding a test doing exactly what you did, and it's working...
> > > >
> > > > give me 10 minutes and I will post a link here...
> > > >
> > > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > Same Issue!
> > > > >         public void sendMessageToSmtpQueue(String text) throws
> > ActiveMQException {
> > > > >                 ClientSession session =
> > this.sessionFactory.createSession();
> > > > >                 try {
> > > > >                         session.start();
> > > > >                         ClientMessage message =
> > session.createMessage(true);
> > > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > > >                         message.getBodyBuffer().resetReaderIndex();
> > > > >                         message.getBodyBuffer().writeString(text);
> > > > >                         ClientProducer producer =
> > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                         producer.send(message);
> > > > >                 } finally {
> > > > >                         session.close();
> > > > >                 }
> > > > >         }
> > > > >
> > > > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > length=1953068645 is greater than readableBytes=3
> > > > >         at
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > >         at
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > >         at
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > >         at
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> >
> .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > > > >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > > > >         at
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > >         at
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > >         at
> java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > >         at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > >         at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > >         at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > >         at
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > >         at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > >         at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > >         at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > >         at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > >         at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > >         at
> org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > >         at
> > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > > stRunner.java:209)
> > > > >
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Can you try calling message.getBodyBuffer().resetReaderIndex();
> > before the send?
> > > > >
> > > > > if that does not work I will try your code and see what happens.
> > > > > (Let me know if doesn't please)
> > > > >
> > > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com>
> > wrote:
> > > > > >
> > > > > > maybe take inspiration from
> > > > > >
> https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > > rati
> > > > > >
> on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > > on/c lient/MessageBufferTest.java that passes a string, but there
> > > > > > are corresponding byte[] or buffer variants in the api. If you
> > > > > > want to skip the decoding, to access the raw buffer, you need to
> > > > > > parse the type to get to the appropriate part of the buffer.
> > > > > > There are loads of usage examples in the tests and they all work,
> > > > > > start there and break it as you go.
> > > > > >
> > > > > > the issue is the wire level encoding that the client does, the
> JMS
> > > > > > api hides this, as do the typed accessors, but you can get direct
> > > > > > access to the encoded buffers via the core api as you are doing
> > > > > > but you need to be type aware, for example a string can be utf-8
> > > > > > encoded or it can be raw bytes on the wire, depending on the size
> > > > > > and chars, the encoding handles and hides this detail. But if you
> > > > > > go for direct access, you need to be aware of the encoding.
> > > > > >
> > > > > >
> > > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > getDataBuffer gives same result! Already tried!
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > Why you don't use the JMS API for this?
> > > > > > >
> > > > > > > or if you really want to use the core API, use the
> > getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > > >
> > > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> > jbertram@apache.org> wrote:
> > > > > > > >
> > > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > > method on line
> > > > > > > > 93 of MailServerActiveMQClient.java, but I don't see that
> call
> > > > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > > > seem correct. Can you clarify this?
> > > > > > > >
> > > > > > > >
> > > > > > > > Justin
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > > <er...@cgi.com>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > > > Fyi:
> > > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii
> > > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > > e.
> > > > > > > > >
> > > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > > Onderwerp: AW: send message
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> > attachments unless
> > > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et
> n’ouvrez
> > aucune pièce
> > > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur
> fiable,
> > > > > > > > > ou que vous ayez l'assurance que le contenu provient d'une
> > source sûre.
> > > > > > > > >
> > > > > > > > > While sending / receiving a text message I get this
> > > > > > > > >
> > > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > > simpleString,
> > > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > > >
> >
> .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > > > >         at
> > > > > > > > >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > > ke0(
> > > > > > > > > Nati
> > > > > > > > > ve
> > > > > > > > > Method)
> > > > > > > > >         at
> > > > > > > > >
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > > > >         at
> > > > > > > > >
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > > > >         at
> > java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > > >         at
> > > > > > > > >
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > > >         at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > > > >         at
> > > > > > > > >
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > > > >         at
> > > > > > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > > Remo
> > > > > > > > > teTe
> > > > > > > > > stRunner.java:209)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > > An: users@activemq.apache.org
> > > > > > > > > Betreff: Re: send message
> > > > > > > > >
> > > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Justin
> > > > > > > > >
> > > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <Tobias.Wolf@t-systems.com
> >
> > wrote:
> > > > > > > > >
> > > > > > > > > > I try to send and receive a netty ByteBuf message, but it
> > fails.
> > > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > > mistake in sending or receiving!
> > > > > > > > > > I was thinking to use the jms layer, but I'm receiving
> the
> > > > > > > > > > data buffer throught a netty buffer and I want to avoid
> to
> > > > > > > > > > convert the buffer to a byte array!
> > > > > > > > > >
> > > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > > > throws ActiveMQException {
> > > > > > > > > >              ClientSession session =
> > this.sessionFactory.createSession();
> > > > > > > > > >              try {
> > > > > > > > > >                     session.start();
> > > > > > > > > >                     ClientMessage message =
> > session.createMessage(true);
> > > > > > > > > >
> > > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> > buf.readableBytes());
> > > > > > > > > >                     ClientProducer producer =
> > > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                     producer.send(message);
> > > > > > > > > >              } finally {
> > > > > > > > > >                     session.close();
> > > > > > > > > >              }
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > > >        public ActiveMQBuffer
> receiveMessageFromSmtpQueue()
> > > > > > > > > > throws ActiveMQException {
> > > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > > >              ClientSession session =
> > this.sessionFactory.createSession();
> > > > > > > > > >              try {
> > > > > > > > > >                     session.start();
> > > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > > >                     ClientMessage message =
> > consumer.receive();
> > > > > > > > > >                     result =
> > > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > > > >
> >  message.getBodyBuffer().readBytes(result);
> > > > > > > > > >              } finally {
> > > > > > > > > >                     session.close();
> > > > > > > > > >              }
> > > > > > > > > >
> > > > > > > > > >              return result;
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > > >              this.configuration = new
> ConfigurationImpl();
> > > > > > > > > >
> > > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > > >
> > this.configuration.setPersistenceEnabled(true);
> > > > > > > > > >
> this.configuration.setSecurityEnabled(false);
> > > > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > > >
> > > > > > > > > >              this.server = new
> > ActiveMQServerImpl(this.configuration);
> > > > > > > > > >              this.server.start();
> > > > > > > > > >        }
> > > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Clebert Suconic
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
> >
>

Re: send message

Posted by Tim Bain <tb...@alumni.duke.edu>.
One thing to keep in mind is that although the code may be slightly slower,
if it lets you use an API that is more favorable (which might mean better
documented, more portable, more stable across future versions, easier for
others to maintain because they're already familiar with it, or a number of
other potential advantages), that might be a win.

Only you know your use case and whether the performance advantages of what
you're trying to do actually outweigh the types of advantages I referenced
in the first paragraph. But remember that premature optimization is the
root of all evil, so make sure that your micro-optimization of avoiding the
creation of a String is really a significant enough optimization in the
context of your use case to justify the disadvantages of what you're trying
to do.

Tim

On Tue, Mar 23, 2021, 9:20 AM Clebert Suconic <cl...@gmail.com>
wrote:

> Not on the API itself.
>
> Try the core api example I sent you... and let me know what is
> different from yours.
>
> On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
> >
> > I want to use the jms layer, but I've a netty application and I want to
> write the ByteBuf mostly efficent to the queue.
> > I think it makes no sense to convert it back from a native buffer into a
> byte array or stream and tunnel this throught the jvm!
> >
> > Is there a way to use a ByteBuf with jms?
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Dienstag, 23. März 2021 15:00
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > You were supposed to call reset right before sending though... but I did
> not need it on my test.. I will post a link...
> >
> > Anyway, if you use the JMS API, the JMS layer is very thin, and I don't
> think it would affect your performance in any way. you could create a
> BytesMessage and all the detail would be hidden away from the internal API.
> >
> > On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <
> clebert.suconic@gmail.com> wrote:
> > >
> > > I'm adding a test doing exactly what you did, and it's working...
> > >
> > > give me 10 minutes and I will post a link here...
> > >
> > > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > > >
> > > > Same Issue!
> > > >         public void sendMessageToSmtpQueue(String text) throws
> ActiveMQException {
> > > >                 ClientSession session =
> this.sessionFactory.createSession();
> > > >                 try {
> > > >                         session.start();
> > > >                         ClientMessage message =
> session.createMessage(true);
> > > >                         message.setType(ClientMessage.TEXT_TYPE);
> > > >                         message.getBodyBuffer().resetReaderIndex();
> > > >                         message.getBodyBuffer().writeString(text);
> > > >                         ClientProducer producer =
> session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > >                         producer.send(message);
> > > >                 } finally {
> > > >                         session.close();
> > > >                 }
> > > >         }
> > > >
> > > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> length=1953068645 is greater than readableBytes=3
> > > >         at
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > >         at
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > >         at
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > >         at
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > >         at com.tsystems.gematik.kim.mailserver.mq
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > > >         at com.tsystems.gematik.kim.mailserver.mq
> .MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > > >         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> > > >         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > >         at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > >         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > >         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > >         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > >         at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > >         at
> org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > >         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > >         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > >         at
> org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > >         at
> org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > >         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > >         at
> org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > >         at
> org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > >         at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > >         at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > >         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > >         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > >         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > stRunner.java:209)
> > > >
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 13:48
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > Can you try calling message.getBodyBuffer().resetReaderIndex();
> before the send?
> > > >
> > > > if that does not work I will try your code and see what happens.
> > > > (Let me know if doesn't please)
> > > >
> > > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com>
> wrote:
> > > > >
> > > > > maybe take inspiration from
> > > > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > > rati
> > > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > > on/c lient/MessageBufferTest.java that passes a string, but there
> > > > > are corresponding byte[] or buffer variants in the api. If you
> > > > > want to skip the decoding, to access the raw buffer, you need to
> > > > > parse the type to get to the appropriate part of the buffer.
> > > > > There are loads of usage examples in the tests and they all work,
> > > > > start there and break it as you go.
> > > > >
> > > > > the issue is the wire level encoding that the client does, the JMS
> > > > > api hides this, as do the typed accessors, but you can get direct
> > > > > access to the encoded buffers via the core api as you are doing
> > > > > but you need to be type aware, for example a string can be utf-8
> > > > > encoded or it can be raw bytes on the wire, depending on the size
> > > > > and chars, the encoding handles and hides this detail. But if you
> > > > > go for direct access, you need to be aware of the encoding.
> > > > >
> > > > >
> > > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > > >
> > > > > > getDataBuffer gives same result! Already tried!
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > Why you don't use the JMS API for this?
> > > > > >
> > > > > > or if you really want to use the core API, use the
> getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > > >
> > > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <
> jbertram@apache.org> wrote:
> > > > > > >
> > > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > > method on line
> > > > > > > 93 of MailServerActiveMQClient.java, but I don't see that call
> > > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > > seem correct. Can you clarify this?
> > > > > > >
> > > > > > >
> > > > > > > Justin
> > > > > > >
> > > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > > <er...@cgi.com>
> > > > > > > wrote:
> > > > > > >
> > > > > > > > Fyi:
> > > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii
> > > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > > e.
> > > > > > > >
> > > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > > Aan: users@activemq.apache.org
> > > > > > > > Onderwerp: AW: send message
> > > > > > > >
> > > > > > > >
> > > > > > > > EXTERNAL SENDER:   Do not click any links or open any
> attachments unless
> > > > > > > > you trust the sender and know the content is safe.
> > > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez
> aucune pièce
> > > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable,
> > > > > > > > ou que vous ayez l'assurance que le contenu provient d'une
> source sûre.
> > > > > > > >
> > > > > > > > While sending / receiving a text message I get this
> > > > > > > >
> > > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > > simpleString,
> > > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > > >         at
> > > > > > > >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > > >         at
> > > > > > > >
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > > >         at
> > > > > > > >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > > >         at
> > > > > > > >
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > >
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > >
> .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > > >         at
> > > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > > ke0(
> > > > > > > > Nati
> > > > > > > > ve
> > > > > > > > Method)
> > > > > > > >         at
> > > > > > > >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > > >         at
> > > > > > > >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > > >         at
> java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > > >         at
> > > > > > > >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > > >         at
> > > > > > > >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > > >         at
> > > > > > > >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > > >         at
> > > > > > > >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > > >         at
> org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > > >         at
> > > > > > > >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > > >         at
> > > > > > > >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > > >         at
> org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > > >         at
> org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > > >         at
> > > > > > > >
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > > >         at
> org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > > >         at
> org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > > >         at
> org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > > >         at
> > > > > > > >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > > >         at
> > > > > > > >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > > >         at
> > > > > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > > >         at
> > > > > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > > >         at
> > > > > > > >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > > >         at
> > > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > > Remo
> > > > > > > > teTe
> > > > > > > > stRunner.java:209)
> > > > > > > >
> > > > > > > >
> > > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > > An: users@activemq.apache.org
> > > > > > > > Betreff: Re: send message
> > > > > > > >
> > > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > > >
> > > > > > > >
> > > > > > > > Justin
> > > > > > > >
> > > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com>
> wrote:
> > > > > > > >
> > > > > > > > > I try to send and receive a netty ByteBuf message, but it
> fails.
> > > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > > mistake in sending or receiving!
> > > > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > > > convert the buffer to a byte array!
> > > > > > > > >
> > > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > > throws ActiveMQException {
> > > > > > > > >              ClientSession session =
> this.sessionFactory.createSession();
> > > > > > > > >              try {
> > > > > > > > >                     session.start();
> > > > > > > > >                     ClientMessage message =
> session.createMessage(true);
> > > > > > > > >
> > > > > > > > > message.getBodyBuffer().writeBytes(buf, 0,
> buf.readableBytes());
> > > > > > > > >                     ClientProducer producer =
> > > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > >                     producer.send(message);
> > > > > > > > >              } finally {
> > > > > > > > >                     session.close();
> > > > > > > > >              }
> > > > > > > > >        }
> > > > > > > > >
> > > > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > > > throws ActiveMQException {
> > > > > > > > >              ActiveMQBuffer result;
> > > > > > > > >              ClientSession session =
> this.sessionFactory.createSession();
> > > > > > > > >              try {
> > > > > > > > >                     session.start();
> > > > > > > > >                     ClientConsumer consumer =
> > > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > > >                     ClientMessage message =
> consumer.receive();
> > > > > > > > >                     result =
> > > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > > >
>  message.getBodyBuffer().readBytes(result);
> > > > > > > > >              } finally {
> > > > > > > > >                     session.close();
> > > > > > > > >              }
> > > > > > > > >
> > > > > > > > >              return result;
> > > > > > > > >        }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >        public void startServer() throws Exception {
> > > > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > > > >
> > > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > > >
> this.configuration.setPersistenceEnabled(true);
> > > > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > > >
> > > > > > > > >              this.server = new
> ActiveMQServerImpl(this.configuration);
> > > > > > > > >              this.server.start();
> > > > > > > > >        }
> > > > > > > > >
> > > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Clebert Suconic
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic
>

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
Not on the API itself.

Try the core api example I sent you... and let me know what is
different from yours.

On Tue, Mar 23, 2021 at 10:34 AM <To...@t-systems.com> wrote:
>
> I want to use the jms layer, but I've a netty application and I want to write the ByteBuf mostly efficent to the queue.
> I think it makes no sense to convert it back from a native buffer into a byte array or stream and tunnel this throught the jvm!
>
> Is there a way to use a ByteBuf with jms?
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Dienstag, 23. März 2021 15:00
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> You were supposed to call reset right before sending though... but I did not need it on my test.. I will post a link...
>
> Anyway, if you use the JMS API, the JMS layer is very thin, and I don't think it would affect your performance in any way. you could create a BytesMessage and all the detail would be hidden away from the internal API.
>
> On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <cl...@gmail.com> wrote:
> >
> > I'm adding a test doing exactly what you did, and it's working...
> >
> > give me 10 minutes and I will post a link here...
> >
> > On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> > >
> > > Same Issue!
> > >         public void sendMessageToSmtpQueue(String text) throws ActiveMQException {
> > >                 ClientSession session = this.sessionFactory.createSession();
> > >                 try {
> > >                         session.start();
> > >                         ClientMessage message = session.createMessage(true);
> > >                         message.setType(ClientMessage.TEXT_TYPE);
> > >                         message.getBodyBuffer().resetReaderIndex();
> > >                         message.getBodyBuffer().writeString(text);
> > >                         ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > >                         producer.send(message);
> > >                 } finally {
> > >                         session.close();
> > >                 }
> > >         }
> > >
> > > java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
> > >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> > >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> > >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > >         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > >         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > >         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > >         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > >         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > >         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > >         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > >         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > stRunner.java:209)
> > >
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Dienstag, 23. März 2021 13:48
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?
> > >
> > > if that does not work I will try your code and see what happens.
> > > (Let me know if doesn't please)
> > >
> > > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
> > > >
> > > > maybe take inspiration from
> > > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > > rati
> > > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > > on/c lient/MessageBufferTest.java that passes a string, but there
> > > > are corresponding byte[] or buffer variants in the api. If you
> > > > want to skip the decoding, to access the raw buffer, you need to
> > > > parse the type to get to the appropriate part of the buffer.
> > > > There are loads of usage examples in the tests and they all work,
> > > > start there and break it as you go.
> > > >
> > > > the issue is the wire level encoding that the client does, the JMS
> > > > api hides this, as do the typed accessors, but you can get direct
> > > > access to the encoded buffers via the core api as you are doing
> > > > but you need to be type aware, for example a string can be utf-8
> > > > encoded or it can be raw bytes on the wire, depending on the size
> > > > and chars, the encoding handles and hides this detail. But if you
> > > > go for direct access, you need to be aware of the encoding.
> > > >
> > > >
> > > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > > >
> > > > > getDataBuffer gives same result! Already tried!
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > Why you don't use the JMS API for this?
> > > > >
> > > > > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > > >
> > > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > > > > >
> > > > > > The stack-trace indicates you're invoking the "readString"
> > > > > > method on line
> > > > > > 93 of MailServerActiveMQClient.java, but I don't see that call
> > > > > > in the code you pasted. Therefore, that stack-trace doesn't
> > > > > > seem correct. Can you clarify this?
> > > > > >
> > > > > >
> > > > > > Justin
> > > > > >
> > > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > > <er...@cgi.com>
> > > > > > wrote:
> > > > > >
> > > > > > > Fyi:
> > > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii
> > > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > > e.
> > > > > > >
> > > > > > > -----Oorspronkelijk bericht-----
> > > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > > Aan: users@activemq.apache.org
> > > > > > > Onderwerp: AW: send message
> > > > > > >
> > > > > > >
> > > > > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > > > > you trust the sender and know the content is safe.
> > > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable,
> > > > > > > ou que vous ayez l'assurance que le contenu provient d'une source sûre.
> > > > > > >
> > > > > > > While sending / receiving a text message I get this
> > > > > > >
> > > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > > simpleString,
> > > > > > > length=1953068645 is greater than readableBytes=3
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > > >         at
> > > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > > ke0(
> > > > > > > Nati
> > > > > > > ve
> > > > > > > Method)
> > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > > >         at
> > > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > > >         at
> > > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > > >         at
> > > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > > >         at
> > > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > > >         at
> > > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > > >         at
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > > >         at
> > > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > > >         at
> > > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > > >         at
> > > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > > Remo
> > > > > > > teTe
> > > > > > > stRunner.java:209)
> > > > > > >
> > > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > > An: users@activemq.apache.org
> > > > > > > Betreff: Re: send message
> > > > > > >
> > > > > > > What actually fails? Do you have a stack-trace?
> > > > > > >
> > > > > > >
> > > > > > > Justin
> > > > > > >
> > > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > > > > >
> > > > > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > > > > What I'm doing wrong here? I even don't know ist he
> > > > > > > > mistake in sending or receiving!
> > > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > > convert the buffer to a byte array!
> > > > > > > >
> > > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf)
> > > > > > > > throws ActiveMQException {
> > > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > > >              try {
> > > > > > > >                     session.start();
> > > > > > > >                     ClientMessage message = session.createMessage(true);
> > > > > > > >
> > > > > > > > message.getBodyBuffer().writeBytes(buf, 0, buf.readableBytes());
> > > > > > > >                     ClientProducer producer =
> > > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > >                     producer.send(message);
> > > > > > > >              } finally {
> > > > > > > >                     session.close();
> > > > > > > >              }
> > > > > > > >        }
> > > > > > > >
> > > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > > throws ActiveMQException {
> > > > > > > >              ActiveMQBuffer result;
> > > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > > >              try {
> > > > > > > >                     session.start();
> > > > > > > >                     ClientConsumer consumer =
> > > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > > >                     ClientMessage message = consumer.receive();
> > > > > > > >                     result =
> > > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > > >                     message.getBodyBuffer().readBytes(result);
> > > > > > > >              } finally {
> > > > > > > >                     session.close();
> > > > > > > >              }
> > > > > > > >
> > > > > > > >              return result;
> > > > > > > >        }
> > > > > > > >
> > > > > > > >
> > > > > > > >        public void startServer() throws Exception {
> > > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > > >
> > > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > > >              this.configuration.setPersistenceEnabled(true);
> > > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > > >
> > > > > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > > > > >              this.server.start();
> > > > > > > >        }
> > > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Clebert Suconic
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
I want to use the jms layer, but I've a netty application and I want to write the ByteBuf mostly efficent to the queue.
I think it makes no sense to convert it back from a native buffer into a byte array or stream and tunnel this throught the jvm!

Is there a way to use a ByteBuf with jms?

-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Dienstag, 23. März 2021 15:00
An: users@activemq.apache.org
Betreff: Re: send message

You were supposed to call reset right before sending though... but I did not need it on my test.. I will post a link...

Anyway, if you use the JMS API, the JMS layer is very thin, and I don't think it would affect your performance in any way. you could create a BytesMessage and all the detail would be hidden away from the internal API.

On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic <cl...@gmail.com> wrote:
>
> I'm adding a test doing exactly what you did, and it's working...
>
> give me 10 minutes and I will post a link here...
>
> On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> >
> > Same Issue!
> >         public void sendMessageToSmtpQueue(String text) throws ActiveMQException {
> >                 ClientSession session = this.sessionFactory.createSession();
> >                 try {
> >                         session.start();
> >                         ClientMessage message = session.createMessage(true);
> >                         message.setType(ClientMessage.TEXT_TYPE);
> >                         message.getBodyBuffer().resetReaderIndex();
> >                         message.getBodyBuffer().writeString(text);
> >                         ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> >                         producer.send(message);
> >                 } finally {
> >                         session.close();
> >                 }
> >         }
> >
> > java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
> >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> >         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> >         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> >         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> >         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> >         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> >         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> >         at 
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > stRunner.java:209)
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Dienstag, 23. März 2021 13:48
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?
> >
> > if that does not work I will try your code and see what happens. 
> > (Let me know if doesn't please)
> >
> > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
> > >
> > > maybe take inspiration from
> > > https://github.com/apache/activemq-artemis/blob/master/tests/integ
> > > rati 
> > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integrati
> > > on/c lient/MessageBufferTest.java that passes a string, but there 
> > > are corresponding byte[] or buffer variants in the api. If you 
> > > want to skip the decoding, to access the raw buffer, you need to 
> > > parse the type to get to the appropriate part of the buffer.
> > > There are loads of usage examples in the tests and they all work, 
> > > start there and break it as you go.
> > >
> > > the issue is the wire level encoding that the client does, the JMS 
> > > api hides this, as do the typed accessors, but you can get direct 
> > > access to the encoded buffers via the core api as you are doing 
> > > but you need to be type aware, for example a string can be utf-8 
> > > encoded or it can be raw bytes on the wire, depending on the size 
> > > and chars, the encoding handles and hides this detail. But if you 
> > > go for direct access, you need to be aware of the encoding.
> > >
> > >
> > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > >
> > > > getDataBuffer gives same result! Already tried!
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > Why you don't use the JMS API for this?
> > > >
> > > > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > >
> > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > > > >
> > > > > The stack-trace indicates you're invoking the "readString" 
> > > > > method on line
> > > > > 93 of MailServerActiveMQClient.java, but I don't see that call 
> > > > > in the code you pasted. Therefore, that stack-trace doesn't 
> > > > > seem correct. Can you clarify this?
> > > > >
> > > > >
> > > > > Justin
> > > > >
> > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> > > > > <er...@cgi.com>
> > > > > wrote:
> > > > >
> > > > > > Fyi:
> > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii 
> > > > > > text) And "tive" is likely part of the string "ActiveMQ"?
> > > > > > e.
> > > > > >
> > > > > > -----Oorspronkelijk bericht-----
> > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > Aan: users@activemq.apache.org
> > > > > > Onderwerp: AW: send message
> > > > > >
> > > > > >
> > > > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > > > you trust the sender and know the content is safe.
> > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, 
> > > > > > ou que vous ayez l'assurance que le contenu provient d'une source sûre.
> > > > > >
> > > > > > While sending / receiving a text message I get this
> > > > > >
> > > > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > > > simpleString,
> > > > > > length=1953068645 is greater than readableBytes=3
> > > > > >         at
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > >         at
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > >         at
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > >         at
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > >         at
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> > > > > > ke0(
> > > > > > Nati
> > > > > > ve
> > > > > > Method)
> > > > > >         at
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > >         at
> > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > >         at
> > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > >         at
> > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > >         at
> > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > >         at
> > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > >         at
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > >         at
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > >         at
> > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> > > > > > Remo
> > > > > > teTe
> > > > > > stRunner.java:209)
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > What actually fails? Do you have a stack-trace?
> > > > > >
> > > > > >
> > > > > > Justin
> > > > > >
> > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > > > What I'm doing wrong here? I even don't know ist he 
> > > > > > > mistake in sending or receiving!
> > > > > > > I was thinking to use the jms layer, but I'm receiving the 
> > > > > > > data buffer throught a netty buffer and I want to avoid to 
> > > > > > > convert the buffer to a byte array!
> > > > > > >
> > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf) 
> > > > > > > throws ActiveMQException {
> > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > >              try {
> > > > > > >                     session.start();
> > > > > > >                     ClientMessage message = session.createMessage(true);
> > > > > > >                     
> > > > > > > message.getBodyBuffer().writeBytes(buf, 0, buf.readableBytes());
> > > > > > >                     ClientProducer producer = 
> > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                     producer.send(message);
> > > > > > >              } finally {
> > > > > > >                     session.close();
> > > > > > >              }
> > > > > > >        }
> > > > > > >
> > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() 
> > > > > > > throws ActiveMQException {
> > > > > > >              ActiveMQBuffer result;
> > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > >              try {
> > > > > > >                     session.start();
> > > > > > >                     ClientConsumer consumer = 
> > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                     ClientMessage message = consumer.receive();
> > > > > > >                     result = 
> > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > >                     message.getBodyBuffer().readBytes(result);
> > > > > > >              } finally {
> > > > > > >                     session.close();
> > > > > > >              }
> > > > > > >
> > > > > > >              return result;
> > > > > > >        }
> > > > > > >
> > > > > > >
> > > > > > >        public void startServer() throws Exception {
> > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > >
> > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > >              this.configuration.setPersistenceEnabled(true);
> > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > >
> > > > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > > > >              this.server.start();
> > > > > > >        }
> > > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
You were supposed to call reset right before sending though... but I
did not need it on my test.. I will post a link...

Anyway, if you use the JMS API, the JMS layer is very thin, and I
don't think it would affect your performance in any way. you could
create a BytesMessage and all the detail would be hidden away from the
internal API.

On Tue, Mar 23, 2021 at 9:57 AM Clebert Suconic
<cl...@gmail.com> wrote:
>
> I'm adding a test doing exactly what you did, and it's working...
>
> give me 10 minutes and I will post a link here...
>
> On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
> >
> > Same Issue!
> >         public void sendMessageToSmtpQueue(String text) throws ActiveMQException {
> >                 ClientSession session = this.sessionFactory.createSession();
> >                 try {
> >                         session.start();
> >                         ClientMessage message = session.createMessage(true);
> >                         message.setType(ClientMessage.TEXT_TYPE);
> >                         message.getBodyBuffer().resetReaderIndex();
> >                         message.getBodyBuffer().writeString(text);
> >                         ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> >                         producer.send(message);
> >                 } finally {
> >                         session.close();
> >                 }
> >         }
> >
> > java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
> >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> >         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> >         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
> >         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
> >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> >         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> >         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> >         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> >         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> >         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> >         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> >         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> >         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Dienstag, 23. März 2021 13:48
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?
> >
> > if that does not work I will try your code and see what happens. (Let me know if doesn't please)
> >
> > On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
> > >
> > > maybe take inspiration from
> > > https://github.com/apache/activemq-artemis/blob/master/tests/integrati
> > > on-tests/src/test/java/org/apache/activemq/artemis/tests/integration/c
> > > lient/MessageBufferTest.java that passes a string, but there are
> > > corresponding byte[] or buffer variants in the api. If you want to
> > > skip the decoding, to access the raw buffer, you need to parse the
> > > type to get to the appropriate part of the buffer.
> > > There are loads of usage examples in the tests and they all work,
> > > start there and break it as you go.
> > >
> > > the issue is the wire level encoding that the client does, the JMS api
> > > hides this, as do the typed accessors, but you can get direct access
> > > to the encoded buffers via the core api as you are doing but you need
> > > to be type aware, for example a string can be utf-8 encoded or it can
> > > be raw bytes on the wire, depending on the size and chars, the
> > > encoding handles and hides this detail. But if you go for direct
> > > access, you need to be aware of the encoding.
> > >
> > >
> > > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > > >
> > > > getDataBuffer gives same result! Already tried!
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Clebert Suconic <cl...@gmail.com>
> > > > Gesendet: Dienstag, 23. März 2021 03:19
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > Why you don't use the JMS API for this?
> > > >
> > > > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > > >
> > > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > > > >
> > > > > The stack-trace indicates you're invoking the "readString" method
> > > > > on line
> > > > > 93 of MailServerActiveMQClient.java, but I don't see that call in
> > > > > the code you pasted. Therefore, that stack-trace doesn't seem
> > > > > correct. Can you clarify this?
> > > > >
> > > > >
> > > > > Justin
> > > > >
> > > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > > <er...@cgi.com>
> > > > > wrote:
> > > > >
> > > > > > Fyi:
> > > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text)
> > > > > > And "tive" is likely part of the string "ActiveMQ"?
> > > > > > e.
> > > > > >
> > > > > > -----Oorspronkelijk bericht-----
> > > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > > Aan: users@activemq.apache.org
> > > > > > Onderwerp: AW: send message
> > > > > >
> > > > > >
> > > > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > > > you trust the sender and know the content is safe.
> > > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou
> > > > > > que vous ayez l'assurance que le contenu provient d'une source sûre.
> > > > > >
> > > > > > While sending / receiving a text message I get this
> > > > > >
> > > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > > simpleString,
> > > > > > length=1953068645 is greater than readableBytes=3
> > > > > >         at
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > > >         at
> > > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > > >         at
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > > >         at
> > > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > > >         at
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(
> > > > > > Nati
> > > > > > ve
> > > > > > Method)
> > > > > >         at
> > > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > > >         at
> > > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > > >         at
> > > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > > >         at
> > > > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > > >         at
> > > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > > >         at
> > > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > > >         at
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > > >         at
> > > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > > >         at
> > > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > > >         at
> > > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > > > teTe
> > > > > > stRunner.java:209)
> > > > > >
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > > An: users@activemq.apache.org
> > > > > > Betreff: Re: send message
> > > > > >
> > > > > > What actually fails? Do you have a stack-trace?
> > > > > >
> > > > > >
> > > > > > Justin
> > > > > >
> > > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > > > >
> > > > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > > > What I'm doing wrong here? I even don't know ist he mistake in
> > > > > > > sending or receiving!
> > > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > > convert the buffer to a byte array!
> > > > > > >
> > > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > > > > > > ActiveMQException {
> > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > >              try {
> > > > > > >                     session.start();
> > > > > > >                     ClientMessage message = session.createMessage(true);
> > > > > > >                     message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > > buf.readableBytes());
> > > > > > >                     ClientProducer producer =
> > > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                     producer.send(message);
> > > > > > >              } finally {
> > > > > > >                     session.close();
> > > > > > >              }
> > > > > > >        }
> > > > > > >
> > > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > > throws ActiveMQException {
> > > > > > >              ActiveMQBuffer result;
> > > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > > >              try {
> > > > > > >                     session.start();
> > > > > > >                     ClientConsumer consumer =
> > > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > > >                     ClientMessage message = consumer.receive();
> > > > > > >                     result =
> > > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > > >                     message.getBodyBuffer().readBytes(result);
> > > > > > >              } finally {
> > > > > > >                     session.close();
> > > > > > >              }
> > > > > > >
> > > > > > >              return result;
> > > > > > >        }
> > > > > > >
> > > > > > >
> > > > > > >        public void startServer() throws Exception {
> > > > > > >              this.configuration = new ConfigurationImpl();
> > > > > > >
> > > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > > >              this.configuration.setPersistenceEnabled(true);
> > > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > > >
> > > > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > > > >              this.server.start();
> > > > > > >        }
> > > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Clebert Suconic
> >
> >
> >
> > --
> > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
I'm adding a test doing exactly what you did, and it's working...

give me 10 minutes and I will post a link here...

On Tue, Mar 23, 2021 at 9:56 AM <To...@t-systems.com> wrote:
>
> Same Issue!
>         public void sendMessageToSmtpQueue(String text) throws ActiveMQException {
>                 ClientSession session = this.sessionFactory.createSession();
>                 try {
>                         session.start();
>                         ClientMessage message = session.createMessage(true);
>                         message.setType(ClientMessage.TEXT_TYPE);
>                         message.getBodyBuffer().resetReaderIndex();
>                         message.getBodyBuffer().writeString(text);
>                         ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
>                         producer.send(message);
>                 } finally {
>                         session.close();
>                 }
>         }
>
> java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
>         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
>         at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
>         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
>         at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
>         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
>         at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
>         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
>         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
>
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Dienstag, 23. März 2021 13:48
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?
>
> if that does not work I will try your code and see what happens. (Let me know if doesn't please)
>
> On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
> >
> > maybe take inspiration from
> > https://github.com/apache/activemq-artemis/blob/master/tests/integrati
> > on-tests/src/test/java/org/apache/activemq/artemis/tests/integration/c
> > lient/MessageBufferTest.java that passes a string, but there are
> > corresponding byte[] or buffer variants in the api. If you want to
> > skip the decoding, to access the raw buffer, you need to parse the
> > type to get to the appropriate part of the buffer.
> > There are loads of usage examples in the tests and they all work,
> > start there and break it as you go.
> >
> > the issue is the wire level encoding that the client does, the JMS api
> > hides this, as do the typed accessors, but you can get direct access
> > to the encoded buffers via the core api as you are doing but you need
> > to be type aware, for example a string can be utf-8 encoded or it can
> > be raw bytes on the wire, depending on the size and chars, the
> > encoding handles and hides this detail. But if you go for direct
> > access, you need to be aware of the encoding.
> >
> >
> > On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> > >
> > > getDataBuffer gives same result! Already tried!
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clebert Suconic <cl...@gmail.com>
> > > Gesendet: Dienstag, 23. März 2021 03:19
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > Why you don't use the JMS API for this?
> > >
> > > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> > >
> > > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > > >
> > > > The stack-trace indicates you're invoking the "readString" method
> > > > on line
> > > > 93 of MailServerActiveMQClient.java, but I don't see that call in
> > > > the code you pasted. Therefore, that stack-trace doesn't seem
> > > > correct. Can you clarify this?
> > > >
> > > >
> > > > Justin
> > > >
> > > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > > <er...@cgi.com>
> > > > wrote:
> > > >
> > > > > Fyi:
> > > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text)
> > > > > And "tive" is likely part of the string "ActiveMQ"?
> > > > > e.
> > > > >
> > > > > -----Oorspronkelijk bericht-----
> > > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > > Verzonden: maandag 22 maart 2021 16:41
> > > > > Aan: users@activemq.apache.org
> > > > > Onderwerp: AW: send message
> > > > >
> > > > >
> > > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > > you trust the sender and know the content is safe.
> > > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou
> > > > > que vous ayez l'assurance que le contenu provient d'une source sûre.
> > > > >
> > > > > While sending / receiving a text message I get this
> > > > >
> > > > > java.lang.IndexOutOfBoundsException: Error reading in
> > > > > simpleString,
> > > > > length=1953068645 is greater than readableBytes=3
> > > > >         at
> > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > > >         at
> > > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > > >         at
> > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > > >         at
> > > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > > >         at
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(
> > > > > Nati
> > > > > ve
> > > > > Method)
> > > > >         at
> > > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > > >         at
> > > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > > >         at
> > > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > > >         at
> > > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > > >         at
> > > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > > >         at
> > > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > > >         at
> > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > > >         at
> > > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > > >         at
> > > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > > >         at
> > > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > > teTe
> > > > > stRunner.java:209)
> > > > >
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Justin Bertram <jb...@apache.org>
> > > > > Gesendet: Montag, 22. März 2021 16:34
> > > > > An: users@activemq.apache.org
> > > > > Betreff: Re: send message
> > > > >
> > > > > What actually fails? Do you have a stack-trace?
> > > > >
> > > > >
> > > > > Justin
> > > > >
> > > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > > >
> > > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > > What I'm doing wrong here? I even don't know ist he mistake in
> > > > > > sending or receiving!
> > > > > > I was thinking to use the jms layer, but I'm receiving the
> > > > > > data buffer throught a netty buffer and I want to avoid to
> > > > > > convert the buffer to a byte array!
> > > > > >
> > > > > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > > > > > ActiveMQException {
> > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > >              try {
> > > > > >                     session.start();
> > > > > >                     ClientMessage message = session.createMessage(true);
> > > > > >                     message.getBodyBuffer().writeBytes(buf, 0,
> > > > > > buf.readableBytes());
> > > > > >                     ClientProducer producer =
> > > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > >                     producer.send(message);
> > > > > >              } finally {
> > > > > >                     session.close();
> > > > > >              }
> > > > > >        }
> > > > > >
> > > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue()
> > > > > > throws ActiveMQException {
> > > > > >              ActiveMQBuffer result;
> > > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > > >              try {
> > > > > >                     session.start();
> > > > > >                     ClientConsumer consumer =
> > > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > > >                     ClientMessage message = consumer.receive();
> > > > > >                     result =
> > > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > > >                     message.getBodyBuffer().readBytes(result);
> > > > > >              } finally {
> > > > > >                     session.close();
> > > > > >              }
> > > > > >
> > > > > >              return result;
> > > > > >        }
> > > > > >
> > > > > >
> > > > > >        public void startServer() throws Exception {
> > > > > >              this.configuration = new ConfigurationImpl();
> > > > > >
> > > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > > >              this.configuration.setPersistenceEnabled(true);
> > > > > >              this.configuration.setSecurityEnabled(false);
> > > > > >              this.configuration.addQueueConfiguration(new
> > > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > > >
> > > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > > >              this.server.start();
> > > > > >        }
> > > > > >
> > > > >
> > >
> > >
> > >
> > > --
> > > Clebert Suconic
>
>
>
> --
> Clebert Suconic



-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
Same Issue!
	public void sendMessageToSmtpQueue(String text) throws ActiveMQException {
		ClientSession session = this.sessionFactory.createSession();
		try {
			session.start();
			ClientMessage message = session.createMessage(true);
			message.setType(ClientMessage.TEXT_TYPE);
			message.getBodyBuffer().resetReaderIndex();
			message.getBodyBuffer().writeString(text);
			ClientProducer producer = session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
			producer.send(message);
		} finally {
			session.close();
		}
	}

java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
	at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
	at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
	at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
	at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
	at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:94)
	at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceiveTextMessage(MailServerActiveMQClientTest.java:37)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)


-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Dienstag, 23. März 2021 13:48
An: users@activemq.apache.org
Betreff: Re: send message

Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?

if that does not work I will try your code and see what happens. (Let me know if doesn't please)

On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
>
> maybe take inspiration from
> https://github.com/apache/activemq-artemis/blob/master/tests/integrati
> on-tests/src/test/java/org/apache/activemq/artemis/tests/integration/c
> lient/MessageBufferTest.java that passes a string, but there are 
> corresponding byte[] or buffer variants in the api. If you want to 
> skip the decoding, to access the raw buffer, you need to parse the 
> type to get to the appropriate part of the buffer.
> There are loads of usage examples in the tests and they all work, 
> start there and break it as you go.
>
> the issue is the wire level encoding that the client does, the JMS api 
> hides this, as do the typed accessors, but you can get direct access 
> to the encoded buffers via the core api as you are doing but you need 
> to be type aware, for example a string can be utf-8 encoded or it can 
> be raw bytes on the wire, depending on the size and chars, the 
> encoding handles and hides this detail. But if you go for direct 
> access, you need to be aware of the encoding.
>
>
> On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> >
> > getDataBuffer gives same result! Already tried!
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Dienstag, 23. März 2021 03:19
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Why you don't use the JMS API for this?
> >
> > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> >
> > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > >
> > > The stack-trace indicates you're invoking the "readString" method 
> > > on line
> > > 93 of MailServerActiveMQClient.java, but I don't see that call in 
> > > the code you pasted. Therefore, that stack-trace doesn't seem 
> > > correct. Can you clarify this?
> > >
> > >
> > > Justin
> > >
> > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> > > <er...@cgi.com>
> > > wrote:
> > >
> > > > Fyi:
> > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text) 
> > > > And "tive" is likely part of the string "ActiveMQ"?
> > > > e.
> > > >
> > > > -----Oorspronkelijk bericht-----
> > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > Verzonden: maandag 22 maart 2021 16:41
> > > > Aan: users@activemq.apache.org
> > > > Onderwerp: AW: send message
> > > >
> > > >
> > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > you trust the sender and know the content is safe.
> > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou 
> > > > que vous ayez l'assurance que le contenu provient d'une source sûre.
> > > >
> > > > While sending / receiving a text message I get this
> > > >
> > > > java.lang.IndexOutOfBoundsException: Error reading in 
> > > > simpleString,
> > > > length=1953068645 is greater than readableBytes=3
> > > >         at
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > >         at
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > >         at
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > >         at
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(
> > > > Nati
> > > > ve
> > > > Method)
> > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > >         at
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > >         at
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > >         at
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > >         at
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > >         at
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > >         at
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > >         at
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > >         at
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > >         at
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Remo
> > > > teTe
> > > > stRunner.java:209)
> > > >
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Justin Bertram <jb...@apache.org>
> > > > Gesendet: Montag, 22. März 2021 16:34
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > What actually fails? Do you have a stack-trace?
> > > >
> > > >
> > > > Justin
> > > >
> > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > >
> > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > What I'm doing wrong here? I even don't know ist he mistake in 
> > > > > sending or receiving!
> > > > > I was thinking to use the jms layer, but I'm receiving the 
> > > > > data buffer throught a netty buffer and I want to avoid to 
> > > > > convert the buffer to a byte array!
> > > > >
> > > > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> > > > > ActiveMQException {
> > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > >              try {
> > > > >                     session.start();
> > > > >                     ClientMessage message = session.createMessage(true);
> > > > >                     message.getBodyBuffer().writeBytes(buf, 0, 
> > > > > buf.readableBytes());
> > > > >                     ClientProducer producer = 
> > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                     producer.send(message);
> > > > >              } finally {
> > > > >                     session.close();
> > > > >              }
> > > > >        }
> > > > >
> > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() 
> > > > > throws ActiveMQException {
> > > > >              ActiveMQBuffer result;
> > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > >              try {
> > > > >                     session.start();
> > > > >                     ClientConsumer consumer = 
> > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                     ClientMessage message = consumer.receive();
> > > > >                     result =
> > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > >                     message.getBodyBuffer().readBytes(result);
> > > > >              } finally {
> > > > >                     session.close();
> > > > >              }
> > > > >
> > > > >              return result;
> > > > >        }
> > > > >
> > > > >
> > > > >        public void startServer() throws Exception {
> > > > >              this.configuration = new ConfigurationImpl();
> > > > >              
> > > > > this.configuration.addAcceptorConfiguration("in-vm",
> > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > >              this.configuration.setPersistenceEnabled(true);
> > > > >              this.configuration.setSecurityEnabled(false);
> > > > >              this.configuration.addQueueConfiguration(new
> > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > >
> > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > >              this.server.start();
> > > > >        }
> > > > >
> > > >
> >
> >
> >
> > --
> > Clebert Suconic



--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
Can you try calling message.getBodyBuffer().resetReaderIndex(); before the send?

if that does not work I will try your code and see what happens. (Let
me know if doesn't please)

On Tue, Mar 23, 2021 at 7:55 AM Gary Tully <ga...@gmail.com> wrote:
>
> maybe take inspiration from
> https://github.com/apache/activemq-artemis/blob/master/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/MessageBufferTest.java
> that passes a string, but there are corresponding byte[] or buffer
> variants in the api. If you want to skip the decoding, to access the
> raw buffer, you need to parse the type to get to the appropriate part
> of the buffer.
> There are loads of usage examples in the tests and they all work,
> start there and break it as you go.
>
> the issue is the wire level encoding that the client does, the JMS api
> hides this, as do the typed accessors, but you can get direct access
> to the encoded buffers via the core api as you are doing but you need
> to be type aware,
> for example a string can be utf-8 encoded or it can be raw bytes on
> the wire, depending on the size and chars, the encoding handles and
> hides this detail. But if you go for direct access, you need to be
> aware of the encoding.
>
>
> On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
> >
> > getDataBuffer gives same result! Already tried!
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Clebert Suconic <cl...@gmail.com>
> > Gesendet: Dienstag, 23. März 2021 03:19
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > Why you don't use the JMS API for this?
> >
> > or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
> >
> > On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> > >
> > > The stack-trace indicates you're invoking the "readString" method on
> > > line
> > > 93 of MailServerActiveMQClient.java, but I don't see that call in the
> > > code you pasted. Therefore, that stack-trace doesn't seem correct. Can
> > > you clarify this?
> > >
> > >
> > > Justin
> > >
> > > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > > <er...@cgi.com>
> > > wrote:
> > >
> > > > Fyi:
> > > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text) And
> > > > "tive" is likely part of the string "ActiveMQ"?
> > > > e.
> > > >
> > > > -----Oorspronkelijk bericht-----
> > > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > > Verzonden: maandag 22 maart 2021 16:41
> > > > Aan: users@activemq.apache.org
> > > > Onderwerp: AW: send message
> > > >
> > > >
> > > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > > you trust the sender and know the content is safe.
> > > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que
> > > > vous ayez l'assurance que le contenu provient d'une source sûre.
> > > >
> > > > While sending / receiving a text message I get this
> > > >
> > > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > > > length=1953068645 is greater than readableBytes=3
> > > >         at
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > > >         at
> > > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > > >         at
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > > >         at
> > > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > > >         at com.tsystems.gematik.kim.mailserver.mq
> > > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Nati
> > > > ve
> > > > Method)
> > > >         at
> > > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > > >         at
> > > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > > >         at
> > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > > >         at
> > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > > >         at
> > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > > >         at
> > > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > > >         at
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > > >         at
> > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > > >         at
> > > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > > >         at
> > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > > >         at
> > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > > stRunner.java:209)
> > > >
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Justin Bertram <jb...@apache.org>
> > > > Gesendet: Montag, 22. März 2021 16:34
> > > > An: users@activemq.apache.org
> > > > Betreff: Re: send message
> > > >
> > > > What actually fails? Do you have a stack-trace?
> > > >
> > > >
> > > > Justin
> > > >
> > > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > > >
> > > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > > What I'm doing wrong here? I even don't know ist he mistake in
> > > > > sending or receiving!
> > > > > I was thinking to use the jms layer, but I'm receiving the data
> > > > > buffer throught a netty buffer and I want to avoid to convert the
> > > > > buffer to a byte array!
> > > > >
> > > > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > > > > ActiveMQException {
> > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > >              try {
> > > > >                     session.start();
> > > > >                     ClientMessage message = session.createMessage(true);
> > > > >                     message.getBodyBuffer().writeBytes(buf, 0,
> > > > > buf.readableBytes());
> > > > >                     ClientProducer producer =
> > > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                     producer.send(message);
> > > > >              } finally {
> > > > >                     session.close();
> > > > >              }
> > > > >        }
> > > > >
> > > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws
> > > > > ActiveMQException {
> > > > >              ActiveMQBuffer result;
> > > > >              ClientSession session = this.sessionFactory.createSession();
> > > > >              try {
> > > > >                     session.start();
> > > > >                     ClientConsumer consumer =
> > > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > > >                     ClientMessage message = consumer.receive();
> > > > >                     result =
> > > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > > >                     message.getBodyBuffer().readBytes(result);
> > > > >              } finally {
> > > > >                     session.close();
> > > > >              }
> > > > >
> > > > >              return result;
> > > > >        }
> > > > >
> > > > >
> > > > >        public void startServer() throws Exception {
> > > > >              this.configuration = new ConfigurationImpl();
> > > > >              this.configuration.addAcceptorConfiguration("in-vm",
> > > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > > >              this.configuration.setPersistenceEnabled(true);
> > > > >              this.configuration.setSecurityEnabled(false);
> > > > >              this.configuration.addQueueConfiguration(new
> > > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > > >
> > > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > > >              this.server.start();
> > > > >        }
> > > > >
> > > >
> >
> >
> >
> > --
> > Clebert Suconic



-- 
Clebert Suconic

Re: send message

Posted by Gary Tully <ga...@gmail.com>.
maybe take inspiration from
https://github.com/apache/activemq-artemis/blob/master/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/MessageBufferTest.java
that passes a string, but there are corresponding byte[] or buffer
variants in the api. If you want to skip the decoding, to access the
raw buffer, you need to parse the type to get to the appropriate part
of the buffer.
There are loads of usage examples in the tests and they all work,
start there and break it as you go.

the issue is the wire level encoding that the client does, the JMS api
hides this, as do the typed accessors, but you can get direct access
to the encoded buffers via the core api as you are doing but you need
to be type aware,
for example a string can be utf-8 encoded or it can be raw bytes on
the wire, depending on the size and chars, the encoding handles and
hides this detail. But if you go for direct access, you need to be
aware of the encoding.


On Tue, 23 Mar 2021 at 07:37, <To...@t-systems.com> wrote:
>
> getDataBuffer gives same result! Already tried!
>
> -----Ursprüngliche Nachricht-----
> Von: Clebert Suconic <cl...@gmail.com>
> Gesendet: Dienstag, 23. März 2021 03:19
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> Why you don't use the JMS API for this?
>
> or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.
>
> On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
> >
> > The stack-trace indicates you're invoking the "readString" method on
> > line
> > 93 of MailServerActiveMQClient.java, but I don't see that call in the
> > code you pasted. Therefore, that stack-trace doesn't seem correct. Can
> > you clarify this?
> >
> >
> > Justin
> >
> > On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin
> > <er...@cgi.com>
> > wrote:
> >
> > > Fyi:
> > > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text) And
> > > "tive" is likely part of the string "ActiveMQ"?
> > > e.
> > >
> > > -----Oorspronkelijk bericht-----
> > > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > > Verzonden: maandag 22 maart 2021 16:41
> > > Aan: users@activemq.apache.org
> > > Onderwerp: AW: send message
> > >
> > >
> > > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > > you trust the sender and know the content is safe.
> > > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que
> > > vous ayez l'assurance que le contenu provient d'une source sûre.
> > >
> > > While sending / receiving a text message I get this
> > >
> > > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > > length=1953068645 is greater than readableBytes=3
> > >         at
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> > >         at
> > > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> > >         at
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> > >         at
> > > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> > >         at com.tsystems.gematik.kim.mailserver.mq
> > > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> > >         at com.tsystems.gematik.kim.mailserver.mq
> > > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Nati
> > > ve
> > > Method)
> > >         at
> > > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> > >         at
> > > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> > >         at
> > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> > >         at
> > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> > >         at
> > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> > >         at
> > > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> > >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> > >         at
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> > >         at
> > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> > >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> > >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> > >         at
> > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> > >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> > >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> > >         at
> > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> > >         at
> > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> > >         at
> > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > > stRunner.java:209)
> > >
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Justin Bertram <jb...@apache.org>
> > > Gesendet: Montag, 22. März 2021 16:34
> > > An: users@activemq.apache.org
> > > Betreff: Re: send message
> > >
> > > What actually fails? Do you have a stack-trace?
> > >
> > >
> > > Justin
> > >
> > > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> > >
> > > > I try to send and receive a netty ByteBuf message, but it fails.
> > > > What I'm doing wrong here? I even don't know ist he mistake in
> > > > sending or receiving!
> > > > I was thinking to use the jms layer, but I'm receiving the data
> > > > buffer throught a netty buffer and I want to avoid to convert the
> > > > buffer to a byte array!
> > > >
> > > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > > > ActiveMQException {
> > > >              ClientSession session = this.sessionFactory.createSession();
> > > >              try {
> > > >                     session.start();
> > > >                     ClientMessage message = session.createMessage(true);
> > > >                     message.getBodyBuffer().writeBytes(buf, 0,
> > > > buf.readableBytes());
> > > >                     ClientProducer producer =
> > > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > > >                     producer.send(message);
> > > >              } finally {
> > > >                     session.close();
> > > >              }
> > > >        }
> > > >
> > > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws
> > > > ActiveMQException {
> > > >              ActiveMQBuffer result;
> > > >              ClientSession session = this.sessionFactory.createSession();
> > > >              try {
> > > >                     session.start();
> > > >                     ClientConsumer consumer =
> > > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > > >                     ClientMessage message = consumer.receive();
> > > >                     result =
> > > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > > >                     message.getBodyBuffer().readBytes(result);
> > > >              } finally {
> > > >                     session.close();
> > > >              }
> > > >
> > > >              return result;
> > > >        }
> > > >
> > > >
> > > >        public void startServer() throws Exception {
> > > >              this.configuration = new ConfigurationImpl();
> > > >              this.configuration.addAcceptorConfiguration("in-vm",
> > > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > > >              this.configuration.setPersistenceEnabled(true);
> > > >              this.configuration.setSecurityEnabled(false);
> > > >              this.configuration.addQueueConfiguration(new
> > > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > > >
> > > >              this.server = new ActiveMQServerImpl(this.configuration);
> > > >              this.server.start();
> > > >        }
> > > >
> > >
>
>
>
> --
> Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
getDataBuffer gives same result! Already tried!

-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Dienstag, 23. März 2021 03:19
An: users@activemq.apache.org
Betreff: Re: send message

Why you don't use the JMS API for this?

or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.

On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
>
> The stack-trace indicates you're invoking the "readString" method on 
> line
> 93 of MailServerActiveMQClient.java, but I don't see that call in the 
> code you pasted. Therefore, that stack-trace doesn't seem correct. Can 
> you clarify this?
>
>
> Justin
>
> On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> <er...@cgi.com>
> wrote:
>
> > Fyi:
> > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text) And 
> > "tive" is likely part of the string "ActiveMQ"?
> > e.
> >
> > -----Oorspronkelijk bericht-----
> > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > Verzonden: maandag 22 maart 2021 16:41
> > Aan: users@activemq.apache.org
> > Onderwerp: AW: send message
> >
> >
> > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > you trust the sender and know the content is safe.
> > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que 
> > vous ayez l'assurance que le contenu provient d'une source sûre.
> >
> > While sending / receiving a text message I get this
> >
> > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > length=1953068645 is greater than readableBytes=3
> >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Nati
> > ve
> > Method)
> >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >         at
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> >         at
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> >         at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >         at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> >         at
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> >         at
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> >         at
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > stRunner.java:209)
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Justin Bertram <jb...@apache.org>
> > Gesendet: Montag, 22. März 2021 16:34
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > What actually fails? Do you have a stack-trace?
> >
> >
> > Justin
> >
> > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> >
> > > I try to send and receive a netty ByteBuf message, but it fails.
> > > What I'm doing wrong here? I even don't know ist he mistake in 
> > > sending or receiving!
> > > I was thinking to use the jms layer, but I'm receiving the data 
> > > buffer throught a netty buffer and I want to avoid to convert the 
> > > buffer to a byte array!
> > >
> > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> > > ActiveMQException {
> > >              ClientSession session = this.sessionFactory.createSession();
> > >              try {
> > >                     session.start();
> > >                     ClientMessage message = session.createMessage(true);
> > >                     message.getBodyBuffer().writeBytes(buf, 0, 
> > > buf.readableBytes());
> > >                     ClientProducer producer = 
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > >                     producer.send(message);
> > >              } finally {
> > >                     session.close();
> > >              }
> > >        }
> > >
> > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
> > > ActiveMQException {
> > >              ActiveMQBuffer result;
> > >              ClientSession session = this.sessionFactory.createSession();
> > >              try {
> > >                     session.start();
> > >                     ClientConsumer consumer = 
> > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > >                     ClientMessage message = consumer.receive();
> > >                     result =
> > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > >                     message.getBodyBuffer().readBytes(result);
> > >              } finally {
> > >                     session.close();
> > >              }
> > >
> > >              return result;
> > >        }
> > >
> > >
> > >        public void startServer() throws Exception {
> > >              this.configuration = new ConfigurationImpl();
> > >              this.configuration.addAcceptorConfiguration("in-vm",
> > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > >              this.configuration.setPersistenceEnabled(true);
> > >              this.configuration.setSecurityEnabled(false);
> > >              this.configuration.addQueueConfiguration(new
> > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > >
> > >              this.server = new ActiveMQServerImpl(this.configuration);
> > >              this.server.start();
> > >        }
> > >
> >



--
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
I was thinking to use the JMS API, but I need to store a netty ByteBuf tot he queue and I thougth the core api is more effective, isn't it?!

-----Ursprüngliche Nachricht-----
Von: Clebert Suconic <cl...@gmail.com> 
Gesendet: Dienstag, 23. März 2021 03:19
An: users@activemq.apache.org
Betreff: Re: send message

Why you don't use the JMS API for this?

or if you really want to use the core API, use the getReadOnlyBuffer() or getDataBuffer() on the Message instead.

On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
>
> The stack-trace indicates you're invoking the "readString" method on 
> line
> 93 of MailServerActiveMQClient.java, but I don't see that call in the 
> code you pasted. Therefore, that stack-trace doesn't seem correct. Can 
> you clarify this?
>
>
> Justin
>
> On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin 
> <er...@cgi.com>
> wrote:
>
> > Fyi:
> > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text) And 
> > "tive" is likely part of the string "ActiveMQ"?
> > e.
> >
> > -----Oorspronkelijk bericht-----
> > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > Verzonden: maandag 22 maart 2021 16:41
> > Aan: users@activemq.apache.org
> > Onderwerp: AW: send message
> >
> >
> > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > you trust the sender and know the content is safe.
> > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que 
> > vous ayez l'assurance que le contenu provient d'une source sûre.
> >
> > While sending / receiving a text message I get this
> >
> > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > length=1953068645 is greater than readableBytes=3
> >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Nati
> > ve
> > Method)
> >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >         at
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> >         at
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> >         at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >         at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> >         at
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> >         at
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> >         at
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > stRunner.java:209)
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Justin Bertram <jb...@apache.org>
> > Gesendet: Montag, 22. März 2021 16:34
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > What actually fails? Do you have a stack-trace?
> >
> >
> > Justin
> >
> > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> >
> > > I try to send and receive a netty ByteBuf message, but it fails.
> > > What I'm doing wrong here? I even don't know ist he mistake in 
> > > sending or receiving!
> > > I was thinking to use the jms layer, but I'm receiving the data 
> > > buffer throught a netty buffer and I want to avoid to convert the 
> > > buffer to a byte array!
> > >
> > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> > > ActiveMQException {
> > >              ClientSession session = this.sessionFactory.createSession();
> > >              try {
> > >                     session.start();
> > >                     ClientMessage message = session.createMessage(true);
> > >                     message.getBodyBuffer().writeBytes(buf, 0, 
> > > buf.readableBytes());
> > >                     ClientProducer producer = 
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > >                     producer.send(message);
> > >              } finally {
> > >                     session.close();
> > >              }
> > >        }
> > >
> > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
> > > ActiveMQException {
> > >              ActiveMQBuffer result;
> > >              ClientSession session = this.sessionFactory.createSession();
> > >              try {
> > >                     session.start();
> > >                     ClientConsumer consumer = 
> > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > >                     ClientMessage message = consumer.receive();
> > >                     result =
> > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > >                     message.getBodyBuffer().readBytes(result);
> > >              } finally {
> > >                     session.close();
> > >              }
> > >
> > >              return result;
> > >        }
> > >
> > >
> > >        public void startServer() throws Exception {
> > >              this.configuration = new ConfigurationImpl();
> > >              this.configuration.addAcceptorConfiguration("in-vm",
> > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > >              this.configuration.setPersistenceEnabled(true);
> > >              this.configuration.setSecurityEnabled(false);
> > >              this.configuration.addQueueConfiguration(new
> > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > >
> > >              this.server = new ActiveMQServerImpl(this.configuration);
> > >              this.server.start();
> > >        }
> > >
> >



--
Clebert Suconic

Re: send message

Posted by Clebert Suconic <cl...@gmail.com>.
Why you don't use the JMS API for this?

or if you really want to use the core API, use the getReadOnlyBuffer()
or getDataBuffer() on the Message instead.

On Mon, Mar 22, 2021 at 12:01 PM Justin Bertram <jb...@apache.org> wrote:
>
> The stack-trace indicates you're invoking the "readString" method on line
> 93 of MailServerActiveMQClient.java, but I don't see that call in the code
> you pasted. Therefore, that stack-trace doesn't seem correct. Can you
> clarify this?
>
>
> Justin
>
> On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin <er...@cgi.com>
> wrote:
>
> > Fyi:
> > 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text)
> > And "tive" is likely part of the string "ActiveMQ"?
> > e.
> >
> > -----Oorspronkelijk bericht-----
> > Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> > Verzonden: maandag 22 maart 2021 16:41
> > Aan: users@activemq.apache.org
> > Onderwerp: AW: send message
> >
> >
> > EXTERNAL SENDER:   Do not click any links or open any attachments unless
> > you trust the sender and know the content is safe.
> > EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> > jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que vous
> > ayez l'assurance que le contenu provient d'une source sûre.
> >
> > While sending / receiving a text message I get this
> >
> > java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> > length=1953068645 is greater than readableBytes=3
> >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
> >         at
> > org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
> >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
> >         at
> > org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
> >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
> >         at com.tsystems.gematik.kim.mailserver.mq
> > .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
> >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >         at
> > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >         at
> > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> >         at
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> >         at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >         at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> >         at
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> >         at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> >         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> >         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> >         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> >         at
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
> >         at
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
> >         at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Justin Bertram <jb...@apache.org>
> > Gesendet: Montag, 22. März 2021 16:34
> > An: users@activemq.apache.org
> > Betreff: Re: send message
> >
> > What actually fails? Do you have a stack-trace?
> >
> >
> > Justin
> >
> > On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
> >
> > > I try to send and receive a netty ByteBuf message, but it fails.
> > > What I'm doing wrong here? I even don't know ist he mistake in sending
> > > or receiving!
> > > I was thinking to use the jms layer, but I'm receiving the data buffer
> > > throught a netty buffer and I want to avoid to convert the buffer to a
> > > byte array!
> > >
> > >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > > ActiveMQException {
> > >              ClientSession session = this.sessionFactory.createSession();
> > >              try {
> > >                     session.start();
> > >                     ClientMessage message = session.createMessage(true);
> > >                     message.getBodyBuffer().writeBytes(buf, 0,
> > > buf.readableBytes());
> > >                     ClientProducer producer =
> > > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> > >                     producer.send(message);
> > >              } finally {
> > >                     session.close();
> > >              }
> > >        }
> > >
> > >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws
> > > ActiveMQException {
> > >              ActiveMQBuffer result;
> > >              ClientSession session = this.sessionFactory.createSession();
> > >              try {
> > >                     session.start();
> > >                     ClientConsumer consumer =
> > > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> > >                     ClientMessage message = consumer.receive();
> > >                     result =
> > > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> > >                     message.getBodyBuffer().readBytes(result);
> > >              } finally {
> > >                     session.close();
> > >              }
> > >
> > >              return result;
> > >        }
> > >
> > >
> > >        public void startServer() throws Exception {
> > >              this.configuration = new ConfigurationImpl();
> > >              this.configuration.addAcceptorConfiguration("in-vm",
> > > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> > >              this.configuration.setPersistenceEnabled(true);
> > >              this.configuration.setSecurityEnabled(false);
> > >              this.configuration.addQueueConfiguration(new
> > > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> > >
> > >              this.server = new ActiveMQServerImpl(this.configuration);
> > >              this.server.start();
> > >        }
> > >
> >



-- 
Clebert Suconic

AW: send message

Posted by To...@t-systems.com.
The stack trace is correct

-----Ursprüngliche Nachricht-----
Von: Justin Bertram <jb...@apache.org> 
Gesendet: Montag, 22. März 2021 17:01
An: users@activemq.apache.org
Betreff: Re: send message

The stack-trace indicates you're invoking the "readString" method on line
93 of MailServerActiveMQClient.java, but I don't see that call in the code you pasted. Therefore, that stack-trace doesn't seem correct. Can you clarify this?


Justin

On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin <er...@cgi.com>
wrote:

> Fyi:
> 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text) And 
> "tive" is likely part of the string "ActiveMQ"?
> e.
>
> -----Oorspronkelijk bericht-----
> Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> Verzonden: maandag 22 maart 2021 16:41
> Aan: users@activemq.apache.org
> Onderwerp: AW: send message
>
>
> EXTERNAL SENDER:   Do not click any links or open any attachments unless
> you trust the sender and know the content is safe.
> EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que 
> vous ayez l'assurance que le contenu provient d'une source sûre.
>
> While sending / receiving a text message I get this
>
> java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> length=1953068645 is greater than readableBytes=3
>         at
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
>         at
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
>         at
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
>         at
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
>         at com.tsystems.gematik.kim.mailserver.mq
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
>         at com.tsystems.gematik.kim.mailserver.mq
> .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
>         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>         at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>         at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
>         at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTest
> Runner.java:209)
>
>
> -----Ursprüngliche Nachricht-----
> Von: Justin Bertram <jb...@apache.org>
> Gesendet: Montag, 22. März 2021 16:34
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> What actually fails? Do you have a stack-trace?
>
>
> Justin
>
> On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
>
> > I try to send and receive a netty ByteBuf message, but it fails.
> > What I'm doing wrong here? I even don't know ist he mistake in 
> > sending or receiving!
> > I was thinking to use the jms layer, but I'm receiving the data 
> > buffer throught a netty buffer and I want to avoid to convert the 
> > buffer to a byte array!
> >
> >        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> > ActiveMQException {
> >              ClientSession session = this.sessionFactory.createSession();
> >              try {
> >                     session.start();
> >                     ClientMessage message = session.createMessage(true);
> >                     message.getBodyBuffer().writeBytes(buf, 0, 
> > buf.readableBytes());
> >                     ClientProducer producer = 
> > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> >                     producer.send(message);
> >              } finally {
> >                     session.close();
> >              }
> >        }
> >
> >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
> > ActiveMQException {
> >              ActiveMQBuffer result;
> >              ClientSession session = this.sessionFactory.createSession();
> >              try {
> >                     session.start();
> >                     ClientConsumer consumer = 
> > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> >                     ClientMessage message = consumer.receive();
> >                     result =
> > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> >                     message.getBodyBuffer().readBytes(result);
> >              } finally {
> >                     session.close();
> >              }
> >
> >              return result;
> >        }
> >
> >
> >        public void startServer() throws Exception {
> >              this.configuration = new ConfigurationImpl();
> >              this.configuration.addAcceptorConfiguration("in-vm",
> > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> >              this.configuration.setPersistenceEnabled(true);
> >              this.configuration.setSecurityEnabled(false);
> >              this.configuration.addQueueConfiguration(new
> > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> >
> >              this.server = new ActiveMQServerImpl(this.configuration);
> >              this.server.start();
> >        }
> >
>

Re: send message

Posted by Justin Bertram <jb...@apache.org>.
The stack-trace indicates you're invoking the "readString" method on line
93 of MailServerActiveMQClient.java, but I don't see that call in the code
you pasted. Therefore, that stack-trace doesn't seem correct. Can you
clarify this?


Justin

On Mon, Mar 22, 2021 at 10:55 AM Dondorp, Erwin <er...@cgi.com>
wrote:

> Fyi:
> 1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text)
> And "tive" is likely part of the string "ActiveMQ"?
> e.
>
> -----Oorspronkelijk bericht-----
> Van: Tobias.Wolf@t-systems.com <To...@t-systems.com>
> Verzonden: maandag 22 maart 2021 16:41
> Aan: users@activemq.apache.org
> Onderwerp: AW: send message
>
>
> EXTERNAL SENDER:   Do not click any links or open any attachments unless
> you trust the sender and know the content is safe.
> EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que vous
> ayez l'assurance que le contenu provient d'une source sûre.
>
> While sending / receiving a text message I get this
>
> java.lang.IndexOutOfBoundsException: Error reading in simpleString,
> length=1953068645 is greater than readableBytes=3
>         at
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
>         at
> org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
>         at
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
>         at
> org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
>         at com.tsystems.gematik.kim.mailserver.mq
> .MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
>         at com.tsystems.gematik.kim.mailserver.mq
> .MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
>         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>         at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>         at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
>         at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
>
>
> -----Ursprüngliche Nachricht-----
> Von: Justin Bertram <jb...@apache.org>
> Gesendet: Montag, 22. März 2021 16:34
> An: users@activemq.apache.org
> Betreff: Re: send message
>
> What actually fails? Do you have a stack-trace?
>
>
> Justin
>
> On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:
>
> > I try to send and receive a netty ByteBuf message, but it fails.
> > What I'm doing wrong here? I even don't know ist he mistake in sending
> > or receiving!
> > I was thinking to use the jms layer, but I'm receiving the data buffer
> > throught a netty buffer and I want to avoid to convert the buffer to a
> > byte array!
> >
> >        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> > ActiveMQException {
> >              ClientSession session = this.sessionFactory.createSession();
> >              try {
> >                     session.start();
> >                     ClientMessage message = session.createMessage(true);
> >                     message.getBodyBuffer().writeBytes(buf, 0,
> > buf.readableBytes());
> >                     ClientProducer producer =
> > session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
> >                     producer.send(message);
> >              } finally {
> >                     session.close();
> >              }
> >        }
> >
> >        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws
> > ActiveMQException {
> >              ActiveMQBuffer result;
> >              ClientSession session = this.sessionFactory.createSession();
> >              try {
> >                     session.start();
> >                     ClientConsumer consumer =
> > session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
> >                     ClientMessage message = consumer.receive();
> >                     result =
> > ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
> >                     message.getBodyBuffer().readBytes(result);
> >              } finally {
> >                     session.close();
> >              }
> >
> >              return result;
> >        }
> >
> >
> >        public void startServer() throws Exception {
> >              this.configuration = new ConfigurationImpl();
> >              this.configuration.addAcceptorConfiguration("in-vm",
> > ACTIVE_MQ_EMBEDDED_SERVER_URL);
> >              this.configuration.setPersistenceEnabled(true);
> >              this.configuration.setSecurityEnabled(false);
> >              this.configuration.addQueueConfiguration(new
> > QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
> >
> >              this.server = new ActiveMQServerImpl(this.configuration);
> >              this.server.start();
> >        }
> >
>

RE: send message

Posted by "Dondorp, Erwin" <er...@cgi.com>.
Fyi:
1953068645(decimal) = 74697665(hexadecimal) = "tive"(ascii text)
And "tive" is likely part of the string "ActiveMQ"?
e.

-----Oorspronkelijk bericht-----
Van: Tobias.Wolf@t-systems.com <To...@t-systems.com> 
Verzonden: maandag 22 maart 2021 16:41
Aan: users@activemq.apache.org
Onderwerp: AW: send message


EXTERNAL SENDER:   Do not click any links or open any attachments unless you trust the sender and know the content is safe.
EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que vous ayez l'assurance que le contenu provient d'une source sûre.

While sending / receiving a text message I get this

java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
	at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
	at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
	at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
	at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
	at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
	at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)


-----Ursprüngliche Nachricht-----
Von: Justin Bertram <jb...@apache.org>
Gesendet: Montag, 22. März 2021 16:34
An: users@activemq.apache.org
Betreff: Re: send message

What actually fails? Do you have a stack-trace?


Justin

On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:

> I try to send and receive a netty ByteBuf message, but it fails.
> What I'm doing wrong here? I even don't know ist he mistake in sending 
> or receiving!
> I was thinking to use the jms layer, but I'm receiving the data buffer 
> throught a netty buffer and I want to avoid to convert the buffer to a 
> byte array!
>
>        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> ActiveMQException {
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientMessage message = session.createMessage(true);
>                     message.getBodyBuffer().writeBytes(buf, 0, 
> buf.readableBytes());
>                     ClientProducer producer = 
> session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
>                     producer.send(message);
>              } finally {
>                     session.close();
>              }
>        }
>
>        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
> ActiveMQException {
>              ActiveMQBuffer result;
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientConsumer consumer = 
> session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
>                     ClientMessage message = consumer.receive();
>                     result =
> ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
>                     message.getBodyBuffer().readBytes(result);
>              } finally {
>                     session.close();
>              }
>
>              return result;
>        }
>
>
>        public void startServer() throws Exception {
>              this.configuration = new ConfigurationImpl();
>              this.configuration.addAcceptorConfiguration("in-vm",
> ACTIVE_MQ_EMBEDDED_SERVER_URL);
>              this.configuration.setPersistenceEnabled(true);
>              this.configuration.setSecurityEnabled(false);
>              this.configuration.addQueueConfiguration(new
> QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
>
>              this.server = new ActiveMQServerImpl(this.configuration);
>              this.server.start();
>        }
>

AW: send message

Posted by To...@t-systems.com.
While sending / receiving a text message I get this

java.lang.IndexOutOfBoundsException: Error reading in simpleString, length=1953068645 is greater than readableBytes=3
	at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:185)
	at org.apache.activemq.artemis.api.core.SimpleString.readSimpleString(SimpleString.java:173)
	at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readStringInternal(ChannelBufferWrapper.java:113)
	at org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper.readString(ChannelBufferWrapper.java:98)
	at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClient.receiveTextMessageFromSmtpQueue(MailServerActiveMQClient.java:93)
	at com.tsystems.gematik.kim.mailserver.mq.MailServerActiveMQClientTest.sendAndReceive(MailServerActiveMQClientTest.java:28)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)


-----Ursprüngliche Nachricht-----
Von: Justin Bertram <jb...@apache.org> 
Gesendet: Montag, 22. März 2021 16:34
An: users@activemq.apache.org
Betreff: Re: send message

What actually fails? Do you have a stack-trace?


Justin

On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:

> I try to send and receive a netty ByteBuf message, but it fails.
> What I'm doing wrong here? I even don't know ist he mistake in sending 
> or receiving!
> I was thinking to use the jms layer, but I'm receiving the data buffer 
> throught a netty buffer and I want to avoid to convert the buffer to a 
> byte array!
>
>        public void sendMessageToSmtpQueue(ByteBuf buf) throws 
> ActiveMQException {
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientMessage message = session.createMessage(true);
>                     message.getBodyBuffer().writeBytes(buf, 0, 
> buf.readableBytes());
>                     ClientProducer producer = 
> session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
>                     producer.send(message);
>              } finally {
>                     session.close();
>              }
>        }
>
>        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
> ActiveMQException {
>              ActiveMQBuffer result;
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientConsumer consumer = 
> session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
>                     ClientMessage message = consumer.receive();
>                     result =
> ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
>                     message.getBodyBuffer().readBytes(result);
>              } finally {
>                     session.close();
>              }
>
>              return result;
>        }
>
>
>        public void startServer() throws Exception {
>              this.configuration = new ConfigurationImpl();
>              this.configuration.addAcceptorConfiguration("in-vm",
> ACTIVE_MQ_EMBEDDED_SERVER_URL);
>              this.configuration.setPersistenceEnabled(true);
>              this.configuration.setSecurityEnabled(false);
>              this.configuration.addQueueConfiguration(new
> QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
>
>              this.server = new ActiveMQServerImpl(this.configuration);
>              this.server.start();
>        }
>

Re: send message

Posted by Justin Bertram <jb...@apache.org>.
What actually fails? Do you have a stack-trace?


Justin

On Mon, Mar 22, 2021 at 9:53 AM <To...@t-systems.com> wrote:

> I try to send and receive a netty ByteBuf message, but it fails.
> What I'm doing wrong here? I even don't know ist he mistake in sending or
> receiving!
> I was thinking to use the jms layer, but I'm receiving the data buffer
> throught a netty buffer and I want to avoid to convert the buffer to a byte
> array!
>
>        public void sendMessageToSmtpQueue(ByteBuf buf) throws
> ActiveMQException {
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientMessage message = session.createMessage(true);
>                     message.getBodyBuffer().writeBytes(buf, 0,
> buf.readableBytes());
>                     ClientProducer producer =
> session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
>                     producer.send(message);
>              } finally {
>                     session.close();
>              }
>        }
>
>        public ActiveMQBuffer receiveMessageFromSmtpQueue() throws
> ActiveMQException {
>              ActiveMQBuffer result;
>              ClientSession session = this.sessionFactory.createSession();
>              try {
>                     session.start();
>                     ClientConsumer consumer =
> session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
>                     ClientMessage message = consumer.receive();
>                     result =
> ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
>                     message.getBodyBuffer().readBytes(result);
>              } finally {
>                     session.close();
>              }
>
>              return result;
>        }
>
>
>        public void startServer() throws Exception {
>              this.configuration = new ConfigurationImpl();
>              this.configuration.addAcceptorConfiguration("in-vm",
> ACTIVE_MQ_EMBEDDED_SERVER_URL);
>              this.configuration.setPersistenceEnabled(true);
>              this.configuration.setSecurityEnabled(false);
>              this.configuration.addQueueConfiguration(new
> QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));
>
>              this.server = new ActiveMQServerImpl(this.configuration);
>              this.server.start();
>        }
>