gpt4 book ai didi

amazon-web-services - Spring Cloud for AWS - 如何转换从 SQS 接收并由 S3 发送的消息

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

我已将 S3 配置为在每次上传文件时触发一个事件。该事件将发送至 SQS。现在我想使用 Spring Cloud for AWS 从队列中读取消息。有没有办法将有效负载转换为表示 S3 事件记录的已知类型?我尝试过

package com.test;
import java.util.Map;

import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.MessageMapping;

import com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord;

public class SQSHandler {
@MessageMapping("MediaQueue")
private void receiveMessage(S3EventNotificationRecord message, @Headers Map<String, String> headers) {
System.out.println("MYK MYK MYK");
}
}

但我收到错误

ord, message=GenericMessage [payload={here was whole payload}] at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:115) at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:137) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:106) at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:447) ... 8 more

你知道有什么方法可以做这样的事情吗?

最佳答案

问题的解决方案如下:

 import com.amazonaws.services.s3.event.S3EventNotification;

@MessageMapping("${mediaQueueName}")
private void receiveMessage(String message, @Header(value = "MessageId") String messageId) {
S3EventNotification notification = S3EventNotification.parseJson(message);
//do whatever you need
}

关于amazon-web-services - Spring Cloud for AWS - 如何转换从 SQS 接收并由 S3 发送的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35095986/

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