> On 25 Apr 2016, at 15:20, Claus Ibsen <[email protected]> wrote:
>
> On Mon, Apr 25, 2016 at 3:15 PM, Antonin Stefanutti
> <[email protected]> wrote:
>> Hi Nicolas,
>>
>> There is some sort of cyclic dependency in your code from the CDI standpoint.
>>
>> You have an injection point for @Uri("jms:...") while your have the producer
>> method for the component in the same bean.
>>
>> I would suggest you either move the producer method in a separate bean, like
>> JmsComponentFactory or declare the producer method static.
>>
>
> Yeah that is a good idea to keep those @produces separated from routes
> and etc (eg their clients). I guess its a habit of coming up with a
> good naming for those factory classes. Do you create 1 class per kind,
> or have more in the same class? or a mix?
I would tend to create one class per kind, for example for JMS typically
something like:
class JmsComponentFactory {
// Connection factory resource (from JNDI for example)
@Resource(mappedName = "jndi.connectionFactoryName")
private ConnectionFactory connectionFactory;
@Produces
@Named("jms")
@ApplicationScoped
// Some external configuration parameters
Component produceJmsComponent(@ConfigProperty(name = "jms.consumers")
String inputQueueConcurrentConsumers) {
CachingConnectionFactory cachingConnectionFactory = new
CachingConnectionFactory(connectionFactory);
cachingConnectionFactory.setSessionCacheSize(Integer.parseInt(consumers));
return JmsComponent.jmsComponent(cachingConnectionFactory);
}
// Don’t forget to close the connections
void disposeJmsComponent(@Disposes @Named("jms") Component component) {
((SingleConnectionFactory)
component.getConfiguration().getConnectionFactory()).destroy();
}
}
I’m planning to add a JMS / CDI example :)
>> Antonin
>>
>>> On 25 Apr 2016, at 14:46, nicolasduminil
>>> <[email protected]> wrote:
>>>
>>> Hi Claus,
>>>
>>> Many thanks for your suggestion. Now the code looks as follows:
>>>
>>> public class MyRoutes extends RouteBuilder {
>>> @Inject
>>> @Uri("file:data/inbox?noop=true")
>>> private Endpoint inputEndpoint;
>>>
>>> @Inject
>>> @Uri("jms:incommingData")
>>> private Endpoint resultEndpoint;
>>>
>>> @Produces
>>> @Named("jms")
>>> public Component jmsComponent()
>>> {
>>> ConnectionFactory connectionFactory = new
>>> ActiveMQConnectionFactory("tcp://cac40:61616?create=false");
>>> return JmsComponent.jmsComponentAutoAcknowledge(connectionFactory);
>>> }
>>>
>>> @Override
>>> public void configure() {
>>> from(inputEndpoint).to("bean:counterBean").to(resultEndpoint);
>>> }
>>> }
>>>
>>> Running it with camel:run raises the following:
>>>
>>> [ERROR] Caused by: org.apache.camel.ResolveEndpointFailedException: Failed
>>> to resolve endpoint: jms://incommingData due to: Cannot auto create
>>> component: jms
>>> [ERROR] at
>>> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:588)
>>> [ERROR] at
>>> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:601)
>>> [ERROR] at
>>> org.apache.camel.impl.DefaultCamelContext$Proxy$_$$_WeldClientProxy.getEndpoint(Unknown
>>> Source)
>>> [ERROR] at
>>> org.apache.camel.cdi.CdiCamelFactory.endpoint(CdiCamelFactory.java:119)
>>> [ERROR] ... 65 more
>>>
>>> Is there anything else I could try. This code was generated by the
>>> maven-camel-jms-cdi archetype.
>>>
>>> Kind regards,
>>>
>>> Nicolas DUMINIL
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/java-lang-IllegalArgumentException-Cannot-add-component-as-its-already-previously-added-jms-tp5781607p5781658.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2