gpt4 book ai didi

java - 有人可以提供 spring-integration-aws SQS 用法的示例吗?

转载 作者:行者123 更新时间:2023-12-04 12:47:13 25 4
gpt4 key购买 nike

Herespring-integration-aws 项目。他们提供了有关 Inbound Channle 适配器的示例:

@SpringBootApplication
public static class MyConfiguration {

@Autowired
private AmazonSQSAsync amazonSqs;

@Bean
public PollableChannel inputChannel() {
return new QueueChannel();
}

@Bean
public MessageProducer sqsMessageDrivenChannelAdapter() {
SqsMessageDrivenChannelAdapter adapter = new SqsMessageDrivenChannelAdapter(this.amazonSqs, "myQueue");
adapter.setOutputChannel(inputChannel());
return adapter;
}
}

好了,ChannelSqsMessageDrivenChannelAdapter 都定义好了,但是接下来呢?假设我有这样的 spring bean:

import com.amazonaws.services.sqs.model.Message;

@Component
public class MyComponent {
public void onMessage(Message message) throws Exception {
//handle sqs message
}
}
  1. 如何告诉 spring 将所有消息从myQueue 传递给这个组件?
  2. 是否有任何额外的配置来处理消息一?例如在收到消息 SQS 后将它们标记为处理并且它们对其他客户端不可见,所以它是只需要获取一条消息,然后处理并获取下一条消息。做此行为默认启用?

最佳答案

您应该阅读 Spring Integration Reference Manual .

@Component
public class MyComponent {

@ServiceActivator(inputChannel = "inputChannel")
public void onMessage(Message message) throws Exception {
//handle sqs message
}

}

关于java - 有人可以提供 spring-integration-aws SQS 用法的示例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com