You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by mayuraviraj <ma...@gmail.com> on 2016/02/18 04:55:35 UTC

Identify ActiveMQ asyncrhonous message failures?

I have ActiveMQ persistent queue and due to performance i'm publishing to
producer using async mode.


My Code as following, 
     ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory(brokerURL);
     factory.setUseAsyncSend(true);
     PooledConnectionFactory connectionFactory = new
PooledConnectionFactory(factory);
     Connection connection = connectionFactory.createConnection();
     connection.start();
     Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
     MessageProduer producer = session.createProducer(destination);
     Queue queue = session.createQueue(qName);
     producer.send(queue, message);


Is there a way to register handler to get the error/success of
`producer.send()` method ?



--
View this message in context: http://activemq.2283324.n4.nabble.com/Identify-ActiveMQ-asyncrhonous-message-failures-tp4707716.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Identify ActiveMQ asyncrhonous message failures?

Posted by Tim Bain <tb...@alumni.duke.edu>.
Remember that you can always call a private or protected method (or field)
via reflection.  You pay a price in terms of both performance and
maintainability, but neither price is so high that you shouldn't at least
consider the option if you don't have a better one.
On Feb 19, 2016 9:16 AM, "Timothy Bish" <ta...@gmail.com> wrote:

> On 02/19/2016 02:35 AM, mayuraviraj wrote:
> > While I was analysing how activemq do it async send internally I found
> > following approach to get async response. ( This is using activemq
> producer
> > implementation). Unfortunately i had to abandon PooledConnectionFactory
> > since PooledConnection does not have a way to return
> ActiveMQMessageProducer
> > ( it has method with protected access). However I believe even-though
> > following code using only once connection since sessions are created in
> > separate thread, performance won't be impacted.
> >
> > ActiveMQConnectionFactory factory = new
> > ActiveMQConnectionFactory(brokerURL);
> > factory.setUseAsyncSend(true);
> > Connection connection = connectionFactory.createConnection();
> > connection.start();
> > Session session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> > MessageProduer producer = session.createProducer(destination);
> > Queue queue = session.createQueue(qName);
> > ((ActiveMQMessageProducer)producer).send(queue, message, new
> AsyncCallback()
> > {
> >         @Override
> >         public void onSuccess() {
> >
> >         }
> >
> >         @Override
> >         public void onException(JMSException exception) {
> >
> >         }
> >     };);
> >
> >
> >
> > --
> > View this message in context:
> http://activemq.2283324.n4.nabble.com/Identify-ActiveMQ-asyncrhonous-message-failures-tp4707716p4707854.html
> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >
> The use of the configuration option factory.setUseAsyncSend(true); won't
> have any effect on the send in this case.
>
> Also keep in mind that you will need to wait for all the onComplete
> callbacks to receive the ACK from the broker to be sure all your sends
> are successful which will lower the performance to something closer to
> what you saw with non-async sends.
>
> --
> Tim Bish
> twitter: @tabish121
> blog: http://timbish.blogspot.com/
>
>

Re: Identify ActiveMQ asyncrhonous message failures?

Posted by Timothy Bish <ta...@gmail.com>.
On 02/19/2016 02:35 AM, mayuraviraj wrote:
> While I was analysing how activemq do it async send internally I found
> following approach to get async response. ( This is using activemq producer
> implementation). Unfortunately i had to abandon PooledConnectionFactory
> since PooledConnection does not have a way to return ActiveMQMessageProducer
> ( it has method with protected access). However I believe even-though
> following code using only once connection since sessions are created in
> separate thread, performance won't be impacted. 
>
> ActiveMQConnectionFactory factory = new
> ActiveMQConnectionFactory(brokerURL);
> factory.setUseAsyncSend(true);
> Connection connection = connectionFactory.createConnection();
> connection.start();
> Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
> MessageProduer producer = session.createProducer(destination);
> Queue queue = session.createQueue(qName);
> ((ActiveMQMessageProducer)producer).send(queue, message, new AsyncCallback()
> {
>         @Override
>         public void onSuccess() {
>
>         }
>
>         @Override
>         public void onException(JMSException exception) {
>
>         }
>     };);
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Identify-ActiveMQ-asyncrhonous-message-failures-tp4707716p4707854.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
The use of the configuration option factory.setUseAsyncSend(true); won't
have any effect on the send in this case.

Also keep in mind that you will need to wait for all the onComplete
callbacks to receive the ACK from the broker to be sure all your sends
are successful which will lower the performance to something closer to
what you saw with non-async sends.

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


Re: Identify ActiveMQ asyncrhonous message failures?

Posted by mayuraviraj <ma...@gmail.com>.
While I was analysing how activemq do it async send internally I found
following approach to get async response. ( This is using activemq producer
implementation). Unfortunately i had to abandon PooledConnectionFactory
since PooledConnection does not have a way to return ActiveMQMessageProducer
( it has method with protected access). However I believe even-though
following code using only once connection since sessions are created in
separate thread, performance won't be impacted. 

ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory(brokerURL);
factory.setUseAsyncSend(true);
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProduer producer = session.createProducer(destination);
Queue queue = session.createQueue(qName);
((ActiveMQMessageProducer)producer).send(queue, message, new AsyncCallback()
{
        @Override
        public void onSuccess() {

        }

        @Override
        public void onException(JMSException exception) {

        }
    };);



--
View this message in context: http://activemq.2283324.n4.nabble.com/Identify-ActiveMQ-asyncrhonous-message-failures-tp4707716p4707854.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Identify ActiveMQ asyncrhonous message failures?

Posted by Christopher Shannon <ch...@gmail.com>.
No there isn't, with async sends you won't know if the send has failed once
it leaves the client because you won't get notified by the receiver of the
status.  If you need to know the status (error or success) then you have to
do a sync send.  The trade off for performance is that some message loss is
acceptable.

On Wed, Feb 17, 2016 at 10:55 PM, mayuraviraj <ma...@gmail.com> wrote:

> I have ActiveMQ persistent queue and due to performance i'm publishing to
> producer using async mode.
>
>
> My Code as following,
>      ActiveMQConnectionFactory factory = new
> ActiveMQConnectionFactory(brokerURL);
>      factory.setUseAsyncSend(true);
>      PooledConnectionFactory connectionFactory = new
> PooledConnectionFactory(factory);
>      Connection connection = connectionFactory.createConnection();
>      connection.start();
>      Session session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
>      MessageProduer producer = session.createProducer(destination);
>      Queue queue = session.createQueue(qName);
>      producer.send(queue, message);
>
>
> Is there a way to register handler to get the error/success of
> `producer.send()` method ?
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Identify-ActiveMQ-asyncrhonous-message-failures-tp4707716.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>