【问题标题】:Spring Cloud Task not started with Spring Cloud Stream using RabbitMQSpring Cloud Task 未通过 Spring Cloud Stream 使用 RabbitMQ 启动
【发布时间】:2019-03-27 20:32:41
【问题描述】:

我正在尝试将 Spring Cloud API 作为微服务课程的一部分。

为了设置无服务器任务,我使用 Cloud Task、Cloud Stream(RabbitMQ) 和 Spring Web。

为此,我设置了以下项目:

要执行的无服务器任务 - https://github.com/Omkar-Shetkar/pluralsight-springcloud-m3-task

接收来自用户的 Http 请求并提交给 RabbitMQ 的组件 - https://github.com/Omkar-Shetkar/pluralsight-springcloud-m3-taskintake

接收 TaskLaunchRequest 并转发到云任务的接收器组件 - https://github.com/Omkar-Shetkar/pluralsight-springcloud-m3-tasksink

设置以上组件,确保任务组件在本地 maven 存储库中可用。

pluralsight.com.TaskController.launchTask(String) 中向/tasks 发起POST 请求后,我看到了一个HTTP 响应。

但是,我在与无服务器任务相关的任务日志数据库中看不到任何更新。 这意味着,任务本身不会被调用。

在 RabbitMQ 控制台中,我可以看到从入口和接收器组件建立了连接,但我没有看到任何消息交换发生。

名称为 tasktopic 的队列的消息计数为零。

感谢有关如何继续解决此问题的任何指示和建议。

谢谢。

【问题讨论】:

    标签: rabbitmq spring-cloud spring-cloud-stream spring-cloud-task


    【解决方案1】:

    我当前的实现有两个问题:

    在入口和接收器模块中 -> application.properties,绑定属性键错误。

    应该是:

    在进气模块中

    spring.cloud.stream.bindings.output.destination=tasktopic
    

    在接收器模块中

    spring.cloud.stream.bindings.input.destination=tasktopic
    

    此外,本地云部署器版本在接收器模块 pom.xml 中不兼容。

    更新为:

       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-deployer-local</artifactId>
            <version>1.3.0.RELEASE</version>
        </dependency>
    

    通过这些更改,我能够获取 RabbitMQ 消息。

    【讨论】:

      【解决方案2】:

      TaskIntakeApplication 中缺少@EnableTaskLauncher 注释。

      @SpringBootApplication
      @EnableTaskLauncher
      public class PluralsightSpringcloudM3TaskintakeApplication {
      
          public static void main(String[] args) {
              SpringApplication.run(PluralsightSpringcloudM3TaskintakeApplication.class, args);
          }
      }
      

      【讨论】:

      • 我想@EnableTaskLauncher 应该与接收器任务一起使用。在我进行建议的更改后,出现以下错误: org.springframework.cloud.task.launcher.TaskLauncherSink 中的字段 taskLauncher 需要一个找不到的 'org.springframework.cloud.deployer.spi.task.TaskLauncher' 类型的 bean。注入点有以下注解: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: 考虑在你的配置。
      猜你喜欢
      • 2018-01-24
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 2021-03-25
      • 2017-05-31
      • 2021-06-07
      • 1970-01-01
      相关资源
      最近更新 更多