在我们的代码中,我们从 sqs 队列中删除一条消息并获取 deletResponse
。
String deleteResponse = sqsClient.deleteMessage(simBridge2ESBUrl, message.getReceiptHandle()).toString();
此调用后消息被删除,但 deleteResponse
始终为 {}
。所以我们检查了源代码,发现 DeleteMessageResult::toString
函数只返回 {}
。
以下是 AWS 源代码。 toString()
和hashCode()
函数看起来很奇怪。源代码有错误还是我做错了?谢谢。
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights
* Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.services.sqs.model;
import java.io.Serializable;
/**
*
*/
public class DeleteMessageResult implements Serializable, Cloneable {
/**
* Returns a string representation of this object; useful for testing and
* debugging.
*
* @return A string representation of this object.
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("}");
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj instanceof DeleteMessageResult == false)
return false;
DeleteMessageResult other = (DeleteMessageResult) obj;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int hashCode = 1;
return hashCode;
}
@Override
public DeleteMessageResult clone() {
try {
return (DeleteMessageResult) super.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(
"Got a CloneNotSupportedException from Object.clone() "
+ "even though we're Cloneable!", e);
}
}
}
最佳答案
从编程的角度来看,toString()
是正确编写的。想想这个函数做了什么:
A string representation of this object.
因为 DeleteMessageResult
类没有属性,所以没有什么可以返回的。这同样适用于 hashCode()
。 DeleteMessageResult
的两个对象始终相同,因此它们每次都具有相同的哈希值。
话虽如此,我确实认为 DeleteMessageResult
应该包含具有唯一 RequestId
的 ResposeMetadata
,如 API reference 中所示:
<DeleteMessageResponse>
<ResponseMetadata>
<RequestId>
b5293cb5-d306-4a17-9048-b263635abe42
</RequestId>
</ResponseMetadata>
</DeleteMessageResponse>
所以,是的,这个类可以(可能,应该)被修补以完全支持 SQS API。
关于java - AWS 源代码错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41307904/