无法通过Springboot应用程序从SQS读取消息

问题描述 投票:0回答:1
package com.example.aws.Springbootsqs.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SQSController {
    
    Logger logger =LoggerFactory.getLogger(SQSController.class);
    
    @Autowired
    private QueueMessagingTemplate queueMessagingTemplate;
    
    @Value("${cloud.aws.end-point.uri}")
    private String endPoint;

    
    @GetMapping("/put/{msg}")
    public void putMessagesToQueue(@PathVariable("msg") String message) {
        queueMessagingTemplate
        .send(endPoint, MessageBuilder
                .withPayload(message)
                .build());
        
    }
    
    @SqsListener("sqs-queue")
    public void loadMessagesFromQueue(String message) {
        logger.info(message);
    
    }
    
    
}

我可以将消息推送到 SQS,但同时当我读取和打印消息时,该方法没有被调用,也没有从 SQS 打印任何内容,并且控制台上没有错误。

任何帮助都会有用的。预先感谢。

java spring-boot amazon-sqs
1个回答
0
投票

也许您使用的是SSO登录方法,SQS监听器当前不支持SSO登录,您必须在.aws文件夹中刷新它们或在配置文件中添加ACCESS_KEY和SECRET_KEY。如果您可以分享您的 pom/build 文件,那就更有利了,我不确定您正在使用哪种构建工具。

© www.soinside.com 2019 - 2024. All rights reserved.