You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ctytgat <ch...@gmail.com> on 2012/04/03 17:52:30 UTC

Advice needed with Camel/AMQ use case

Hi All,

I've got the following use case which is currently implemented using
camel/AMQ:

Queue 'dispatchHttpQueue' contains messages for different destinations. I
need to support about 500 destinations.
(The destination is set on the message using a camel/JMS header)
Each message needs to be delivered to its destination via a rest interface.
The connection to the destinations is shaky at best (3G/gprs)

Now, what I currently have is a limited amount of concurrent consumers (3)
that forward messages to a HTTP endpoint. 
Exceptions (mostly IO errors) are handled by re-inserting the message on the
queue with an AMQ_SCHEDULED_DELAY header (custom bean) until a number of
retries is exhausted. After all retries failed the message is moved to a
DLQ.

Code for this is shown below.

But this approach has the following drawbacks:
- original message order is not maintained when failures occur
- if the queue contains quite some messages for a destination which is
temporarily unreachable, it will hinder/slowdown delivery to other
destinations.


I'm looking for a better solution where
(1) order is preserved
(2) unreachable destinations have no effect on delivery to reachable ones
(3) whenever a destination is unreachable, the oldest message is retried
until it goes through or expires.

What I've considered so far:
- using AMQ message groups to preserve ordering. Group ID is destination ID.
But unless I configure 500 concurrentConsumers  (= 500 threads), I still
don't solve (2). Obviously that's not an option.
- create 1 queue per destination and consume from all queues using a
wildcard. But I don't see a way of accomplishing everything without having
again 500 threads.

Any suggestions would be greatly appreciated!


        from(activemq:queue:dispatchHttpQueue +
           
"?concurrentConsumers={{hermes.dris.distribution.kv78.concurrentOutgoingHttpDispatchers}}&"
+
            
"maxConcurrentConsumers={{hermes.dris.distribution.kv78.maxConcurrentOutgoingHttpDispatchers}}")
            .routeId(ROUTE_ID_DISPATCH_HTTP)
            // use multicast instead of a pipeline, or the audit log will
contain the http response!
            .multicast().stopOnException().to(ENDPOINT_TIMINGPOINT,
ENDPOINT_AUDIT_OUTGOING);

        from(ENDPOINT_TIMINGPOINT)
            .routeId(ROUTE_ID_TIMINGPOINT)
            .onException(IOException.class)
                .handled(true)
                .beanRef("dispatchRetryTagger")
                .choice()
                    .when(header("dispatchRetryCount").isLessThan(3))
                        .log(LoggingLevel.WARN, "Failed delivery (attempt =
${in.header.dispatchRetryCount}) for exchangeId ${id}:
${in.header.CamelExceptionCaught}")
                        .to(activemq:queue:dispatchHttpQueue)
                    .otherwise()
                        .removeHeader("AMQ_SCHEDULED_DELAY")
                        .to(ENDPOINT_DLQ)
                .end()
            .end()
            .removeHeaders("CamelHttp*")
            .setHeader(Exchange.HTTP_URI, simple("http://${header." +
HEADER_DESTINATION_ADDRESS + "}"))
            .setHeader(Exchange.HTTP_PATH,
simple("${properties:hermes.dris.distribution.kv78.timingpoint.urlpath}"))
            .setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
            .setHeader(Exchange.CONTENT_ENCODING, constant("gzip")) // use
