You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Felix Thomas <fe...@gmail.com> on 2015/08/02 14:05:42 UTC

Some Stupid Questions

Hello,

    I had some doubts so I thought the forum is the best way to get some
answers.

  1) Since I am using XML DSL earlier Java DSL.
    I have a Bean defined like below. Currently the Constructor is passed.
But How do I make it dynamic i.e. decide based on the route which argument
to pass. Do I need to make always different bean entry for each argument to
pass.

   <bean id="CustomProcessorDB"
class="com.worldline.frida.camel.core.CustomProcessor">
     <constructor-arg value="DB"/>
   </bean>

In java I could write  process(new CustomProcessor(CustomConstants.CSV))
Can I do the same in XML.


 2) Threading :- If I have declared a Bean as above and if I use it in a
SPLIT in Parallel processing mode using a Thread profile. Will Camel also
create a Pool of the bean and pass it for each thread. i.e. if my Pool size
is 5 will  camel create 5 instance of the bean class and use it in the
processing automatically.  I want to know if it will be thread safe for
each bean object.


3) Database component :-  If i am getting billions of data from a DB using
a timer component consumer is there any feature that I can mark some column
with some flag stating it has been processed .

I saw in the SQL Component there are some option like consumer.onConsume
etc. but is there something similar in JDBC component .  Other approach is
to move some records to a temporary table and use that but still some flag
has to be done on the Original table which is being updated every moment.

4) Performance :-  Is keeping a separate Camelcontext for each route a best
approach, or only if there a lot of traffic of messages then you should
consider separation.
    How does camel work incase if you host multiple camelcontext on same
machine and same JVM,

Rgds
Felix

Re: Some Stupid Questions

Posted by Claus Ibsen <cl...@gmail.com>.
See the cache option on the bean component

On Tue, Aug 4, 2015 at 9:33 PM, Christian Müller
<ch...@gmail.com> wrote:
> It will create a new instance for each call to the registry. But if you
> inject this bean to another bean (which has the singleton scope), than
> there is only one instance of this bean.
> A workaround could be to call the registry by yourself to get a fresh copy
> of this bean.
> The solution is to make your bean thread safe. What kind of state do you
> have to maintain?
>
> Best,
> Christian
> -----------------
>
> Software Integration Specialist
>
> Apache Member
> V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
> Apache Incubator PMC Member
>
> https://www.linkedin.com/pub/christian-mueller/11/551/642
>
> On Tue, Aug 4, 2015 at 1:40 PM, fxthomas <fe...@gmail.com> wrote:
>
>> Thanks for your answers I will try them out whatever possible.
>>
>> I tried the Below things too.
>>
>> 1) I checked the bean construction the saw that it being created only once
>> so i change the bean defination to below
>>
>> <bean id="CustomProcessorCSV" class="com.XXXX.CustomProcessor"
>> scope="prototype">
>>       <constructor-arg value="CSV"/>
>>     </bean
>>
>> But still I see only one Instance being created on the Logs, isn',t scope
>> prototype supposed to return from registry a new instance so in turn it
>> should create multiple instance of the bean. Hope my understanding  is okay
>> ?
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Some-Stupid-Questions-tp5770217p5770275.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition: http://www.manning.com/ibsen2

Re: Some Stupid Questions

Posted by Christian Müller <ch...@gmail.com>.
It will create a new instance for each call to the registry. But if you
inject this bean to another bean (which has the singleton scope), than
there is only one instance of this bean.
A workaround could be to call the registry by yourself to get a fresh copy
of this bean.
The solution is to make your bean thread safe. What kind of state do you
have to maintain?

Best,
Christian
-----------------

Software Integration Specialist

Apache Member
V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
Apache Incubator PMC Member

https://www.linkedin.com/pub/christian-mueller/11/551/642

On Tue, Aug 4, 2015 at 1:40 PM, fxthomas <fe...@gmail.com> wrote:

> Thanks for your answers I will try them out whatever possible.
>
> I tried the Below things too.
>
> 1) I checked the bean construction the saw that it being created only once
> so i change the bean defination to below
>
> <bean id="CustomProcessorCSV" class="com.XXXX.CustomProcessor"
> scope="prototype">
>       <constructor-arg value="CSV"/>
>     </bean
>
> But still I see only one Instance being created on the Logs, isn',t scope
> prototype supposed to return from registry a new instance so in turn it
> should create multiple instance of the bean. Hope my understanding  is okay
> ?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Some-Stupid-Questions-tp5770217p5770275.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Some Stupid Questions

Posted by fxthomas <fe...@gmail.com>.
Thanks for your answers I will try them out whatever possible.  

I tried the Below things too. 

1) I checked the bean construction the saw that it being created only once
so i change the bean defination to below

<bean id="CustomProcessorCSV" class="com.XXXX.CustomProcessor"
scope="prototype">
      <constructor-arg value="CSV"/>
    </bean

But still I see only one Instance being created on the Logs, isn',t scope
prototype supposed to return from registry a new instance so in turn it
should create multiple instance of the bean. Hope my understanding  is okay
?



