You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by DaHoopster <hw...@structuralinvest.com> on 2010/04/29 03:44:39 UTC

Question on splitter

Hi,

I am having trouble using the splitter. I think it's a very simple problem
but I just can't figure what. I have tried a couple of way to split but no
luck. Here is what I have:

Method 1:
=====================================================================
route config:

        from("activemq:queue:inputQueue?jmsMessageType=Object").
                to("customSorter").
                split(body()).
                to("activemq:queue:outputQueue?jmsMessageType=Text");

My customerSorter code:

the object.getNumbers returns a list of MyNumber object

    public void process(Exchange exchange) throws Exception
    {
        final MyObject object = exchange.getIn().getBody(MyObject.class);
        final MyObject sorted = sort(object);
        exchange.getIn().setBody(object.getNumbers());
    }

For some reason, I am not getting anything on the output queue.


Method 2:
=====================================================================

Route config:

        from("activemq:queue:inputQueue?jmsMessageType=Object").
                to("customSorter").
                split(new MySplitExpression()).
                to("activemq:queue:outputQueue?jmsMessageType=Text");

MySplitExpression:

    public <T> T evaluate(final Exchange exchange, final Class<T> tClass)
    {
        final MyObject myObject =
exchange.getIn().copy().getBody(MyObject.class);
        final List<Message> answer = new LinkedList<Message>();
        for (final MyNumber myNumber : inventory.getNumbers())
        {
            final Message answerMessage = exchange.getIn().copy();
            answerMessage.setBody(myNumber, MyNumber.class);
            System.out.println("=== splitting ===");
        }
        return (T) answer;
    }

I am seeing the message being printed out but I still don't have any
messages on the output queue.

Could you help me see what's going on here?

Thanks,
Han
-- 
View this message in context: http://old.nabble.com/Question-on-splitter-tp28395839p28395839.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Question on splitter

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Apr 29, 2010 at 5:54 AM, DaHoopster <hw...@structuralinvest.com> wrote:
>
> Thanks for the reply Ashwin.
>
> No, MyObject is not  serializable but it's annotated with XML annotations.
> We are marshaling the object into XML messages and putting XML messages onto
> the queues.
>
> The examples on the page you gave me don't work because the syntax are not
> the same as the version of camel I am using, which is 2.2.6. So given that
> we are using XML messages, is there a quick solution to the problem?
>

The splitter wiki page have an XML based example using XPath.

> Here is what the message look like:
> <MyObject>
>  <MyNumbers>
>    <MyNumber>blaM/MyNumber>
>    <MyNumber>blaM/MyNumber>
>    <MyNumber>blaM/MyNumber>
>    <MyNumber>blaM/MyNumber>
>  </MyNumbers>
> </MyObject>
>

You may use an xpath expression, something like
    split(xpath("/MyObject/MyNumbers/MyNumber/text")).


>
> Thanks,
> Han
>
>
> Ashwin Karpe wrote:
>>
>> Hi,
>>
>> First of all, I assume that the MyObject class is serializable.
>>
>> Please check out the section "Using a Pojo to do the splitting" at the
>> link
>>  http://camel.apache.org/splitter.html
>> http://camel.apache.org/splitter.html
>>
>> There is a very good and straightforward example that can do the trick for
>> you.
>>
>> What you need is to to take the object, split its payload, create a list
>> of items and allow the splitter to take it from there.
>>
>> Cheers,
>>
>> Ashwin...
>>
>>
>>
>> DaHoopster wrote:
>>>
>>> Hi,
>>>
>>> I am having trouble using the splitter. I think it's a very simple
>>> problem but I just can't figure what. I have tried a couple of way to
>>> split but no luck. Here is what I have:
>>>
>>> Method 1:
>>> =====================================================================
>>> route config:
>>>
>>>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>>>                 to("customSorter").
>>>                 split(body()).
>>>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
>>>
>>> My customerSorter code:
>>>
>>> the object.getNumbers returns a list of MyNumber object
>>>
>>>     public void process(Exchange exchange) throws Exception
>>>     {
>>>         final MyObject object = exchange.getIn().getBody(MyObject.class);
>>>         final MyObject sorted = sort(object);
>>>         exchange.getIn().setBody(object.getNumbers());
>>>     }
>>>
>>> For some reason, I am not getting anything on the output queue.
>>>
>>>
>>> Method 2:
>>> =====================================================================
>>>
>>> Route config:
>>>
>>>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>>>                 to("customSorter").
>>>                 split(new MySplitExpression()).
>>>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
>>>
>>> MySplitExpression:
>>>
>>>     public <T> T evaluate(final Exchange exchange, final Class<T> tClass)
>>>     {
>>>         final MyObject myObject =
>>> exchange.getIn().copy().getBody(MyObject.class);
>>>         final List<Message> answer = new LinkedList<Message>();
>>>         for (final MyNumber myNumber : inventory.getNumbers())
>>>         {
>>>             final Message answerMessage = exchange.getIn().copy();
>>>             answerMessage.setBody(myNumber, MyNumber.class);
>>>             System.out.println("=== splitting ===");
>>>         }
>>>         return (T) answer;
>>>     }
>>>
>>> I am seeing the message being printed out but I still don't have any
>>> messages on the output queue.
>>>
>>> Could you help me see what's going on here?
>>>
>>> Thanks,
>>> Han
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Question-on-splitter-tp28395839p28396442.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Question on splitter

