5

我正在尝试使用 Sleuth 跟踪 Spring 云集成 aws + AWS SQS 应用程序。消息加入队列后,接收方从 SQS 接收消息。该日志具有应用程序名称,但在从 sql 队列接收消息时没有跟踪 ID 和跨度 ID。这是日志中的一行:

2017-07-28 16:24:02.352 信息 [sqs-sleuth-demo,,,] 9706 --- [enerContainer-2] com.example.demo.SQSMessageReceiver:出列消息:你好世界

我使用 Spring Boot '1.5.4.RELEASE' 和 Spring Cloud 'Dalston.SR1'。这是依赖项:

dependencies {

  compile("org.springframework.boot:spring-boot")
  compile("org.springframework.boot:spring-boot-starter")
  compile("org.springframework.boot:spring-boot-starter-web")

  compile("org.springframework.cloud:spring-cloud-aws-messaging")
  compile("org.springframework.cloud:spring-cloud-aws-autoconfigure")
  compile('org.springframework.cloud:spring-cloud-starter-sleuth')
  compile("org.springframework.integration:spring-integration-aws:1.0.0.RELEASE")

  compile("com.amazonaws:aws-java-sdk-sqs")
}

dependencyManagement {
  imports {
    mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
  }
}

AppConfig.java

@Configuration
public class AppConfig {

  @Value("${amazon.aws.accesskey}")
  private String amazonAWSAccessKey;

  @Value("${amazon.aws.secretkey}")
  private String amazonAWSSecretKey;

  @Value("${amazon.sqs.endpoint}")
  private String amazonSqsEndpoint;

  @Value("${cloud.aws.region.static}")
  private String awsRegion;

  @Bean
  @Primary
  public AWSCredentialsProviderChain credentialsProviderChain() {

    return new DefaultAWSCredentialsProviderChain();
  }
}

SQSMessageReceiver.java

@Component
public class SQSMessageReceiver {

  private static final Logger LOGGER = LoggerFactory.getLogger(SQSMessageReceiver.class);

  @Autowired
  private RestTemplate restTemplate;

  @SqsListener(value="${amazon.sqs.queue.name}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)

  public void receive(String message) throws Exception {

    LOGGER.info("dequeued message: " + message);

  }
}

和,DemoApplication.java

@SpringBootApplication
@EnableSqs
public class DemoApplication {

  private static final Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class);

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);

  }
}

是否可以使用 Sleuth 跟踪 SQS 事件或设置/代码有什么问题?

谢谢,

4

0 回答 0