Multicast with choice

View: New views
9 Messages — Rating Filter:   Alert me  

Multicast with choice

by Louis Polycarpou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to broadcast a feed to multiple endpoints but with content-based selection. I assume I need to use multicast, however, I can't achieve conditional multicast based on content selection since I can't use an otherwise() method after using multicast().to("endpoint1", "endpoint2")

Furthermore, the to() method supports a list of endpoints without requiring a multicast first so what is the difference between that and a multicast().to(...)?

feed in -> multicast to two outputs

To recap with code:

1) I can't use otherwise after a multicast...

        from(cnn).
                choice().
                when(xpath(filter)).multicast().to(im, archive); // I can't now use otherwise()...

2) Do I really need multicast or can I just do the following...?

        from(cnn).
                choice().
                when(xpath(filter)).to(im, archive).
                otherwise().to(myPojo);

Re: Multicast with choice

by Louis Polycarpou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Louis Polycarpou wrote:
I'm trying to broadcast a feed to multiple endpoints but with content-based selection. I assume I need to use multicast, however, I can't achieve conditional multicast based on content selection since I can't use an otherwise() method after using multicast().to("endpoint1", "endpoint2")

Furthermore, the to() method supports a list of endpoints without requiring a multicast first so what is the difference between that and a multicast().to(...)?

feed in -> multicast to two outputs

To recap with code:

1) I can't use otherwise after a multicast...

        from(cnn).
                choice().
                when(xpath(filter)).multicast().to(im, archive); // I can't now use otherwise()...

2) Do I really need multicast or can I just do the following...?

        from(cnn).
                choice().
                when(xpath(filter)).to(im, archive).
                otherwise().to(myPojo);
One way I've worked around this is to inverse the filter and do the multicast in the otherwise() part but clearly this doesn't answer my original question:

from(cnn).
                choice().
                when(xpath(filter)).to(stdout).
                otherwise().multicast().to(im, archive);

Re: Multicast with choice

by hzbarcea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Did you try end() to terminate the multicast?  As in:
from(uri).
   choice().
     when(expr).multicast().to(uris).end().
     otherwise().to(pojo);

Cheers
Hadrian


On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:

>
>
>
> Louis Polycarpou wrote:
>>
>> I'm trying to broadcast a feed to multiple endpoints but with
>> content-based selection. I assume I need to use multicast, however, I
>> can't achieve conditional multicast based on content selection  
>> since I
>> can't use an otherwise() method after using  
>> multicast().to("endpoint1",
>> "endpoint2")
>>
>> Furthermore, the to() method supports a list of endpoints without
>> requiring a multicast first so what is the difference between that  
>> and a
>> multicast().to(...)?
>>
>> feed in -> multicast to two outputs
>>
>> To recap with code:
>>
>> 1) I can't use otherwise after a multicast...
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).multicast().to(im, archive); // I
>> can't now use otherwise()...
>>
>> 2) Do I really need multicast or can I just do the following...?
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).to(im, archive).
>>                otherwise().to(myPojo);
>>
>>
>
> One way I've worked around this is to inverse the filter and do the
> multicast in the otherwise() part but clearly this doesn't answer my
> original question:
>
> from(cnn).
>                choice().
>                when(xpath(filter)).to(stdout).
>                otherwise().multicast().to(im, archive);
>
> --
> View this message in context: http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Multicast with choice

by Louis Polycarpou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks. I'll try that.  The multicast fluent builder example here  doesn't use end:

from("direct:a").multicast().to("direct:x", "direct:y", "direct:z");

What's the difference between:

 multicast().to("direct:x", "direct:y", "direct:z").end();

and

 to("direct:x", "direct:y", "direct:z");

Thanks.
Hadrian Zbarcea wrote:
Hi,

Did you try end() to terminate the multicast?  As in:
from(uri).
   choice().
     when(expr).multicast().to(uris).end().
     otherwise().to(pojo);

Cheers
Hadrian


On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:

>
>
>
> Louis Polycarpou wrote:
>>
>> I'm trying to broadcast a feed to multiple endpoints but with
>> content-based selection. I assume I need to use multicast, however, I
>> can't achieve conditional multicast based on content selection  
>> since I
>> can't use an otherwise() method after using  
>> multicast().to("endpoint1",
>> "endpoint2")
>>
>> Furthermore, the to() method supports a list of endpoints without
>> requiring a multicast first so what is the difference between that  
>> and a
>> multicast().to(...)?
>>
>> feed in -> multicast to two outputs
>>
>> To recap with code:
>>
>> 1) I can't use otherwise after a multicast...
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).multicast().to(im, archive); // I
>> can't now use otherwise()...
>>
>> 2) Do I really need multicast or can I just do the following...?
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).to(im, archive).
>>                otherwise().to(myPojo);
>>
>>
>
> One way I've worked around this is to inverse the filter and do the
> multicast in the otherwise() part but clearly this doesn't answer my
> original question:
>
> from(cnn).
>                choice().
>                when(xpath(filter)).to(stdout).
>                otherwise().multicast().to(im, archive);
>
> --
> View this message in context: http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Multicast with choice