Posted by DaHoopster <hw...@structuralinvest.com>.
Thanks for the reply Ashwin.

No, MyObject is not  serializable but it's annotated with XML annotations.
We are marshaling the object into XML messages and putting XML messages onto
the queues.

The examples on the page you gave me don't work because the syntax are not
the same as the version of camel I am using, which is 2.2.6. So given that
we are using XML messages, is there a quick solution to the problem? 

Here is what the message look like:
<MyObject>
  <MyNumbers>
    <MyNumber>blaM/MyNumber>
    <MyNumber>blaM/MyNumber>
    <MyNumber>blaM/MyNumber>
    <MyNumber>blaM/MyNumber>
  </MyNumbers>
</MyObject>


Thanks,
Han


Ashwin Karpe wrote:
> 
> Hi,
> 
> First of all, I assume that the MyObject class is serializable.
> 
> Please check out the section "Using a Pojo to do the splitting" at the
> link 
>  http://camel.apache.org/splitter.html
> http://camel.apache.org/splitter.html 
> 
> There is a very good and straightforward example that can do the trick for
> you. 
> 
> What you need is to to take the object, split its payload, create a list
> of items and allow the splitter to take it from there.
> 
> Cheers,
> 
> Ashwin... 
> 
> 
> 
> DaHoopster wrote:
>> 
>> Hi,
>> 
>> I am having trouble using the splitter. I think it's a very simple
>> problem but I just can't figure what. I have tried a couple of way to
>> split but no luck. Here is what I have:
>> 
>> Method 1:
>> =====================================================================
>> route config:
>> 
>>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>>                 to("customSorter").
>>                 split(body()).
>>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
>> 
>> My customerSorter code:
>> 
>> the object.getNumbers returns a list of MyNumber object
>> 
>>     public void process(Exchange exchange) throws Exception
>>     {
>>         final MyObject object = exchange.getIn().getBody(MyObject.class);
>>         final MyObject sorted = sort(object);
>>         exchange.getIn().setBody(object.getNumbers());
>>     }
>> 
>> For some reason, I am not getting anything on the output queue.
>> 
>> 
>> Method 2:
>> =====================================================================
>> 
>> Route config:
>> 
>>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>>                 to("customSorter").
>>                 split(new MySplitExpression()).
>>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
>> 
>> MySplitExpression:
>> 
>>     public <T> T evaluate(final Exchange exchange, final Class<T> tClass)
>>     {
>>         final MyObject myObject =
>> exchange.getIn().copy().getBody(MyObject.class);
>>         final List<Message> answer = new LinkedList<Message>();
>>         for (final MyNumber myNumber : inventory.getNumbers())
>>         {
>>             final Message answerMessage = exchange.getIn().copy();
>>             answerMessage.setBody(myNumber, MyNumber.class);
>>             System.out.println("=== splitting ===");
>>         }
>>         return (T) answer;
>>     }
>> 
>> I am seeing the message being printed out but I still don't have any
>> messages on the output queue.
>> 
>> Could you help me see what's going on here?
>> 
>> Thanks,
>> Han
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Question-on-splitter-tp28395839p28396442.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Question on splitter

