我正在尝试开发一个SQS侦听器,它在后台运行并在新消息到达时从AWS SQS读取消息,并且永远不应删除该消息,因为将有一个单独的删除消息的过程。
这是一个独立的应用程序,刚刚开始开发。但由于基本的东西不起作用,因此无法继续进行。我确定我错过了什么。我正在使用 spring-cloud-aws-messaging(版本:1.2.0.BUILD-SNAPSHOT)。
这是一个非常简单的独立应用程序,具有以下文件: 一个弹簧配置文件:application-context.xml(上面已粘贴的内容) 一个SQS监听器:SBSQSMessageListener(已粘贴上面的内容) 一个主程序正在加载application-context.xml&创建ApplicationContext
我的Spring配置文件:
<aws-context:context-region region="us-west-2"/>
<aws-context:context-credentials>
<aws-context:simple-credentials access-key="xxxxxxx" secret-key="xxxxxxxxxxxxx" />
</aws-context:context-credentials>
<aws-messaging:queue-messaging-template id="queueMessagingTemplate" />
<aws-messaging:annotation-driven-queue-listener task-executor="simpleTaskExecutor" />
<bean id="simpleTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="4" />
<property name="maxPoolSize" value="10" />
<property name="queueCapacity" value="1" />
<property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean>
我的SQSListener:
package sb.aws.sqs.listener;
import java.util.concurrent.ExecutionException;
import org.apache.log4j.Logger;
import org.springframework.cloud.aws.messaging.config.annotation.EnableSqs;
import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
import org.springframework.cloud.aws.messaging.listener.Acknowledgment;
import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Component;
@Component
@EnableSqs
public class SBSQSMessageListener {
final static Logger logger = Logger.getLogger(SBSQSMessageListener.class);
@MessageMapping("sb-sqs-queue1")
@SqsListener(value = "sb-sqs-queue1", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receive(String message, Acknowledgment acknowledgment) {
System.out.println("Inside receive: " + message);
try {
acknowledgment.acknowledge().get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我得到以下异常:
DT:02/17/2017 15:20:20 LL:DEBUG主机名:storeId:txnId: CL:DefaultListableBeanFactory MSG:创建的共享实例 singleton bean&#39; simpleMessageListenerContainer&#39; DT:02/17/2017 15:20:20 LL:DEBUG主机名:storeId:txnId:CL:DefaultListableBeanFactory MSG:创建bean的实例&#39; simpleMessageListenerContainer&#39; DT:02/17/2017 15:20:20 LL:DEBUG主机名:storeId:txnId: CL:DefaultListableBeanFactory MSG:返回缓存的实例 单身豆 &#39; org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration&#39; DT:02/17/2017 15:20:20 LL:DEBUG主机名:storeId:txnId: CL:DefaultListableBeanFactory MSG:返回缓存的实例 singleton bean&#39; amazonSQSAsync&#39; DT:02/17/2017 15:20:20 LL:DEBUG hostname:storeId:txnId:CL:DefaultListableBeanFactory MSG:Creating 单例bean的共享实例&#39; amazonSQS&#39; DT:02/17/2017 15:20:20 LL:DEBUG主机名:storeId:txnId:CL:DefaultListableBeanFactory 味精:创建bean的实例&amazonSQS&#39; DT:02/17/2017 15:20:20 LL:DEBUG主机名:storeId:txnId:CL:DefaultListableBeanFactory MSG:返回单例bean的缓存实例 &#39; org.springframework.cloud.aws.messaging.config.annotation.SqsClientConfiguration&#39; DT:02/17/2017 15:20:21 LL:DEBUG主机名:storeId:txnId: CL:DefaultListableBeanFactory MSG:急切地缓存bean&#39; amazonSQS&#39;至 允许解决潜在的循环引用DT:02/17/2017 15:20:21 LL:DEBUG主机名:storeId:txnId: CL:DefaultListableBeanFactory MSG:完成创建bean的实例 &#39; amazonSQS&#39;线程&#34; main&#34;中的例外情况 org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为&#39; simpleMessageListenerContainer&#39;定义 在类路径资源中 [组织/ springframework的/云/ AWS /消息/配置/注解/ SqsConfiguration.class]: 通过构造函数参数表示不满意的依赖关系 [com.amazonaws.services.sqs.AmazonSQSAsync]类型的索引0 ::否 [com.amazonaws.services.sqs.AmazonSQSAsync]类型的限定bean是 已定义:预期单个匹配bean但找到2: amazonSQSAsync,amazonSQS;嵌套异常是 org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有 [com.amazonaws.services.sqs.AmazonSQSAsync]类型的限定bean是 已定义:预期单个匹配bean但找到2: amazonSQSAsync,amazonSQS at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 在 org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 在 org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:139) 在 org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:93) 在sb.aws.sqs.SBSQSMain.main(SBSQSMain.java:14) 引起:org.springframework.beans.factory.NoUniqueBeanDefinitionException:否 [com.amazonaws.services.sqs.AmazonSQSAsync]类型的限定bean是 已定义:预期单个匹配bean但找到2: amazonSQSAsync,amazonSQS at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) 在 org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) 在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ......还有15个
如果我错过任何东西,请你指导我吗?
非常感谢。