gzip compression
            .log(LoggingLevel.DEBUG, "Sending request to
${in.header.CamelHttpUri}/${in.header.CamelHttpPath}")
            .to(ENDPOINT_TIMINGPOINT_HTTP +
"?httpClientConfigurerRef=timingPointHttpClientConfigurer&headerFilterStrategy=#distributionHttpHeaderFilterStrategy");

--
View this message in context: http://camel.465427.n5.nabble.com/Advice-needed-with-Camel-AMQ-use-case-tp5615624p5615624.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Advice needed with Camel/AMQ use case

Posted by ctytgat <ch...@gmail.com>.
Hey Raúl,

thx for your reply. It's been a while but the problem is still relevant.

In the meantime I got to a more or less acceptable solution by introducing a
blacklist of destinations, and delaying messages based on this blacklist.
This way I don't block consumer threads on connection timeouts which
basically solves (2).

I still can't preserve ordering though, which I'm sure will cause us
problems sooner or later.

You asked to clarify the following: 
"create 1 queue per destination and consume from all queues using a
wildcard. But I don't see a way of accomplishing everything without having
again 500 threads. "

Well, this is basically your "multiplexing" solution.
But assume I got 500 queues, and 20 consumers. If I got 30 unreachable
destinations, these 20 threads could potentially be waiting on connection
timeouts etc, while the other 470 destinations don't get served quickly
enough.
This is really worst case, sure, but theoretically it can happen :)

Also, don't you think having 500 queues won't severely impact performance?
There's also more bookkeeping to do like cleanup obsolete queues etc...

If you got more ideas, I'd be glad to hear them :)

--
View this message in context: http://camel.465427.n5.nabble.com/Advice-needed-with-Camel-AMQ-use-case-tp5615624p5715295.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Advice needed with Camel/AMQ use case

Posted by Raul Kripalani <ra...@fusesource.com>.
Hi there,

This certainly seems like an interesting use case. Before I come forth with
an idea, could you please clarify what you mean with "create 1 queue per
destination and consume from all queues using a
wildcard. But I don't see a way of accomplishing everything without
having again
500 threads." - I don't see how having 500 threads could guarantee the
Quality of Service requirements you have anyway... I'm sure I'm missing
something?

Besides that, have you thought about a multiplex-like pattern? If you can
drop the explicit message scheduling that you do, and rely on JMS
transactions with a correctly configured RedeliveryPolicy to match your
requirements, you could implement the following solution:

   - <route1> "the decomposer" => consume from dispatchHttpQueue and
   de-multiplex into the 500 queues depending on the final destination. Queue
   name pattern: "prefix.destination.<destinationId>". Compute this
   destination dynamically using recipient list, routing slip or dynamic
   router.
   - <route2> "the dispatcher" => consume from prefix.destination.* using
   local JMS transactions. Have as many threads as you want. No threads
   dedicated to specific destinations are needed. If an Exception occurs,
   Camel will rollback the JMS transaction and the redelivery policy will kick
   in. If you have a sequence of messages A, B, C, D and A succeeds but B
   fails, C and D will not be consumed until B either succeeds or gets
   poisoned (i.e. moved to the DLQ).

Hope this helps.

Regards,

 *Raúl Kripalani*
Principal Consultant | FuseSource Corp.
raul@fusesource.com | fusesource.com <http://www.fusesource.com/>
skype: raul.fuse | twitter: @raulvk <http://twitter.com/raulvk>,
@fusenews<http://twitter.com/fusenews>

On 4 April 2012 13:18, ctytgat <ch...@gmail.com> wrote:

> asyncConsumers certainly won't help me with maintaining the order.
>
> I'm currently trying to implement something around AMQ message groups after
> all.
> Writing some custom sequencing and error handling code might do the trick.
> Won't be a very clean solution though.
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Advice-needed-with-Camel-AMQ-use-case-tp5615624p5617599.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Advice needed with Camel/AMQ use case

Posted by ctytgat <ch...@gmail.com>.
asyncConsumers certainly won't help me with maintaining the order.

I'm currently trying to implement something around AMQ message groups after
all.
Writing some custom sequencing and error handling code might do the trick.
Won't be a very clean solution though.


--
View this message in context: http://camel.465427.n5.nabble.com/Advice-needed-with-Camel-AMQ-use-case-tp5615624p5617599.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Advice needed with Camel/AMQ use case

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Just a few notes, as I just skim read your post.

AMQ 5.6 will have support for asynchronous redeliveries. You would
need to enable this to use it.
Also check out the asyncConsumer=true option in Camel 2.9 on the JMS component.



