You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Franklin Antony <fr...@gmail.com> on 2008/12/03 19:52:25 UTC

Apache Camel and calling Spring Business Services

Dear All,
  I recently started to use Camel for integration purposes. I am very much
confused as to where the Spring business services have to be injected into
Camel. Are they usually injected into RouteBuilder? 

I have a use case currently where I listen to a directory for new files.
Then I get the file, rename it and move the file into another directory with
the new name. During this process I log the old and new file names into the
database.

This is where problem starts. I have a Spring business service thats does
the logging for me. I am not sure where and how to inject the business
service. Also what is the best practice to place the service. Again how is
it possible to pass the new and old file names to this service ?


 from("file://C://test//from").process(new Processor() {

                    public void process(Exchange e) {
                       //Should the Spring business service for logging to
DB be called here ??
                   }
                }).to("file://C://test//to");

I really don't prefer this . Just feels like the routebuilder is doing more
that what its supposed to do.

>From how much I have used Camel,I am so much happy I am using it now :-D .
But I still am getting confused as to where the Spring business services
should be. I would really appreciate if the gurus of Camel can help me out
on this.

Thanks,
Franklin
-- 
View this message in context: http://www.nabble.com/Apache-Camel-and-calling-Spring-Business-Services-tp20819198s22882p20819198.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Apache Camel and calling Spring Business Services

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

The file component supports moving files after processing using native
File.rename method. What you have in your route is a ending file
producer that writes a new file.
So if you want to move the file after the route completes you can do it as:

> --from("file://C://test//from").bean(MyClass,
> --"myMethod")

Notice the last file is gone. Now we need to instruct the first file
where it should move the file and what name it should be.
http://activemq.apache.org/camel/file.html

You can use the expression option to allow a bean to generate the
name. This expressions uses the file language
http://activemq.apache.org/camel/file-language.html


> --from("file://C://test//from?expression=myFileNameGeneratorBean").bean(MyClass,
> --"myMethod")

See the links ad they have samples.


/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Wed, Dec 3, 2008 at 8:44 PM, Franklin Antony
<fr...@gmail.com> wrote:
>
> Thanks a lot.
> Just some more things.. Where exactly has the spring services need to be
> called or injected ?
>
> Also assume in this route
>
> --from("file://C://test//from").bean(MyClass,
> --"myMethod").to("file://C://test//to");
>
> Assume MyClass having myMethod can log to the database , since the message
> payload is received in MyClass. Now myMethod generates a Random Unique name
> for the file and log it into the database.
>
> How can the output (file://c://test/to) directory know what is the new name
> of the file ?
>
>
> Thanks,
> Franklin
>
>
>
> --
> View this message in context: http://www.nabble.com/Apache-Camel-and-calling-Spring-Business-Services-tp20819198s22882p20820119.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: Apache Camel and calling Spring Business Services

Posted by James Strachan <ja...@gmail.com>.
2008/12/3 Franklin Antony <fr...@gmail.com>:
>
> Thanks a lot.
> Just some more things.. Where exactly has the spring services need to be
> called or injected ?

You can pop them in your Spring XML or Java Config. If you prefer you
can use beanRef(String beanName) to refer to named bean in Spring /
JNDI etc.


> Also assume in this route
>
> --from("file://C://test//from").bean(MyClass,
> --"myMethod").to("file://C://test//to");
>
> Assume MyClass having myMethod can log to the database , since the message
> payload is received in MyClass. Now myMethod generates a Random Unique name
> for the file and log it into the database.
>
> How can the output (file://c://test/to) directory know what is the new name
> of the file ?

See the file endpoint for the headers you can specify to customize its
behaviour...
http://activemq.apache.org/camel/file.html

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Apache Camel and calling Spring Business Services

Posted by Franklin Antony <fr...@gmail.com>.
Thanks a lot.
Just some more things.. Where exactly has the spring services need to be
called or injected ?

Also assume in this route

--from("file://C://test//from").bean(MyClass,
--"myMethod").to("file://C://test//to");

Assume MyClass having myMethod can log to the database , since the message
payload is received in MyClass. Now myMethod generates a Random Unique name
for the file and log it into the database.

How can the output (file://c://test/to) directory know what is the new name
of the file ?


Thanks,
Franklin



-- 
View this message in context: http://www.nabble.com/Apache-Camel-and-calling-Spring-Business-Services-tp20819198s22882p20820119.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Apache Camel and calling Spring Business Services

Posted by James Strachan <ja...@gmail.com>.
2008/12/3 Franklin Antony <fr...@gmail.com>:
>
> Dear All,
>  I recently started to use Camel for integration purposes. I am very much
> confused as to where the Spring business services have to be injected into
> Camel. Are they usually injected into RouteBuilder?

These documents are worth a browse...
http://activemq.apache.org/camel/bean-integration.html

in particular this describes how we invoke a bean inside a route
http://activemq.apache.org/camel/bean-binding.html


you can either use it inside a route...

from("jms:someQueue").bean(MyBean.class, "myMethodName");

or using the @Consume annotation
http://activemq.apache.org/camel/pojo-consuming.html

> I have a use case currently where I listen to a directory for new files.
> Then I get the file, rename it and move the file into another directory with
> the new name. During this process I log the old and new file names into the
> database.
>
> This is where problem starts. I have a Spring business service thats does
> the logging for me. I am not sure where and how to inject the business
> service. Also what is the best practice to place the service. Again how is
> it possible to pass the new and old file names to this service ?
>
>
>  from("file://C://test//from").process(new Processor() {
>
>                    public void process(Exchange e) {
>                       //Should the Spring business service for logging to
> DB be called here ??
>                   }
>                }).to("file://C://test//to");
>
> I really don't prefer this . Just feels like the routebuilder is doing more
> that what its supposed to do.
>
> From how much I have used Camel,I am so much happy I am using it now :-D .


from("file://C://test//from").bean(MyClass,
"myMethod").to("file://C://test//to");

You can omit "myMethod" and Camel will probably do the right thing but
it doesn't do any harm to be totally explicit.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/