带有属性占位符的 Spring Cloud AWS SQS SendTo 注释

2024-04-20

这个问题 https://github.com/spring-cloud/spring-cloud-aws/issues/65建议 @SendTo 注释支持属性占位符,但我无法让它工作。这是我想要做的一些简化的代码片段(比尝试用文字解释更容易)。我使用的是 spring-cloud-aws 版本 1.2.1。

这有效:

@Component
public class InputQueueListener {

    @Value("${replyQueueProperty}")
    private String replyQueue;

    @Autowired
    private QueueMessagingTemplate messagingTemplate;

    @SqsListener(value = "${inputQueueProperty}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
    private void receiveMessage(final Message message, final Acknowledgment acknowledgment, @Header("ApproximateReceiveCount") final int receiveCount) throws Exception {
        final Reply reply = doStuff(message);

        messagingTemplate.convertAndSend(replyQueue, reply);
    }
}

这有效:

@Component
public class InputQueueListener {

    @SqsListener(value = "${inputQueueProperty}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
    @SendTo("replyQueueActualName")
    private Reply receiveMessage(final Message message, final Acknowledgment acknowledgment, @Header("ApproximateReceiveCount") final int receiveCount) throws Exception {
        final Reply reply = doStuff(message);

        return reply;
    }
}

但这不起作用:

@Component
public class InputQueueListener {

    @SqsListener(value = "${inputQueueProperty}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
    @SendTo("${replyQueueProperty}")
    private Reply receiveMessage(final Message message, final Acknowledgment acknowledgment, @Header("ApproximateReceiveCount") final int receiveCount) throws Exception {
        final Reply reply = doStuff(message);

        return reply;
    }
}

此操作会失败并出现 NonExistentQueue 异常。但队列是存在的,前两个方法向它发送消息就可以了。 我错过了什么?!我已经检查了拼写错误一百万次,我很确定不是这样的:)

以防万一,这是我的配置:

@Bean
public QueueMessagingTemplate queueMessagingTemplate(final AmazonSQSAsync amazonSqs, final ResourceIdResolver resourceIdResolver) {
    final QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs, resourceIdResolver);
    return queueMessagingTemplate;
}

@Lazy
@Bean(name = "amazonSQS", destroyMethod = "shutdown")
public AmazonSQSAsync amazonSQSClient() {

    final AmazonSQSAsync awsSQSAsyncClient;

    awsSQSAsyncClient = AmazonSQSAsyncClientBuilder
            .standard()
            .withRegion(Regions.fromName(System.getProperty("cloud.aws.region.static")))
            .withCredentials(new DefaultAWSCredentialsProviderChain())
            .build();
    return awsSQSAsyncClient;
}

@Bean
public QueueMessageHandler queueMessageHandler(final AmazonSQSAsync amazonSqs) {
    final QueueMessageHandlerFactory queueMsgHandlerFactory = new QueueMessageHandlerFactory();
    queueMsgHandlerFactory.setAmazonSqs(amazonSqs);

    final QueueMessageHandler queueMessageHandler = queueMsgHandlerFactory.createQueueMessageHandler();

    return queueMessageHandler;
}

@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(final AmazonSQSAsync amazonSqs) {
    final SimpleMessageListenerContainerFactory msgListenerContainerFactory = new SimpleMessageListenerContainerFactory();
    msgListenerContainerFactory.setAmazonSqs(amazonSqs);
    msgListenerContainerFactory.setMaxNumberOfMessages(5);
    msgListenerContainerFactory.setWaitTimeOut(20);

    return msgListenerContainerFactory;
}


@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(final QueueMessageHandler messageHandler, final SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory) {
    final SimpleMessageListenerContainer msgListenerContainer = simpleMessageListenerContainerFactory.createSimpleMessageListenerContainer();
    msgListenerContainer.setMessageHandler(messageHandler);

    return msgListenerContainer;
}

@Bean
public DynamicQueueUrlDestinationResolver destinationResolver(final AmazonSQSAsync amazonSqs, final ResourceIdResolver resourceIdResolver) {
    DynamicQueueUrlDestinationResolver destinationResolver = new DynamicQueueUrlDestinationResolver(amazonSqs, resourceIdResolver);
    return destinationResolver;
}

@Bean
public QueueMessageHandlerFactory queueMessageHandlerFactory(final AmazonSQSAsync amazonSqs) {
    QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();
    factory.setAmazonSqs(amazonSqs);

    return factory;
}

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

带有属性占位符的 Spring Cloud AWS SQS SendTo 注释 的相关文章

随机推荐

  • 如何跨多个域重用代码?

    我只是使用 Yii 框架构建了一个 CMS 框架 我想将 CMS 部署到多个域 home root www domain1 com home root www domain2 com home root www domain3 com ho
  • linux 多端口监听socket

    我正在用 C linux 编写一个多线程服务器应用程序 它必须侦听 2 个不同的端口号 例如侦听端口号 3000 和 4000 以便连接到它的不同客户端提供不同的功能 实际功能由工作人员执行 线程 主线程无限期运行并在新连接上产生新工作线程
  • 跨域属性的目的...?