On Tue, Apr 3, 2012 at 5:52 PM, ctytgat <ch...@gmail.com> wrote:
> Hi All,
>
> I've got the following use case which is currently implemented using
> camel/AMQ:
>
> Queue 'dispatchHttpQueue' contains messages for different destinations. I
> need to support about 500 destinations.
> (The destination is set on the message using a camel/JMS header)
> Each message needs to be delivered to its destination via a rest interface.
> The connection to the destinations is shaky at best (3G/gprs)
>
> Now, what I currently have is a limited amount of concurrent consumers (3)
> that forward messages to a HTTP endpoint.
> Exceptions (mostly IO errors) are handled by re-inserting the message on the
> queue with an AMQ_SCHEDULED_DELAY header (custom bean) until a number of
> retries is exhausted. After all retries failed the message is moved to a
> DLQ.
>
> Code for this is shown below.
>
> But this approach has the following drawbacks:
> - original message order is not maintained when failures occur
> - if the queue contains quite some messages for a destination which is
> temporarily unreachable, it will hinder/slowdown delivery to other
> destinations.
>
>
> I'm looking for a better solution where
> (1) order is preserved
> (2) unreachable destinations have no effect on delivery to reachable ones
> (3) whenever a destination is unreachable, the oldest message is retried
> until it goes through or expires.
>
> What I've considered so far:
> - using AMQ message groups to preserve ordering. Group ID is destination ID.
> But unless I configure 500 concurrentConsumers  (= 500 threads), I still
> don't solve (2). Obviously that's not an option.
> - create 1 queue per destination and consume from all queues using a
> wildcard. But I don't see a way of accomplishing everything without having
> again 500 threads.
>
> Any suggestions would be greatly appreciated!
>
>
>        from(activemq:queue:dispatchHttpQueue +
>
> "?concurrentConsumers={{hermes.dris.distribution.kv78.concurrentOutgoingHttpDispatchers}}&"
> +
>
> "maxConcurrentConsumers={{hermes.dris.distribution.kv78.maxConcurrentOutgoingHttpDispatchers}}")
>            .routeId(ROUTE_ID_DISPATCH_HTTP)
>            // use multicast instead of a pipeline, or the audit log will
> contain the http response!
>            .multicast().stopOnException().to(ENDPOINT_TIMINGPOINT,
> ENDPOINT_AUDIT_OUTGOING);
>
>        from(ENDPOINT_TIMINGPOINT)
>            .routeId(ROUTE_ID_TIMINGPOINT)
>            .onException(IOException.class)
>                .handled(true)
>                .beanRef("dispatchRetryTagger")
>                .choice()
>                    .when(header("dispatchRetryCount").isLessThan(3))
>                        .log(LoggingLevel.WARN, "Failed delivery (attempt =
> ${in.header.dispatchRetryCount}) for exchangeId ${id}:
> ${in.header.CamelExceptionCaught}")
>                        .to(activemq:queue:dispatchHttpQueue)
>                    .otherwise()
>                        .removeHeader("AMQ_SCHEDULED_DELAY")
>                        .to(ENDPOINT_DLQ)
>                .end()
>            .end()
>            .removeHeaders("CamelHttp*")
>            .setHeader(Exchange.HTTP_URI, simple("http://${header." +
> HEADER_DESTINATION_ADDRESS + "}"))
>            .setHeader(Exchange.HTTP_PATH,
> simple("${properties:hermes.dris.distribution.kv78.timingpoint.urlpath}"))
>            .setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
>            .setHeader(Exchange.CONTENT_ENCODING, constant("gzip")) // use
> gzip compression
>            .log(LoggingLevel.DEBUG, "Sending request to
> ${in.header.CamelHttpUri}/${in.header.CamelHttpPath}")
>            .to(ENDPOINT_TIMINGPOINT_HTTP +
> "?httpClientConfigurerRef=timingPointHttpClientConfigurer&headerFilterStrategy=#distributionHttpHeaderFilterStrategy");
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Advice-needed-with-Camel-AMQ-use-case-tp5615624p5615624.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/