by willem.jiang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The end() means to close the block, just like the "}" in java, it is
very useful for the choice() fluent API.

Willem

Louis Polycarpou wrote:

> Thanks. I'll try that.  The multicast fluent builder example
> http://activemq.apache.org/camel/multicast.html here   doesn't use end:
>
> from("direct:a").multicast().to("direct:x", "direct:y", "direct:z");
>
> What's the difference between:
>
>  multicast().to("direct:x", "direct:y", "direct:z").end();
>
> and
>
>  to("direct:x", "direct:y", "direct:z");
>
> Thanks.
>
> Hadrian Zbarcea wrote:
>  
>> Hi,
>>
>> Did you try end() to terminate the multicast?  As in:
>> from(uri).
>>    choice().
>>      when(expr).multicast().to(uris).end().
>>      otherwise().to(pojo);
>>
>> Cheers
>> Hadrian
>>
>>
>> On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:
>>
>>    
>>>
>>> Louis Polycarpou wrote:
>>>      
>>>> I'm trying to broadcast a feed to multiple endpoints but with
>>>> content-based selection. I assume I need to use multicast, however, I
>>>> can't achieve conditional multicast based on content selection  
>>>> since I
>>>> can't use an otherwise() method after using  
>>>> multicast().to("endpoint1",
>>>> "endpoint2")
>>>>
>>>> Furthermore, the to() method supports a list of endpoints without
>>>> requiring a multicast first so what is the difference between that  
>>>> and a
>>>> multicast().to(...)?
>>>>
>>>> feed in -> multicast to two outputs
>>>>
>>>> To recap with code:
>>>>
>>>> 1) I can't use otherwise after a multicast...
>>>>
>>>>        from(cnn).
>>>>                choice().
>>>>                when(xpath(filter)).multicast().to(im, archive); // I
>>>> can't now use otherwise()...
>>>>
>>>> 2) Do I really need multicast or can I just do the following...?
>>>>
>>>>        from(cnn).
>>>>                choice().
>>>>                when(xpath(filter)).to(im, archive).
>>>>                otherwise().to(myPojo);
>>>>
>>>>
>>>>        
>>> One way I've worked around this is to inverse the filter and do the
>>> multicast in the otherwise() part but clearly this doesn't answer my
>>> original question:
>>>
>>> from(cnn).
>>>                choice().
>>>                when(xpath(filter)).to(stdout).
>>>                otherwise().multicast().to(im, archive);
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>      
>>
>>    
>
>  


Re: Multicast with choice

by RomKal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure if end() will help (not in every case) as you could have
to cast to ChoiceType whatever is returned by end().

My solution to those problems was something like:

 from(cnn).
               choice().
               when(xpath(filter)).to(direct:subflow).otherwise().to(direct:something-else);


from(direct:subflow).multicast().to(im, archive);

This way you cannot hit any 'class type' problem in your DSL.

Sometimes it could be important to add in your subflow something like
errorhandler(noErrorHandler()) so it will not have its own error
handler.

Roman


2008/8/7 Willem Jiang <willem.jiang@...>:

