这是我的 SQS 监听器类:
@RequiredArgsConstructor
@Slf4j
@Service
public class SQSS3CreatedNotificationService {
private final FluxProperties fluxProperties;
private final ConsolidateDocumentInputPort consolidateDocumentInputPort;
@SqsListener("#{fluxProperties.getS3CreatedNotificationQueueName()}")
public void listen(final Message s3EventNotification) {
log.trace("Message received: {}", s3EventNotification.body());
consolidateDocumentInputPort.consolidate(UUID.randomUUID());
}
}
如您所见,我使用
Message
类参数来接收 SQS 消息。
这是 sqs 消息,是一个 S3 事件。我在这里写下
log.trace("Message received: {}", s3EventNotification.body());
格式化输出:
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "2024-02-16T13:35:26.982Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "AIDAJDPLRKLG7UEXAMPLE"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "234d0f2e",
"x-amz-id-2": "eftixk72aD6Ap51TnqcoF8eFidJG9Z/2"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "38240f0e",
"bucket": {
"name": "espaidoc",
"ownerIdentity": {
"principalId": "A3NL1KOZZKExample"
},
"arn": "arn:aws:s3:::espaidoc"
},
"object": {
"key": "references/reference1.sha",
"sequencer": "0055AED6DCD90281E5",
"size": 2333,
"eTag": "1d11469e9d81f07729548d7708bbab82"
}
}
}
]
}
我不太清楚是否可以将其序列化为 sdk 上已定义的类。
如果您想在这里反序列化主体,我只是有同样的问题:
对我有帮助的答案是将
com.amazonaws.services.s3.event.S3EventNotification
与 S3EventNotification.parseJson
一起使用