我正在尝试让 spring cloud 使用自动配置来处理消息传递。
我的属性文件包含:
cloud.aws.credentials.accessKey=xxxxxxxxxx
cloud.aws.credentials.secretKey=xxxxxxxxxx
cloud.aws.region.static=us-west-2
我的配置类如下:
@EnableSqs
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
我的听众类:
@RestController
public class OrderListener {
@MessageMapping("orderQueue")
public void orderListener(Order order){
System.out.println("Order Name " + order.getName());
System.out.println("Order Url" + order.getUrl());
}
}
但是,当我运行它时。我收到以下错误:
org.springframework.context.ApplicationContextException: Failed to start bean 'simpleMessageListenerContainer'; nested exception is org.springframework.messaging.core.DestinationResolutionException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: cc8cb199-be88-5993-bd58-fca3c9f17110); nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: cc8cb199-be88-5993-bd58-fca3c9f17110)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:770)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)
at com.releasebot.processor.Application.main(Application.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.springframework.messaging.core.DestinationResolutionException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: cc8cb199-be88-5993-bd58-fca3c9f17110); nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: cc8cb199-be88-5993-bd58-fca3c9f17110)
at org.springframework.cloud.aws.messaging.support.destination.DynamicQueueUrlDestinationResolver.resolveDestination(DynamicQueueUrlDestinationResolver.java:81)
at org.springframework.cloud.aws.messaging.support.destination.DynamicQueueUrlDestinationResolver.resolveDestination(DynamicQueueUrlDestinationResolver.java:37)
at org.springframework.messaging.core.CachingDestinationResolverProxy.resolveDestination(CachingDestinationResolverProxy.java:88)
at org.springframework.cloud.aws.messaging.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:300)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.start(SimpleMessageListenerContainer.java:38)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
... 18 common frames omitted
还有其他人遇到过这个吗?任何帮助将不胜感激
这个错误意味着指定的队列orderQueue在区域us-west-2上不存在。只需创建它,它就可以工作。
顺便说一句,使用
_@EnableSqs_
时不需要添加_@EnableAutoConfiguration_
。
阿兰的回答是正确的。此错误表明该队列在区域 us-west-2 中不存在。原因之一可能是 AWS Java SDK 使用 us-east-1 作为默认区域。来自 AWS 文档http://docs.aws.amazon.com/java-sdk/latest/developer-guide/java-dg-region-selection.html
如果您未在代码中指定区域,则适用于 Java 的 AWS 开发工具包使用 us-east-1 作为默认区域。但是,AWS 管理控制台默认使用 us-west-2。因此,在将 AWS 管理控制台与您的开发结合使用时,请务必在您的代码和控制台中指定相同的区域。
您可以使用
setRegion()
或setEndpoint()
对象的AmazonSQSClient
方法在客户端中专门设置区域或终点。请参阅http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sqs/AmazonSQS.html#setEndpoint-java.lang.String-
有关区域和端点的列表,请参阅http://docs.aws.amazon.com/general/latest/gr/rande.html#sqs_region
尝试使用队列的 URL,而不是名称。
我在尝试使用命令行 get-queue-url 时遇到了同样的问题。看看我有什么:
A client error (AWS.SimpleQueueService.NonExistentQueue) occurred when calling the GetQueueUrl operation: The specified queue does not exist for this wsdl version.
必须运行这个:
$aws configure
在提示“默认区域名称[...]:”下,输入了我的队列所属的区域。然后错误消失了。
所以仔细检查你的配置 ;)
确保您使用的是正确的 AWS 配置文件。这是我的问题。如果您有多个配置文件,您可以获得所有:
cat ~/.aws/credentials
然后您可以设置不同的配置文件:
export AWS_PROFILE=<profile_name>
如果不指定,默认情况下当前配置文件是
default
,所以一定要考虑到这一点。
我在重新创建同名队列后也遇到了这个错误,创建一个新队列是直接的解决方案,因为我不确定新 ARN 连接需要多长时间。
如果队列名称已经存在并且您仍然收到此错误,请确保运行
aws configure
并将区域设置为 us-east-1.
在我的例子中,队列名称存在但它仍然抛出该错误,因为该区域设置为 us-east-2。我不确定为什么,但似乎将区域更改为 us-east-1 到默认区域为我修复了它。