vendredi 30 janvier 2015

Camel, Amazon SQS - No type converter available to convert from type: java.lang.String to the required type: com.amazonaws.services.sqs.AmazonSQS

I am currently working on a Spring Application using Camel which is going to poll SQS as an entry point into the application (1st route). I am successfully able to Achieve this using Spring's XML based Approach.


My AmazonSQSClient Bean:



<bean id="sqsClient" class="com.amazonaws.services.sqs.AmazonSQSClient">
<constructor-arg ref="sqsCredentialsProvider" />
<property name="endpoint" value="${aws.sqs.endpoint}" />
</bean>


My Camel Route:



<route id="pollMessages">
<from id="sqsEndpoint" uri="http://ift.tt/1yNzCqQ" />
<to uri="direct:readSQSMessage" />
</route>


Everything works as I want at this point with the above approach.


Now I am trying to migrate all my beans and Camel Configuration to Java Based Approach.


I have created my Amazon SQS Client Bean as following:



@Bean
public AmazonSQS sqsClient(){
ClientConfiguration clientConfiguration = new ClientConfiguration();
AmazonSQSClient client = new AmazonSQSClient(sqsCredentialsProvider(), clientConfiguration);
client.setEndpoint(sqsEndpoint);

return client;
}


And, I am creating Camel route (snippet) looks like:



@Bean
public CamelContext camelContext() throws Exception{
CamelContext camelContext = new DefaultCamelContext();

camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() {

from("aws-sqs://"+fulfillmentQueueName+"?amazonSQSClient=#sqsClient&amp;delay="+fulfillmentQueuePollInterval)
.to("direct:parseSQSMessage");

}
});

camelContext.start();
return camelContext;
}


However, I am getting errors using this approach:


java.lang.IllegalArgumentException: Could not find a suitable setter for property: amazonSQSClient as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: com.amazonaws.services.sqs.AmazonSQS with value #sqsClient


I read here how to construct a Java style Camel Route


I read here that I need to bind the AWS Client to Registry (registry.bind) but I am not able to find a bind method on any Registry except JNDI


I tried this as well:



SimpleRegistry registry = new SimpleRegistry();
registry.put("sqsClient", sqsClient());

CamelContext camelContext = new DefaultCamelContext(registry);


But got same error.


I searched a lot and tried reading up, plan to keep doing more but am unable to find any complete example doing what I need to do. Snippets are helping much here.


Any help is greatly appreciated. Thanks





Aucun commentaire:

Enregistrer un commentaire