簡體   English   中英

Amazon AWS SQS Java - 屬性為空

[英]Amazon AWS SQS Java - Attributes Null

我正在嘗試從正在處理的每條消息中提取 AWS SQS 消息屬性。 我已驗證該屬性是否存在並且所有內容都拼寫正確:名稱:RequestId 值:thisistherequestid

我以這種方式收到消息:

messages = sqs.receiveMessage(request.withQueueUrl(queueUrl).withAttributeNames("All")).getMessages()

我也試過:

messages = sqs.receiveMessage(request.withQueueUrl(queueUrl).withAttributeNames("RequestId")).getMessages()

我已經嘗試了這兩件事,但每次都返回 null。

        for (Message m : messages) {
            Map<String, MessageAttributeValue> attributeValues = new HashMap<String, MessageAttributeValue>();
            attributeValues = m.getMessageAttributes();
            System.out.println("Attribute Values ===>  " + attributeValues.get("RequestId").getStringValue());

我也試過:

        for (Message m : messages) {
            Map<String, String> attributeValues = new HashMap<String, String>();
            attributeValues = m.getAttributes();
            System.out.println("Attribute Values ===>  " + attributeValues.get("RequestId"));

我不太確定這里出了什么問題..即使你只是這樣做,屬性也是空的:

            attributeValues = m.getMessageAttributes();
            System.out.println("Attribute Values ===>  " + attributeValues);

知道我可能做錯了什么嗎?

這是我在 AWS 控制台中看到的內容:

在此處輸入圖片說明

您設置的是 sqs 中的消息屬性。 因此,在檢索時,您必須使用以下代碼。

messages = sqs.receiveMessage(request.withQueueUrl(queueUrl).withMessageAttributeNames("RequestId")).getMessages()

這將獲取名稱為RequestId的消息屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM