You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Krystian <k....@gmail.com> on 2010/11/08 02:00:17 UTC

Cannot reply to a message routed by camel

Hi,

I know the way I am doing it might be a bit off from what is considered
normal, however I couldn't do it any other way.

I have a queue of user actions to be executed on the system.
There are several concurrent listeners listening for the actions, and they
take them off the queue and 'execute' them.
If an action is executed for a user and another comes in for the same user
it cannot be executed and has to wait for the first one to be completed.
I would normally use ActiveMQ redelivery policy and have it done in a sec,
however with redelivery policy delay the listener is blocked. I cannot have
that. When one action is waiting same listener can execute few other actions
and just increasing the number of concurrent listeners is not the way to go
for me.
To add some complexity to the process, after the action is finished I am
sending a response back to thread which created the first message. I am
using Spring and MessageListenerAdapter so it's pretty straight forward to
do it.

Now. In order to get around the delay I decided to use Camel delay pattern.
I execute my custom bean to calculate the delay and thanks to the fact that
all messages are delayed by the same amount of time messages are always
delayed the way I want. To achieve that I had to resign from redelivery
handling in ActiveMQ and I have it set to maximumRedeliveries = - and
initialRedeliveryDelay = 0. Camel listens on ActiveMQ.DLQ queue and resends
the messages to the original queue.

Here's how it works:

Start -> message sent to ActionQueue -> check if action can be executed:
Yes -> action is executed -> response sent back      <- this works fine

No -> transaction is rolled back -> ActiveMQ redelivery kicks in and sends
message to ActiveMQ.DLQ -> camel picks up the message -> message delayed ->
message sent to ActionQueue

Unfortunately, after the message is sent to ActionQueue and is picked up by
the listener, the response to this message never reaches the caller.

I ran my app with debug logging and can see that when message is rerouted
the reply-to queue changes.

Is there any way I could get this to work?

Thanks,
Krystian
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3254431.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Krystian <k....@gmail.com>.
It all seems like it's a workaround rather than a fix.
I mean... the olution I've got right now is simple and works fine with this
one small issue: reply-to queue being changed.
Since reply-to queues are changing I believe new ones are created. I'm not
sure if that's the case. I cannot see anything in the debug logs, whether
there's a queue created or not. That's the mystery. How come reply to queue
changes between routed messages. To be honest I thought it would be the same
message rerouted all the time with some additional camel-only properties
appended to the body. It seems [again] this is not the case.

So... to recap.
I'm not willing to change the process now [before I see that there's no
other option] as all the changes seem to me like resource hogs in situation
of let's say 100 000 clients. Different listener groups would mean that the
order of messages could get screwed up [at least more screwed up than in
original solution].

Any ideas?

Thanks,
Krystian
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3255019.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Claus Ibsen <cl...@gmail.com>.
Maybe you can use JMSXGroupID and concurrent consumers.
Then the messages within the same group id will be processed in
sequence. But you can leverage parallelism.



On Mon, Nov 8, 2010 at 10:45 AM, Krystian <k....@gmail.com> wrote:
>
> There is an unlimited number of users on the system.
> I can't get each one a separate queue.
> --
> View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3254779.html
> Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Cannot reply to a message routed by camel

Posted by Krystian <k....@gmail.com>.
There is an unlimited number of users on the system.
I can't get each one a separate queue.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3254779.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Donald Whytock <dw...@gmail.com>.
Why not give each user its own SEDA queue and have the listener on the
main queue route messages among the user queues?  Each user would
still be single-threaded, but at least the listener wouldn't be
blocked and resubmits and delays wouldn't be necessary.

Don

On Sun, Nov 7, 2010 at 8:00 PM, Krystian <k....@gmail.com> wrote:
>
> Hi,
>
> I know the way I am doing it might be a bit off from what is considered
> normal, however I couldn't do it any other way.
>
> I have a queue of user actions to be executed on the system.
> There are several concurrent listeners listening for the actions, and they
> take them off the queue and 'execute' them.
> If an action is executed for a user and another comes in for the same user
> it cannot be executed and has to wait for the first one to be completed.
> I would normally use ActiveMQ redelivery policy and have it done in a sec,
> however with redelivery policy delay the listener is blocked. I cannot have
> that. When one action is waiting same listener can execute few other actions
> and just increasing the number of concurrent listeners is not the way to go
> for me.
> To add some complexity to the process, after the action is finished I am
> sending a response back to thread which created the first message. I am
> using Spring and MessageListenerAdapter so it's pretty straight forward to
> do it.
>
> Now. In order to get around the delay I decided to use Camel delay pattern.
> I execute my custom bean to calculate the delay and thanks to the fact that
> all messages are delayed by the same amount of time messages are always
> delayed the way I want. To achieve that I had to resign from redelivery
> handling in ActiveMQ and I have it set to maximumRedeliveries = - and
> initialRedeliveryDelay = 0. Camel listens on ActiveMQ.DLQ queue and resends
> the messages to the original queue.
>
> Here's how it works:
>
> Start -> message sent to ActionQueue -> check if action can be executed:
> Yes -> action is executed -> response sent back      <- this works fine
>
> No -> transaction is rolled back -> ActiveMQ redelivery kicks in and sends
> message to ActiveMQ.DLQ -> camel picks up the message -> message delayed ->
> message sent to ActionQueue
>
> Unfortunately, after the message is sent to ActionQueue and is picked up by
> the listener, the response to this message never reaches the caller.
>
> I ran my app with debug logging and can see that when message is rerouted
> the reply-to queue changes.
>
> Is there any way I could get this to work?
>
> Thanks,
> Krystian
> --
> View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3254431.html
> Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.
>

Re: Cannot reply to a message routed by camel

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hmm... Interesting... So what you are looking for is some kind of executor on
a Browsable Endpoint (tied to a DB, Queue...) that cherry picks messages for
downstream execution based on the execution status/flag associated with a
previously processed message. 

I am afraid such a capability does not exist as yet in Camel. In the
meantime, You could do this in a custom Processor that should be able to
what you want...

Cheers,

Ashwin...  

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3255369.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Krystian <k....@gmail.com>.
Ahhh

one more thing.

Although I have set:

    <bean id="redeliveryPolicy"
class="org.apache.activemq.RedeliveryPolicy">
        <property name="maximumRedeliveries" value="0"/>
        <property name="initialRedeliveryDelay" value="0"/>
        <property name="useExponentialBackOff" value="false"/>
    </bean>

for AMQ [5.3.2] and:
errorHandler(deadLetterChannel("activemq:ActiveMQ.DLQ").maximumRedeliveries(0).redeliveryDelay(1).maximumRedeliveryDelay(1))
from("activemq:ActiveMQ.DLQ?recoveryInterval=1&exchangePattern=OutOnly").delay().expression(bean(DelayerBean.class,
"sendAtTime")).asyncDelayed().to("activemq:testQueue?recoveryInterval=1")

I still get some delays when message is routed to testQueue and listener
rollsback the transaction.
I hoped that the rolledback message would immediately go to the ActiveMQ.DLQ
but it seems it is delayed.


-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3256000.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Krystian <k....@gmail.com>.
Hi Donald,

Yes, I believe this would work.
I would have to have a map with messages, where key = messageId and another
map where user ids are the keys and list of message Ids are the values.
This way I could handle it without all the JMS hacking I'm doing at the
moment.

Actually I was able to make my scenario work with ActiveMQ and Camel.
The only thing I needed to do was add exchangePattern=OutOnly to the from
queue.
Right now it looks like this:

errorHandler(deadLetterChannel("activemq:ActiveMQ.DLQ").maximumRedeliveries(0).redeliveryDelay(1).maximumRedeliveryDelay(1))
       
from("activemq:ActiveMQ.DLQ?recoveryInterval=1&exchangePattern=OutOnly").delay().expression(bean(DelayerBean.class,
"sendAtTime")).asyncDelayed().to("activemq:testQueue?recoveryInterval=1")

I've tried without the recoveryPeriod but it didn't work, so this have to be
there as well.

Anyway since I see the benefits of using solution you proposed I will go
with that and try to implement.

However this little snippet I pasted may be useful to someone someday ;)

Thanks,
Krystian
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3255378.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Donald Whytock <dw...@gmail.com>.
Okay...so what you need in any case is something that keeps track of
what users are currently being handled.  A message comes in, the
set/tree/hash that tracks the users in use is checked, and if the two
users aren't in it then entries are made for them and the message gets
handled; the message handler then tells the tracker when it's done.

If a message comes in and there's entries for one or both of the
users, then that message is added onto linked lists anchored by the
user entries in the hash, so that when a handler announces freed
users, then entries in the lists for those users are fetched and
handled.

Listener's never blocked, JMS queue's kept clean, no re-queueings, and
thread pool size is independent of user base.  Possible sequencing
issues, but not for a given user pair.

On Mon, Nov 8, 2010 at 11:03 AM, Krystian <k....@gmail.com> wrote:
>
> Hi guys,
>
> thanks for the info about ActiveMQ message groups, it would work
> perfectly... unfortunately my solution is a tad more complicated.
> I didn't go into detail in the first message, sorry about that.
> One action concerns 2 users. It is an action between two of them. So my
> message, which is actually a Map Message contains two fields:
> userA, userB
> Depending on the initiator of the action, this user will be userA and the
> other user will be userB.
>
> So i unfortunately cannot create groups with userId, simply because I always
> have 2 and none of them can participate in any other action when this one is
> executed.
> So it I have:
> userA, userB, userC, userD and get this actions:
> 1. userA, userB
> 2. userB, userC
> 3. userC, userD
>
> I want the first one to run, the second one to wait and the third one to
> run. Then when the first action is done and the third action is done the
> second one can be executed.
> If I were to use message groups I would not be able to create groups in a
> way where message 1,2  and 3 would end up on the same queue.
>
> A little bit complicated, yes, but these are the requirements :(
> --
> View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3255253.html
> Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.
>

Re: Cannot reply to a message routed by camel

Posted by Krystian <k....@gmail.com>.
Hi guys,

thanks for the info about ActiveMQ message groups, it would work
perfectly... unfortunately my solution is a tad more complicated.
I didn't go into detail in the first message, sorry about that.
One action concerns 2 users. It is an action between two of them. So my
message, which is actually a Map Message contains two fields:
userA, userB
Depending on the initiator of the action, this user will be userA and the
other user will be userB.

So i unfortunately cannot create groups with userId, simply because I always
have 2 and none of them can participate in any other action when this one is
executed.
So it I have:
userA, userB, userC, userD and get this actions:
1. userA, userB
2. userB, userC
3. userC, userD

I want the first one to run, the second one to wait and the third one to
run. Then when the first action is done and the third action is done the
second one can be executed.
If I were to use message groups I would not be able to create groups in a
way where message 1,2  and 3 would end up on the same queue.

A little bit complicated, yes, but these are the requirements :(
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3255253.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Cannot reply to a message routed by camel

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Please checkout ActiveMQ message groups. This is ideal for your use-case.
This way you don't have to create a million queues and yet the ordered
processing of certain messages without losing load-balancing and failover
benefits.

http://activemq.apache.org/message-groups.html
http://activemq.apache.org/message-groups.html 

Cheers,

Ashwin...


-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/Cannot-reply-to-a-message-routed-by-camel-tp3254431p3255236.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.