You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by rifazjeoffrey <rj...@upcontractor.up.com> on 2012/01/11 20:26:51 UTC

Pass variable to mybatis component

I've my route like this,

<route id="mb-database-poller">
			<from
			
uri="mybatis-comm:fetchMessagesReadyForDelivery?statementType=SelectList&amp;delay=1000&amp;consumer.useIterator=false&amp;maxMessagesPerPoll=100"
/>

			<bean ref="inboundTransportDocumentConverter" method="updateStatus" />

			<split>
  			 	<simple>${in.body}</simple>
				<bean ref="inboundTransportDocumentConverter"
method="constructMessageFromDatabase" />
                <to uri="direct:inboundEndpoint" />
            </split>

		</route>

As you can see I'm using the mybatis component as a poller.

NOw, how can I pass in a variable to 'fetchMessagesReadyForDelivery' method
? This will help me pass in different value to the method without having to
re-write similar DAO methods. I've just one variable(parameter) that this
method expects

Thanks,
Jeoffrey

--
View this message in context: http://camel.465427.n5.nabble.com/Pass-variable-to-mybatis-component-tp5137772p5137772.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Pass variable to mybatis component

Posted by Christian Müller <ch...@gmail.com>.
It looks like the Timer component [1] is sufficient for you. Use the option
"fixedRate=false" (the default option).

[1] http://camel.apache.org/timer.html

Best,
Christian

On Thu, Jan 12, 2012 at 10:10 PM, rifazjeoffrey <
rjeoffre@upcontractor.up.com> wrote:

> We purely use Spring based routing so that option is out.
>
> As a side effect of using timer, I observed this.....suppose the 'period'
> of
> firing is 1sec and if that thread takes 10secs to complete its job. Right
> after this thread is done, I see all the other 10 firings of the same timer
> happen almost back-to-back (because the 10 tries didn't get a chance
> because
> of blocking call by first try).
>
> Is there a way to stop this behavior ?
>
> Hope you understood my question !
>
> Jeff
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Pass-variable-to-mybatis-component-tp5137772p5141007.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Pass variable to mybatis component

Posted by rifazjeoffrey <rj...@upcontractor.up.com>.
We purely use Spring based routing so that option is out.

As a side effect of using timer, I observed this.....suppose the 'period' of
firing is 1sec and if that thread takes 10secs to complete its job. Right
after this thread is done, I see all the other 10 firings of the same timer
happen almost back-to-back (because the 10 tries didn't get a chance because
of blocking call by first try).

Is there a way to stop this behavior ?

Hope you understood my question !

Jeff

--
View this message in context: http://camel.465427.n5.nabble.com/Pass-variable-to-mybatis-component-tp5137772p5141007.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Pass variable to mybatis component

Posted by Christian Müller <ch...@gmail.com>.
You can use the Java DSL instead the XML DSL and in the configure() method
you have to implement you can loop and create as many similar routes you
need.

Best,
Christian

On Thu, Jan 12, 2012 at 8:02 PM, rifazjeoffrey <rjeoffre@upcontractor.up.com
> wrote:

> Thanks....that worked...this is my final route,
>
> <route id="mb-database-poller">
>                        <from
> uri="timer://InbdPoller?fixedRate=true&amp;period=5s"/>
>                        <setBody>
>                                <constant>1</constant>
>                        </setBody>
>                        <to
>
>
> uri="mybatis-comm:fetchMessagesReadyForDelivery?statementType=SelectList&amp;consumer.useIterator=false&amp;maxMessagesPerPoll=100"
> />
>
>                        <bean ref="inboundTransportDocumentConverter"
> method="updateStatus" />
>
>                        <split>
>                                <simple>${in.body}</simple>
>                                <bean
> ref="inboundTransportDocumentConverter"
> method="constructMessageFromDatabase" />
>                <to uri="direct:inboundEndpoint" />
>            </split>
>
>                </route>
>
> Here comes another question, we actually need to run multiple database
> poller (like the one above) which means, as far I know, I need to duplicate
> the above route to as many times I want and just the value of the
> 'constant'
> on every poller.
>
> Is there a way I can avoid creating routes which are going to look similar
> ?
>
> I solved that issue on DAO side based on your suggestions.
>
> ANy help will reduce route duplication !
>
> Thanks,
> Jeff
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Pass-variable-to-mybatis-component-tp5137772p5140746.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Pass variable to mybatis component

Posted by rifazjeoffrey <rj...@upcontractor.up.com>.
Thanks....that worked...this is my final route,

<route id="mb-database-poller">
			<from uri="timer://InbdPoller?fixedRate=true&amp;period=5s"/>
			<setBody>
				<constant>1</constant>
			</setBody>
			<to
			
uri="mybatis-comm:fetchMessagesReadyForDelivery?statementType=SelectList&amp;consumer.useIterator=false&amp;maxMessagesPerPoll=100"
/>

			<bean ref="inboundTransportDocumentConverter" method="updateStatus" />

			<split>
  			 	<simple>${in.body}</simple>
				<bean ref="inboundTransportDocumentConverter"
method="constructMessageFromDatabase" />
                <to uri="direct:inboundEndpoint" />
            </split>

		</route>

Here comes another question, we actually need to run multiple database
poller (like the one above) which means, as far I know, I need to duplicate
the above route to as many times I want and just the value of the 'constant'
on every poller.

Is there a way I can avoid creating routes which are going to look similar ? 

I solved that issue on DAO side based on your suggestions.

ANy help will reduce route duplication !

Thanks,
Jeff

--
View this message in context: http://camel.465427.n5.nabble.com/Pass-variable-to-mybatis-component-tp5137772p5140746.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Pass variable to mybatis component

Posted by Christian Müller <ch...@gmail.com>.
Could this solve your problem?

from("timer:xxx?yyy")
  .bean("yourEnricher")
  .to("mybatis:statement?zzz");

or

from("quartz:xxx?yyy")
  .bean("yourEnricher")
  .to("mybatis:statement?zzz");

Best,
Christian

On Wed, Jan 11, 2012 at 8:26 PM, rifazjeoffrey <rjeoffre@upcontractor.up.com
> wrote:

> I've my route like this,
>
> <route id="mb-database-poller">
>                        <from
>
>
> uri="mybatis-comm:fetchMessagesReadyForDelivery?statementType=SelectList&amp;delay=1000&amp;consumer.useIterator=false&amp;maxMessagesPerPoll=100"
> />
>
>                        <bean ref="inboundTransportDocumentConverter"
> method="updateStatus" />
>
>                        <split>
>                                <simple>${in.body}</simple>
>                                <bean
> ref="inboundTransportDocumentConverter"
> method="constructMessageFromDatabase" />
>                <to uri="direct:inboundEndpoint" />
>            </split>
>
>                </route>
>
> As you can see I'm using the mybatis component as a poller.
>
> NOw, how can I pass in a variable to 'fetchMessagesReadyForDelivery' method
> ? This will help me pass in different value to the method without having to
> re-write similar DAO methods. I've just one variable(parameter) that this
> method expects
>
> Thanks,
> Jeoffrey
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Pass-variable-to-mybatis-component-tp5137772p5137772.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>