> The end() means to close the block, just like the "}" in java, it is very
> useful for the choice() fluent API.
>
> Willem
>
> Louis Polycarpou wrote:
>>
>> Thanks. I'll try that.  The multicast fluent builder example
>> http://activemq.apache.org/camel/multicast.html here   doesn't use end:
>>
>> from("direct:a").multicast().to("direct:x", "direct:y", "direct:z");
>>
>> What's the difference between:
>>
>>  multicast().to("direct:x", "direct:y", "direct:z").end();
>> and
>>
>>  to("direct:x", "direct:y", "direct:z");
>>
>> Thanks.
>>
>> Hadrian Zbarcea wrote:
>>
>>>
>>> Hi,
>>>
>>> Did you try end() to terminate the multicast?  As in:
>>> from(uri).
>>>   choice().
>>>     when(expr).multicast().to(uris).end().
>>>     otherwise().to(pojo);
>>>
>>> Cheers
>>> Hadrian
>>>
>>>
>>> On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:
>>>
>>>
>>>>
>>>> Louis Polycarpou wrote:
>>>>
>>>>>
>>>>> I'm trying to broadcast a feed to multiple endpoints but with
>>>>> content-based selection. I assume I need to use multicast, however, I
>>>>> can't achieve conditional multicast based on content selection  since I
>>>>> can't use an otherwise() method after using
>>>>>  multicast().to("endpoint1",
>>>>> "endpoint2")
>>>>>
>>>>> Furthermore, the to() method supports a list of endpoints without
>>>>> requiring a multicast first so what is the difference between that  and
>>>>> a
>>>>> multicast().to(...)?
>>>>>
>>>>> feed in -> multicast to two outputs
>>>>>
>>>>> To recap with code:
>>>>>
>>>>> 1) I can't use otherwise after a multicast...
>>>>>
>>>>>       from(cnn).
>>>>>               choice().
>>>>>               when(xpath(filter)).multicast().to(im, archive); // I
>>>>> can't now use otherwise()...
>>>>>
>>>>> 2) Do I really need multicast or can I just do the following...?
>>>>>
>>>>>       from(cnn).
>>>>>               choice().
>>>>>               when(xpath(filter)).to(im, archive).
>>>>>               otherwise().to(myPojo);
>>>>>
>>>>>
>>>>>
>>>>
>>>> One way I've worked around this is to inverse the filter and do the
>>>> multicast in the otherwise() part but clearly this doesn't answer my
>>>> original question:
>>>>
>>>> from(cnn).
>>>>               choice().
>>>>               when(xpath(filter)).to(stdout).
>>>>               otherwise().multicast().to(im, archive);
>>>>
>>>> --
>>>> View this message in context:
>>>>
>>>> http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>>
>
>

Re: Multicast with choice

by Louis Polycarpou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

That won't work since otherwise() cannot follow end(). Not in Camel 1.3.0.

Louis

Hadrian Zbarcea wrote:
Hi,

Did you try end() to terminate the multicast?  As in:
from(uri).
   choice().
     when(expr).multicast().to(uris).end().
     otherwise().to(pojo);

Cheers
Hadrian


On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:

>
>
>
> Louis Polycarpou wrote:
>>
>> I'm trying to broadcast a feed to multiple endpoints but with
>> content-based selection. I assume I need to use multicast, however, I
>> can't achieve conditional multicast based on content selection  
>> since I
>> can't use an otherwise() method after using  
>> multicast().to("endpoint1",
>> "endpoint2")
>>
>> Furthermore, the to() method supports a list of endpoints without
>> requiring a multicast first so what is the difference between that  
>> and a
>> multicast().to(...)?
>>
>> feed in -> multicast to two outputs
>>
>> To recap with code:
>>
>> 1) I can't use otherwise after a multicast...
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).multicast().to(im, archive); // I
>> can't now use otherwise()...
>>
>> 2) Do I really need multicast or can I just do the following...?
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).to(im, archive).
>>                otherwise().to(myPojo);
>>
>>
>
> One way I've worked around this is to inverse the filter and do the
> multicast in the otherwise() part but clearly this doesn't answer my
> original question:
>
> from(cnn).
>                choice().
>                when(xpath(filter)).to(stdout).
>                otherwise().multicast().to(im, archive);
>
> --
> View this message in context: http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Multicast with choice

by davsclaus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

A bit late with the answer, but Camel uses Pipeline (pipes and filters EIP pattern) by default, when doing directly routing from -> to.

There is a FAQ entry here:
http://activemq.apache.org/camel/how-to-send-the-same-message-to-multiple-endpoints.html

Multicast = same message being sent to all destinations
Pipeline = like a chain (pipes and filters).
 
/Claus, a Camel rider



Thanks. I'll try that.  The multicast fluent builder example here  doesn't use end:

from("direct:a").multicast().to("direct:x", "direct:y", "direct:z");

What's the difference between:

 multicast().to("direct:x", "direct:y", "direct:z").end();

and

 to("direct:x", "direct:y", "direct:z");

Thanks.
Hadrian Zbarcea wrote:
Hi,

Did you try end() to terminate the multicast?  As in:
from(uri).
   choice().
     when(expr).multicast().to(uris).end().
     otherwise().to(pojo);

Cheers
Hadrian


On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:

