You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by paquettd <da...@lmco.com> on 2009/02/03 02:07:19 UTC
Spring-DM and ProducerTemplate
So I have a spring file that looks something like this. I'm using Spring-DM
and Camel 1.5.0. So this file is in META-INF/spring in my OSGi bundle.
<camelContext id="camelcontext"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="direct:testDirect"/>
<to uri="stream:err"/>
</route>
</camelContext>
<camel:template id="myCamelTemplate"/>
<bean id="myBean" class="myClass">
<property name="producerTemplate" ref="myCamelTemplate"/>
</bean>
So what I've found is that if I sleep for a few hundred milliseconds in my
bean after receiving the producer template I can then send a string to
direct:testDirect and it will print out on stderr. However, if I use the
template right away without sleeping I see
[SpringOsgiExtenderThread-2] WARN
org.apache.camel.component.direct.DirectProducer - No getConsumers()
available on Producer[direct:testDirect] for Exchange[Message: Hello World]
and no message is ever printing. Clearly there is some kind of race here.
What do I need to do so that I can be positive the camel context is up and
ready. I tried casting it to DefaultCamelContext and using the isStarted
method but that doesn't do it. It looks like that starts returning true
before everything is necessarily up and running.
Am I missing something obvious?
Thank you.
--
View this message in context: http://www.nabble.com/Spring-DM-and-ProducerTemplate-tp21802085s22882p21802085.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Spring-DM and ProducerTemplate
Posted by James Strachan <ja...@gmail.com>.
2009/2/3 paquettd <da...@lmco.com>:
> So I have a spring file that looks something like this. I'm using Spring-DM
> and Camel 1.5.0. So this file is in META-INF/spring in my OSGi bundle.
>
> <camelContext id="camelcontext"
> xmlns="http://activemq.apache.org/camel/schema/spring">
> <route>
> <from uri="direct:testDirect"/>
> <to uri="stream:err"/>
> </route>
> </camelContext>
> <camel:template id="myCamelTemplate"/>
>
> <bean id="myBean" class="myClass">
> <property name="producerTemplate" ref="myCamelTemplate"/>
> </bean>
>
> So what I've found is that if I sleep for a few hundred milliseconds in my
> bean after receiving the producer template I can then send a string to
> direct:testDirect and it will print out on stderr. However, if I use the
> template right away without sleeping I see
>
> [SpringOsgiExtenderThread-2] WARN
> org.apache.camel.component.direct.DirectProducer - No getConsumers()
> available on Producer[direct:testDirect] for Exchange[Message: Hello World]
>
> and no message is ever printing. Clearly there is some kind of race here.
> What do I need to do so that I can be positive the camel context is up and
> ready. I tried casting it to DefaultCamelContext and using the isStarted
> method but that doesn't do it. It looks like that starts returning true
> before everything is necessarily up and running.
>
> Am I missing something obvious?
I wonder if you use the @Produce annotation to get camel to inject it
into your bean, it avoids the ordering issues?
http://cwiki.apache.org/CAMEL/pojo-producing.html
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/
Re: Spring-DM and ProducerTemplate
Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Feb 3, 2009 at 2:07 AM, paquettd <da...@lmco.com> wrote:
>
> So I have a spring file that looks something like this. I'm using Spring-DM
> and Camel 1.5.0. So this file is in META-INF/spring in my OSGi bundle.
>
> <camelContext id="camelcontext"
> xmlns="http://activemq.apache.org/camel/schema/spring">
> <route>
> <from uri="direct:testDirect"/>
> <to uri="stream:err"/>
> </route>
> </camelContext>
> <camel:template id="myCamelTemplate"/>
>
> <bean id="myBean" class="myClass">
> <property name="producerTemplate" ref="myCamelTemplate"/>
> </bean>
>
> So what I've found is that if I sleep for a few hundred milliseconds in my
> bean after receiving the producer template I can then send a string to
> direct:testDirect and it will print out on stderr. However, if I use the
> template right away without sleeping I see
>
> [SpringOsgiExtenderThread-2] WARN
> org.apache.camel.component.direct.DirectProducer - No getConsumers()
> available on Producer[direct:testDirect] for Exchange[Message: Hello World]
>
> and no message is ever printing. Clearly there is some kind of race here.
> What do I need to do so that I can be positive the camel context is up and
> ready. I tried casting it to DefaultCamelContext and using the isStarted
> method but that doesn't do it. It looks like that starts returning true
> before everything is necessarily up and running.
>
> Am I missing something obvious?
Yeah it could be. As Spring is doing the IoC stuff your bean might get
injected with the producer template before Camel had a chance to
properly startup.
Maybe you can use the Spring depend-on attribute to instruct your bean
that it depends on camel.
Maybe you have found a isStarted() issue in camel-core. Feel free to
create a ticket in JIRA for the isStarted() so we wont forget and can
take a look at it.
>
> Thank you.
> --
> View this message in context: http://www.nabble.com/Spring-DM-and-ProducerTemplate-tp21802085s22882p21802085.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/