--
View this message in context: http://camel.465427.n5.nabble.com/Some-Stupid-Questions-tp5770217p5770275.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Some Stupid Questions

Posted by Raul Kripalani <ra...@evosent.com>.
On 2 Aug 2015 13:05, "Felix Thomas" <fe...@gmail.com> wrote:

>  2) Threading :- If I have declared a Bean as above and if I use it in a
> SPLIT in Parallel processing mode using a Thread profile. Will Camel also
> create a Pool of the bean and pass it for each thread. i.e. if my Pool
size
> is 5 will  camel create 5 instance of the bean class and use it in the
> processing automatically.  I want to know if it will be thread safe for
> each bean object.

Camel will not build the bean, but it will request it to the registry. So
it's up to the registry to return a new instance or a singleton. In Spring,
you can configure this with the 'scope' attribute.

I suggest you give it a spin with printlns so you can understand when the
new instances are created.

By default, all registries (Spring, Blueprint, Simple Java) return
singletons.

>
> 3) Database component :-  If i am getting billions of data from a DB using
> a timer component consumer is there any feature that I can mark some
column
> with some flag stating it has been processed .
>
> I saw in the SQL Component there are some option like consumer.onConsume
> etc. but is there something similar in JDBC component .  Other approach is
> to move some records to a temporary table and use that but still some flag
> has to be done on the Original table which is being updated every moment.

I suggest you add a WHERE condition to filter out records that do not have
this flag, and use an onCompletion with onCompleteOnly, in sync mode and
BeforeConsumer, in order to set the flag on the record(s) before the route
is done processing.

Re: Some Stupid Questions

Posted by Minh Tran <da...@gmail.com>.
On 02/08/2015, at 10:05 PM, Felix Thomas <fe...@gmail.com> wrote:

> Hello,
> 
>    I had some doubts so I thought the forum is the best way to get some
> answers.
> 
>  1) Since I am using XML DSL earlier Java DSL.
>    I have a Bean defined like below. Currently the Constructor is passed.
> But How do I make it dynamic i.e. decide based on the route which argument
> to pass. Do I need to make always different bean entry for each argument to
> pass.
> 
>   <bean id="CustomProcessorDB"
> class="com.worldline.frida.camel.core.CustomProcessor">
>     <constructor-arg value="DB"/>
>   </bean>
> 
> In java I could write  process(new CustomProcessor(CustomConstants.CSV))
> Can I do the same in XML.
> 
> 

You can refactor your processor so instead of taking the argument on construction, you can have a method that takes that argument. Then simply pass this argument using a header inside camel. If you do not wish to or cannot change your existing code, you could always implement a factory to return the correct processor.


Re: Some Stupid Questions

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

> Is keeping a separate Camelcontext for each route a
> best approach, or only if there a lot of traffic of messages then
> you should consider separation.

The number if the contexts you have doesn't really affects the performance.
The number of contexts is rather related to the architecture of your
application. For example for the OSGi it makes sense to have the context
per bundle (this is what Camel Karaf does) as you would like to deploy new
contexts at runtime without affecting the existing flows. But for fat
jar application, the more natural approach would be to have a single
context (this is what Camel Spring Boot does).

Cheers!

niedz., 2.08.2015 o 14:05 użytkownik Felix Thomas <fe...@gmail.com>
napisał:

> Hello,
>
>     I had some doubts so I thought the forum is the best way to get some
> answers.
>
>   1) Since I am using XML DSL earlier Java DSL.
>     I have a Bean defined like below. Currently the Constructor is passed.
> But How do I make it dynamic i.e. decide based on the route which argument
> to pass. Do I need to make always different bean entry for each argument to
> pass.
>
>    <bean id="CustomProcessorDB"
> class="com.worldline.frida.camel.core.CustomProcessor">
>      <constructor-arg value="DB"/>
>    </bean>
>
> In java I could write  process(new CustomProcessor(CustomConstants.CSV))
> Can I do the same in XML.
>
>
>  2) Threading :- If I have declared a Bean as above and if I use it in a
> SPLIT in Parallel processing mode using a Thread profile. Will Camel also
> create a Pool of the bean and pass it for each thread. i.e. if my Pool size
> is 5 will  camel create 5 instance of the bean class and use it in the
> processing automatically.  I want to know if it will be thread safe for
> each bean object.
>
>
> 3) Database component :-  If i am getting billions of data from a DB using
> a timer component consumer is there any feature that I can mark some column
> with some flag stating it has been processed .
>
> I saw in the SQL Component there are some option like consumer.onConsume
> etc. but is there something similar in JDBC component .  Other approach is
> to move some records to a temporary table and use that but still some flag
> has to be done on the Original table which is being updated every moment.
>
> 4) Performance :-  Is keeping a separate Camelcontext for each route a best
> approach, or only if there a lot of traffic of messages then you should
> consider separation.
>     How does camel work incase if you host multiple camelcontext on same
> machine and same JVM,
>
> Rgds
> Felix
>