>
>
>
> Louis Polycarpou wrote:
>>
>> I'm trying to broadcast a feed to multiple endpoints but with
>> content-based selection. I assume I need to use multicast, however, I
>> can't achieve conditional multicast based on content selection  
>> since I
>> can't use an otherwise() method after using  
>> multicast().to("endpoint1",
>> "endpoint2")
>>
>> Furthermore, the to() method supports a list of endpoints without
>> requiring a multicast first so what is the difference between that  
>> and a
>> multicast().to(...)?
>>
>> feed in -> multicast to two outputs
>>
>> To recap with code:
>>
>> 1) I can't use otherwise after a multicast...
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).multicast().to(im, archive); // I
>> can't now use otherwise()...
>>
>> 2) Do I really need multicast or can I just do the following...?
>>
>>        from(cnn).
>>                choice().
>>                when(xpath(filter)).to(im, archive).
>>                otherwise().to(myPojo);
>>
>>
>
> One way I've worked around this is to inverse the filter and do the
> multicast in the otherwise() part but clearly this doesn't answer my
> original question:
>
> from(cnn).
>                choice().
>                when(xpath(filter)).to(stdout).
>                otherwise().multicast().to(im, archive);
>
> --
> View this message in context: http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Multicast with choice

by hzbarcea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Louis, actually, there is no difference, end() is implicit.  There  
would be a difference if you had something like:

multicast
().to("direct:x").to("direct:y").to("direct:z").end().to("direct:a")

Without the end() they'd be all done in parallel, with end()  
"direct:a" is done after all the other exchanges finish.  The reason  
end() is optional is because Blocks were added a bit later (in 1.3  
iirc) and we wanted to keep backwards compatibility, i.e. not make  
end() mandatory and have existing users update their routes.

My $0.02,
Hadrian


On Nov 1, 2008, at 4:41 AM, davsclaus wrote:

>
> Hi
>
> A bit late with the answer, but Camel uses Pipeline (pipes and  
> filters EIP
> pattern) by default, when doing directly routing from -> to.
>
> There is a FAQ entry here:
> http://activemq.apache.org/camel/how-to-send-the-same-message-to-multiple-endpoints.html
>
> Multicast = same message being sent to all destinations
> Pipeline = like a chain (pipes and filters).
>
> /Claus, a Camel rider
>
>
>
> Louis Polycarpou wrote:
>>
>> Thanks. I'll try that.  The multicast fluent builder example
>> http://activemq.apache.org/camel/multicast.html here   doesn't use  
>> end:
>>
>> from("direct:a").multicast().to("direct:x", "direct:y", "direct:z");
>>
>> What's the difference between:
>>
>> multicast().to("direct:x", "direct:y", "direct:z").end();
>>
>> and
>>
>> to("direct:x", "direct:y", "direct:z");
>>
>> Thanks.
>>
>> Hadrian Zbarcea wrote:
>>>
>>> Hi,
>>>
>>> Did you try end() to terminate the multicast?  As in:
>>> from(uri).
>>>   choice().
>>>     when(expr).multicast().to(uris).end().
>>>     otherwise().to(pojo);
>>>
>>> Cheers
>>> Hadrian
>>>
>>>
>>> On Aug 6, 2008, at 8:28 PM, Louis Polycarpou wrote:
>>>
>>>>
>>>>
>>>>
>>>> Louis Polycarpou wrote:
>>>>>
>>>>> I'm trying to broadcast a feed to multiple endpoints but with
>>>>> content-based selection. I assume I need to use multicast,  
>>>>> however, I
>>>>> can't achieve conditional multicast based on content selection
>>>>> since I
>>>>> can't use an otherwise() method after using
>>>>> multicast().to("endpoint1",
>>>>> "endpoint2")
>>>>>
>>>>> Furthermore, the to() method supports a list of endpoints without
>>>>> requiring a multicast first so what is the difference between that
>>>>> and a
>>>>> multicast().to(...)?
>>>>>
>>>>> feed in -> multicast to two outputs
>>>>>
>>>>> To recap with code:
>>>>>
>>>>> 1) I can't use otherwise after a multicast...
>>>>>
>>>>>       from(cnn).
>>>>>               choice().
>>>>>               when(xpath(filter)).multicast().to(im,  
>>>>> archive); // I
>>>>> can't now use otherwise()...
>>>>>
>>>>> 2) Do I really need multicast or can I just do the following...?
>>>>>
>>>>>       from(cnn).
>>>>>               choice().
>>>>>               when(xpath(filter)).to(im, archive).
>>>>>               otherwise().to(myPojo);
>>>>>
>>>>>
>>>>
>>>> One way I've worked around this is to inverse the filter and do the
>>>> multicast in the otherwise() part but clearly this doesn't answer  
>>>> my
>>>> original question:
>>>>
>>>> from(cnn).
>>>>               choice().
>>>>               when(xpath(filter)).to(stdout).
>>>>               otherwise().multicast().to(im, archive);
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Multicast-with-choice-tp18861976s22882p18862033.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Multicast-with-choice-tp18861976s22882p20278430.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Need professional support or training for Apache Camel? Graphic Design by Hiram and the Nabble Forum configured by James