Я новичок в весенней загрузке и пытаюсь использовать слушатель sqs для опроса очереди тестов в локальном стеке.Я могу помещать сообщения в мою локальную очередь стека.Но затем я хочу опросить ту же очередь и зарегистрировать содержимое сообщения.Тем не менее, я не получаю никаких сообщений, записанных на консоль в списке sqs?
application-local.properties
cloud.aws.region=us-east-1
cloud.local.sqs=http://localstack:4576
cloud.local.s3=http://localstack:4572
app.sqs.maxmessages=1
app.sqs.input=http://localstack:4576/queue/test-queue
app.sqs.output=http://localstack:4576/queue/test-queue
AppController
@Log4j2
@RestController
public class AppController {
private AmazonS3 s3;
private SQSOutput output;
@Autowired
public AppController(AmazonS3 s3, SQSOutput output) {
this.s3 = s3;
this.output = output;
}
@RequestMapping("/send")
public Map<String, String> sendMessage() {
output.send("Test Message!");
Map<String, String> response = new HashMap<>();
response.put("message", "Message sent!");
return response;
}
@SqsListener(value = "${app.sqs.input}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void getMessage(String message) {
log.info("Received message: " + message);
}
}
SetupBeans
@Component
public class SetupBeans {
@Value("${cloud.aws.region}")
private String region;
@Value("${cloud.local.s3}")
private String localCloudS3;
@Value("${cloud.local.sqs}")
private String localCloudSQS;
@Value("${app.sqs.output}")
private String outputUrl;
@Value("${app.sqs.maxmessages}")
private int maxMessages;
@Bean
@Primary
private AWSCredentialsProvider credProvider() {
return DefaultAWSCredentialsProviderChain.getInstance();
}
@Bean
@Primary
public AmazonS3 amazonS3() {
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder
.EndpointConfiguration(localCloudS3, region);
return AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration)
.build();
}
@Bean
@Primary
private AmazonSQSAsync amazonSQSAsync() {
AmazonSQSAsyncClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder
.EndpointConfiguration(localCloudSQS, region);
return AmazonSQSAsyncClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration)
.build();
}
@Bean
private QueueMessagingTemplate queueMessagingTemplate() {
return new QueueMessagingTemplate(amazonSQSAsync());
}
@Bean
public QueueMessageHandlerFactory queueMessageHandlerFactory() {
QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();
MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
// set strict content type match to false
messageConverter.setStrictContentTypeMatch(false);
factory.setArgumentResolvers(Collections.<HandlerMethodArgumentResolver>singletonList(new PayloadArgumentResolver(messageConverter)));
return factory;
}
@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(AmazonSQSAsync amazonSQS){
SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
factory.setAmazonSqs(amazonSQS);
factory.setMaxNumberOfMessages(maxMessages);
return factory;
}
@Bean
private QueueMessageChannel getQueueMessageChannel() {
return new QueueMessageChannel(amazonSQSAsync(), outputUrl);
}
@Bean
public SQSOutput getSQSOutput() {
return new SQSOutput(queueMessagingTemplate(), getQueueMessageChannel());
}
}