Amazon SQS'FailedToCreateRouteException'将Netflix-Hystrix引入Spring项目

时间:2019-03-28 16:08:36

标签: spring maven spring-cloud-netflix hystrix

我正在尝试将Hystrix引入我的Spring项目,但是当我向pom添加以下依赖项(从1.4.4尝试到最新版本2.1.1)时:

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
   <version>2.1.1.RELEASE</version>
</dependency>

我收到以下异常:

Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route queue-name-consumer: Route(queue-name-consumer)[[From[aws-sqs://u... because of The specified queue does not exist or you do not have access to it. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue)
    at org.apache.camel.impl.RouteService.warmUp(RouteService.java:147) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3949) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3856) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3642) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3494) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:209) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3253) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3272) ~[camel-core-2.22.2.jar:2.22.2]
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3249) ~[camel-core-2.22.2.jar:2.22.2]

我正在使用: -Spring Boot 2.0.5 -骆驼2.22.2 -AWS-Java-SDK 1.11.381

我的SQS队列在我的spring app中以以下格式配置

@Configuration
public class QueueConfig implements CamelContextAware {

    private final AmazonSQSAsync amazonSQSClient;

    private CamelContext camelContext;

    @Autowired
    public QueueConfig(AmazonSQSAsync amazonSQSClient) {
        this.amazonSQSClient = amazonSQSClient;
    }

    @Override
    public void setCamelContext(CamelContext camelContext) {
        this.camelContext = camelContext;
    }

    @Override
    public CamelContext getCamelContext() {
        return camelContext;
    }


    @Bean(name = "ExampleListenerBean)
    public MessageListener<Exchange> amazonMessageListener(
            RequestHandler handler,
            Acknowledger<AmazonMessage> acknowledger) {

        MessageListener<Exchange> listener =
                new AmazonMessageListener<>(handler, acknowledger, new CamelSQSMessageConverter());
        return listener;
    }

    @Bean(name = "ExampleRequestRouteDefinition")
    public RouteBuilder exampleRouteDefinition(
            @Qualifier(ExampleListenerBean) MessageListener<Exchange> listener) {

        SqsQueueRouteProps properties =
                SqsQueueRouteProps.main("queueDefinition", "path-to-queue").build();

        String queue = properties.getFullQueueName();
        return SqsQueueRouteBuilder.newBuilder(queue, amazonSQSClient, listener, getCamelContext())
                .withRouteName("example-route-name")
                .withProperties(properties)
                .build();
    }

此设置在没有hystrix依赖的情况下均可正常运行,我不确定在此处查找哪些不兼容性,错误消息会引起误解,因为队列存在,在我找不到的地方有冲突。

1 个答案:

答案 0 :(得分:0)

也要提及该版本,然后尝试一下!

   <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    <version>2.1.1.RELEASE</version>
   </dependency>