    在图像和脚本标签中 我的理解是您可以访问其他域上的脚本和图像 那么什么时候使用这个属性呢 这是当您想要限制其他人访问您的脚本和图像的能力时吗 Images https developer mozilla org en US docs Web
  • 使用 java 构建 wsdl 的框架或工具

    JAVA中有没有什么优秀的工具来处理webservice或wsdl 是的 有一个标准化的API JAX WS http en wikipedia org wiki JAX WS 甚至集成到 Java 标准 API javax xml ws包
  • 延迟加载 Facebook Like 按钮脚本

    Google pagespeed 正在抱怨我的 facebook 之类的按钮脚本 我怎样才能推迟脚本 在初始页面加载期间解析了 45KiB 的 JavaScript 延迟解析 JavaScript 用于减少页面渲染的阻塞 http stat
  • 如何使用多个 ssh 密钥 [重复]

    这个问题在这里已经有答案了 GitHub 用户 我是 github 的新手 并且在 git 设置方面遇到一些问题 我在 github 上有 2 个不同用户的帐户 并且我在系统上设置了 git 2 次 First ssh文件夹 像往常一样 包
  • Hibernate @Enumerated 似乎被忽略

    我有课Person使用带有枚举的注释进行映射Sex指的是性别 是男性还是女性 让我们来看看 Entity Table name PERSON public class Person Id GeneratedValue strategy Ge
  • 无需切换 selenium webdriver 即可获取窗口标题

    有没有办法在不进行任何硒切换的情况下获取窗口标题 目前我正在使用下面的代码 public boolean switchToWindowByTitle String title String currentWindow driver getW
  • 是否可以打开 regedit 并使用 process.start 直接导航到特定键?

    我正在制作一个小工具 可以在注册表中写入一个密钥 其中一小部分只是为了方便起见 只需单击一个按钮即可立即导航到该密钥 我已经知道如何打开 regedit exe 但是有没有办法立即导航到我需要的密钥 我正在尝试与 System Diagno
  • 无法将 HAProxy 实现为 HTTPS 的转发代理

    我正在尝试使用 HAProxy 作为转发代理 它适用于 HTTP 但不适用于 HTTPS 下面是我的 HTTP HAProxy 配置 listen forward http proxy bind 80 http request do res
  • Pivot_longer 6 列至 3 列

    我知道我的问题很简单 但我整个早上都在尝试 但我无法解决这个问题 我有这个数据框 GeneID Gene Symbol01 Ratio 2h Ratio 6h Ratio 10h Ratio 24h Pvalue 2h 1 174 FUT
  • JSF 2.0:如何用自定义渲染器覆盖基本渲染器?

    我正在尝试覆盖渲染器h selectBooleanCheckbox 出于所解释的原因here http www i coding de www en jsf bug selectbooleancheckbox converter html
  • 使用 json 从本地文件传递数据

    我正在尝试将数据从 JSON 文件传递 到简单的 ViewController 上 但我不知道在哪里实际传递该数据 我可以添加到我的setDataToJson方法或者我会将数据添加到我的viewDidLoad method 这是我的代码 i
  • 管理数据库更改的最佳方法[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 管理数据库更改的最佳方法是什么 无论数据库客户端的语言如何 我都需要有一个解决方案 另外 我希望能够在这些更改中使用特定的数据库功能
  • 将 Excel 文档转换为 wiki 标记 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 是否可以转换Excel http en wikipedia org wiki Microsoft Excel电子表格到媒体维基 htt
  • .NET MailMessage 类注入安全吗?

    我怀疑是否邮件留言 http msdn microsoft com en us library system net mail mailmessage aspx类受到保护电子邮件注入 http en wikipedia org wiki E
  • JS:反转数组,但仅反转原始数组 --> 错误:运行时没有输出

    我有以下问题 反转数组 编写一个接受数组并就地反转该数组的函数 该行为应该模仿本机 reverse 数组方法的行为 但是 您的反向函数应该接受要作为参数进行操作的数组 而不是作为该数组上的方法来调用 不要在您自己的实现中使用本机 rever
  • angularjs - 单击具有实际网址的链接时刷新

    我使用 RouteProvider 为我的 url 定义控制器和模板 当我单击与实际位置具有相同 URL 的链接时 没有任何反应 我想要reload 如果用户单击此类链接 即使位置未更改 也会调用该方法 换句话说 如果我将位置设置为相同的值
  • 通过nodejs服务器+socket.io从mp3文件同步流式传输音乐

    我的服务器上有一个 mp3 文件 我希望所有访问该网址的客户都能同步收听该音乐 That is 假设该文件播放 6 分钟 我在上午 10 00 开始播放这首歌 上午 10 03 发出的请求应从歌曲的第 3 分钟开始收听 我所有的客户都应该同
  • 带有属性占位符的 Spring Cloud AWS SQS SendTo 注释

    这个问题 https github com spring cloud spring cloud aws issues 65建议 SendTo 注释支持属性占位符 但我无法让它工作 这是我想要做的一些简化的代码片段 比尝试用文字解释更容易 我