如何在AWS-SQS Camel组件上设置amazonSQSClient参数

时间:2017-04-17 11:33:00

标签: spring apache-camel

我有一个豆子

@Component
public class SqsClient {

    @Autowired
    private AWSCredentialsProvider customChain;

    @Value("my-region")
    private String region;

    private AmazonSQS sqsClient;

    @PostConstruct
    private void init() {
        sqsClient = AmazonSQSClientBuilder.standard()
                .withRegion(region)
                .withCredentials(customChain)
                .build();
    }

    public AmazonSQS getAmazonSQSClient() {
        return sqsClient;
    }
}

同样在我的上下文中我声明了路径

<route id="process.sqs.message">
    <from uri="aws-sqs://{{aws.sqs.queue}}?amazonSQSClient=#sqsClient"/>
    <to url="bean:sqsQueueListener?method=processMessage(${body})"/>
</route>

但是当我启动应用程序时,我得到了异常

Caused by: 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

为什么它无法设置amazonSQSClient

1 个答案:

答案 0 :(得分:2)

因为amazonSQSClient组件上的aws-sqs参数必须是对Camel注册表中com.amazonaws.services.sqs.AmazonSQS的引用。

@Bean注释添加到您的getter中,其名称与您在aws-sqs端点中引用它的名称相同:

@Bean(name = "sqsClient")
public AmazonSQS getAmazonSQSClient() {
    return sqsClient;
}