Posted by Ashwin Karpe <as...@progress.com>.
Hi,

First of all, I assume that the MyObject class is serializable.

Please check out the section "Using a Pojo to do the splitting" at the link 
http://camel.apache.org/splitter.html http://camel.apache.org/splitter.html 

There is a very good and straightforward example that can do the trick for
you. 

What you need is to to take the object, split its payload, create a list of
items and allow the splitter to take it from there.

Cheers,

Ashwin... 



DaHoopster wrote:
> 
> Hi,
> 
> I am having trouble using the splitter. I think it's a very simple problem
> but I just can't figure what. I have tried a couple of way to split but no
> luck. Here is what I have:
> 
> Method 1:
> =====================================================================
> route config:
> 
>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>                 to("customSorter").
>                 split(body()).
>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
> 
> My customerSorter code:
> 
> the object.getNumbers returns a list of MyNumber object
> 
>     public void process(Exchange exchange) throws Exception
>     {
>         final MyObject object = exchange.getIn().getBody(MyObject.class);
>         final MyObject sorted = sort(object);
>         exchange.getIn().setBody(object.getNumbers());
>     }
> 
> For some reason, I am not getting anything on the output queue.
> 
> 
> Method 2:
> =====================================================================
> 
> Route config:
> 
>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>                 to("customSorter").
>                 split(new MySplitExpression()).
>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
> 
> MySplitExpression:
> 
>     public <T> T evaluate(final Exchange exchange, final Class<T> tClass)
>     {
>         final MyObject myObject =
> exchange.getIn().copy().getBody(MyObject.class);
>         final List<Message> answer = new LinkedList<Message>();
>         for (final MyNumber myNumber : inventory.getNumbers())
>         {
>             final Message answerMessage = exchange.getIn().copy();
>             answerMessage.setBody(myNumber, MyNumber.class);
>             System.out.println("=== splitting ===");
>         }
>         return (T) answer;
>     }
> 
> I am seeing the message being printed out but I still don't have any
> messages on the output queue.
> 
> Could you help me see what's going on here?
> 
> Thanks,
> Han
> 


-----
--- 
Ashwin Karpe, Sr. Principal Consultant, PS - Opensource Center of Competence 
Progress Software Corporation
14 Oak Park Drive
Bedford, MA 01730
--- 
+1-972-304-9084 (Office) 
+1-972-971-1700 (Mobile) 
---- 
Blog: http://opensourceknowledge.blogspot.com/


-- 
View this message in context: http://old.nabble.com/Question-on-splitter-tp28395839p28396190.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Question on splitter

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

Please check out my comments in the mail.

DaHoopster wrote:
> Hi,
> 
> I am having trouble using the splitter. I think it's a very simple problem
> but I just can't figure what. I have tried a couple of way to split but no
> luck. Here is what I have:
> 
> Method 1:
> =====================================================================
> route config:
> 
>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>                 to("customSorter").
>                 split(body()).
>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
> 
> My customerSorter code:
> 
> the object.getNumbers returns a list of MyNumber object
> 
>     public void process(Exchange exchange) throws Exception
>     {
>         final MyObject object = exchange.getIn().getBody(MyObject.class);
>         final MyObject sorted = sort(object);
>         exchange.getIn().setBody(object.getNumbers());
>     }
> 
> For some reason, I am not getting anything on the output queue.

I don't think camel know how to split the getNumbers of object.

> 
> 
> Method 2:
> =====================================================================
> 
> Route config:
> 
>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>                 to("customSorter").
>                 split(new MySplitExpression()).
>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
> 
> MySplitExpression:
> 
>     public <T> T evaluate(final Exchange exchange, final Class<T> tClass)
>     {
>         final MyObject myObject =
> exchange.getIn().copy().getBody(MyObject.class);
>         final List<Message> answer = new LinkedList<Message>();
>         for (final MyNumber myNumber : inventory.getNumbers())
>         {
>             final Message answerMessage = exchange.getIn().copy();
>             answerMessage.setBody(myNumber, MyNumber.class);
>             System.out.println("=== splitting ===");

You didn't put the message into the answer list.

>         }
>         return (T) answer;
>     }
> 
> I am seeing the message being printed out but I still don't have any
> messages on the output queue.
> 
> Could you help me see what's going on here?
> 
> Thanks,
> Han

Willem