com.amazonaws.services.sqs.model.Message.getReceiptHandle()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.amazonaws.services.sqs.model.Message.getReceiptHandle()方法的一些代码示例,展示了Message.getReceiptHandle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getReceiptHandle()方法的具体详情如下:
包路径:com.amazonaws.services.sqs.model.Message
类名称:Message
方法名:getReceiptHandle

Message.getReceiptHandle介绍

[英]An identifier associated with the act of receiving the message. A new receipt handle is returned every time you receive a message. When deleting a message, you provide the last received receipt handle to delete the message.
[中]与接收信息的行为相关联的标识符。每次收到消息时,都会返回一个新的接收句柄。删除邮件时,提供上次收到的回执句柄以删除邮件。

代码示例

代码示例来源:origin: aws/aws-sdk-java

private void deleteMessage(Message message) {
  try {
    sqs.deleteMessage(new DeleteMessageRequest(queueUrl, message.getReceiptHandle()));
  } catch (Exception e) {}
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
 * redacted from this string using a placeholder value.
 *
 * @return A string representation of this object.
 *
 * @see java.lang.Object#toString()
 */
@Override
public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append("{");
  if (getMessageId() != null)
    sb.append("MessageId: ").append(getMessageId()).append(",");
  if (getReceiptHandle() != null)
    sb.append("ReceiptHandle: ").append(getReceiptHandle()).append(",");
  if (getMD5OfBody() != null)
    sb.append("MD5OfBody: ").append(getMD5OfBody()).append(",");
  if (getBody() != null)
    sb.append("Body: ").append(getBody()).append(",");
  if (getAttributes() != null)
    sb.append("Attributes: ").append(getAttributes()).append(",");
  if (getMD5OfMessageAttributes() != null)
    sb.append("MD5OfMessageAttributes: ").append(getMD5OfMessageAttributes()).append(",");
  if (getMessageAttributes() != null)
    sb.append("MessageAttributes: ").append(getMessageAttributes());
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public int hashCode() {
  final int prime = 31;
  int hashCode = 1;
  hashCode = prime * hashCode + ((getMessageId() == null) ? 0 : getMessageId().hashCode());
  hashCode = prime * hashCode + ((getReceiptHandle() == null) ? 0 : getReceiptHandle().hashCode());
  hashCode = prime * hashCode + ((getMD5OfBody() == null) ? 0 : getMD5OfBody().hashCode());
  hashCode = prime * hashCode + ((getBody() == null) ? 0 : getBody().hashCode());
  hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode());
  hashCode = prime * hashCode + ((getMD5OfMessageAttributes() == null) ? 0 : getMD5OfMessageAttributes().hashCode());
  hashCode = prime * hashCode + ((getMessageAttributes() == null) ? 0 : getMessageAttributes().hashCode());
  return hashCode;
}

代码示例来源:origin: awsdocs/aws-doc-sdk-examples

public static void changeMessageVisibilitySingle(
    String queue_url, int timeout)
{
  AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
  // Get the receipt handle for the first message in the queue.
  String receipt = sqs.receiveMessage(queue_url)
            .getMessages()
            .get(0)
            .getReceiptHandle();
  sqs.changeMessageVisibility(queue_url, receipt, timeout);
}

代码示例来源:origin: Netflix/conductor

@VisibleForTesting
List<Message> receiveMessages() {
  try {
    ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest()
        .withQueueUrl(queueURL)
        .withVisibilityTimeout(visibilityTimeoutInSeconds)
        .withMaxNumberOfMessages(batchSize);
    ReceiveMessageResult result = client.receiveMessage(receiveMessageRequest);
    List<Message> messages = result.getMessages().stream()
        .map(msg -> new Message(msg.getMessageId(), msg.getBody(), msg.getReceiptHandle()))
        .collect(Collectors.toList());
    Monitors.recordEventQueueMessagesProcessed(QUEUE_TYPE, this.queueName, messages.size());
    return messages;
  } catch (Exception e) {
    logger.error("Exception while getting messages from SQS", e);
    Monitors.recordObservableQMessageReceivedErrors(QUEUE_TYPE);
  }
  return new ArrayList<>();
}

代码示例来源:origin: awsdocs/aws-doc-sdk-examples

public static void changeMessageVisibilityMultiple(
    String queue_url, int timeout)
{
  AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
  List<ChangeMessageVisibilityBatchRequestEntry> entries =
    new ArrayList<ChangeMessageVisibilityBatchRequestEntry>();
  entries.add(new ChangeMessageVisibilityBatchRequestEntry(
        "unique_id_msg1",
        sqs.receiveMessage(queue_url)
          .getMessages()
          .get(0)
          .getReceiptHandle())
      .withVisibilityTimeout(timeout));
  entries.add(new ChangeMessageVisibilityBatchRequestEntry(
        "unique_id_msg2",
        sqs.receiveMessage(queue_url)
          .getMessages()
          .get(0)
          .getReceiptHandle())
      .withVisibilityTimeout(timeout + 200));
  sqs.changeMessageVisibilityBatch(queue_url, entries);
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Nacks and clears all messages remaining in the batch.
 */
synchronized void clear() {
  if (!open) {
    throw new IllegalStateException("batch is not open");
  }
  if (!isExpired()) {
    ChangeMessageVisibilityBatchRequest batchRequest = new ChangeMessageVisibilityBatchRequest()
        .withQueueUrl(qUrl);
    ResultConverter.appendUserAgent(batchRequest, AmazonSQSBufferedAsyncClient.USER_AGENT);
    List<ChangeMessageVisibilityBatchRequestEntry> entries = new ArrayList<ChangeMessageVisibilityBatchRequestEntry>(
        messages.size());
    int i = 0;
    for (Message m : messages) {
      entries.add(new ChangeMessageVisibilityBatchRequestEntry().withId(Integer.toString(i))
          .withReceiptHandle(m.getReceiptHandle()).withVisibilityTimeout(0));
      ++i;
    }
    try {
      batchRequest.setEntries(entries);
      sqsClient.changeMessageVisibilityBatch(batchRequest);
    } catch (AmazonClientException e) {
      // Log and ignore.
      log.warn("ReceiveMessageBatchTask: changeMessageVisibility failed " + e);
    }
  }
  messages.clear();
}

代码示例来源:origin: apache/usergrid

LegacyQueueMessage queueMessage = new LegacyQueueMessage( message.getMessageId(), message.getReceiptHandle(), payload,
  message.getAttributes().get( "type" ) );
queueMessage.setStringBody( originalBody );

代码示例来源:origin: aws/aws-sdk-java

if (other.getMessageId() != null && other.getMessageId().equals(this.getMessageId()) == false)
  return false;
if (other.getReceiptHandle() == null ^ this.getReceiptHandle() == null)
  return false;
if (other.getReceiptHandle() != null && other.getReceiptHandle().equals(this.getReceiptHandle()) == false)
  return false;
if (other.getMD5OfBody() == null ^ this.getMD5OfBody() == null)

代码示例来源:origin: apache/nifi

attributes.put("hash.algorithm", "md5");
attributes.put("sqs.message.id", message.getMessageId());
attributes.put("sqs.receipt.handle", message.getReceiptHandle());
  final DeleteMessageBatchRequestEntry entry = new DeleteMessageBatchRequestEntry();
  entry.setId(message.getMessageId());
  entry.setReceiptHandle(message.getReceiptHandle());
  deleteRequestEntries.add(entry);

代码示例来源:origin: awsdocs/aws-doc-sdk-examples

sqs.deleteMessage(queueUrl, m.getReceiptHandle());

代码示例来源:origin: aws-amplify/aws-sdk-android

@Override
public int hashCode() {
  final int prime = 31;
  int hashCode = 1;
  hashCode = prime * hashCode + ((getMessageId() == null) ? 0 : getMessageId().hashCode());
  hashCode = prime * hashCode
      + ((getReceiptHandle() == null) ? 0 : getReceiptHandle().hashCode());
  hashCode = prime * hashCode + ((getMD5OfBody() == null) ? 0 : getMD5OfBody().hashCode());
  hashCode = prime * hashCode + ((getBody() == null) ? 0 : getBody().hashCode());
  hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode());
  hashCode = prime
      * hashCode
      + ((getMD5OfMessageAttributes() == null) ? 0 : getMD5OfMessageAttributes()
          .hashCode());
  hashCode = prime * hashCode
      + ((getMessageAttributes() == null) ? 0 : getMessageAttributes().hashCode());
  return hashCode;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * 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("{");
  if (getMessageId() != null)
    sb.append("MessageId: " + getMessageId() + ",");
  if (getReceiptHandle() != null)
    sb.append("ReceiptHandle: " + getReceiptHandle() + ",");
  if (getMD5OfBody() != null)
    sb.append("MD5OfBody: " + getMD5OfBody() + ",");
  if (getBody() != null)
    sb.append("Body: " + getBody() + ",");
  if (getAttributes() != null)
    sb.append("Attributes: " + getAttributes() + ",");
  if (getMD5OfMessageAttributes() != null)
    sb.append("MD5OfMessageAttributes: " + getMD5OfMessageAttributes() + ",");
  if (getMessageAttributes() != null)
    sb.append("MessageAttributes: " + getMessageAttributes());
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: aws-amplify/aws-sdk-android

.withReceiptHandle(m.getReceiptHandle())
    .withVisibilityTimeout(0));
++i;

代码示例来源:origin: aws-amplify/aws-sdk-android

&& other.getMessageId().equals(this.getMessageId()) == false)
  return false;
if (other.getReceiptHandle() == null ^ this.getReceiptHandle() == null)
  return false;
if (other.getReceiptHandle() != null
    && other.getReceiptHandle().equals(this.getReceiptHandle()) == false)
  return false;
if (other.getMD5OfBody() == null ^ this.getMD5OfBody() == null)

代码示例来源:origin: aws-amplify/aws-sdk-android

request.addParameter(prefix, StringUtils.fromString(messageId));
if (_message.getReceiptHandle() != null) {
  prefix = _prefix + "ReceiptHandle";
  String receiptHandle = _message.getReceiptHandle();
  request.addParameter(prefix, StringUtils.fromString(receiptHandle));

代码示例来源:origin: org.springframework.cloud/spring-cloud-aws-messaging

private org.springframework.messaging.Message<String> getMessageForExecution() {
    HashMap<String, Object> additionalHeaders = new HashMap<>();
    additionalHeaders.put(QueueMessageHandler.LOGICAL_RESOURCE_ID, this.logicalQueueName);
    if (this.deletionPolicy == SqsMessageDeletionPolicy.NEVER) {
      String receiptHandle = this.message.getReceiptHandle();
      QueueMessageAcknowledgment acknowledgment = new QueueMessageAcknowledgment(SimpleMessageListenerContainer.this.getAmazonSqs(), this.queueUrl, receiptHandle);
      additionalHeaders.put(QueueMessageHandler.ACKNOWLEDGMENT, acknowledgment);
    }
    additionalHeaders.put(QueueMessageHandler.VISIBILITY, new QueueMessageVisibility(SimpleMessageListenerContainer.this.getAmazonSqs(), this.queueUrl, this.message.getReceiptHandle()));
    return createMessage(this.message, additionalHeaders);
  }
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-glacier

private void deleteMessage(Message message) {
  try {
    sqs.deleteMessage(new DeleteMessageRequest(queueUrl, message.getReceiptHandle()));
  } catch (Exception e) {}
}

代码示例来源:origin: spring-cloud/spring-cloud-aws

public static Message<String> createMessage(com.amazonaws.services.sqs.model.Message message, Map<String, Object> additionalHeaders) {
  HashMap<String, Object> messageHeaders = new HashMap<>();
  messageHeaders.put(MESSAGE_ID_MESSAGE_ATTRIBUTE_NAME, message.getMessageId());
  messageHeaders.put(RECEIPT_HANDLE_MESSAGE_ATTRIBUTE_NAME, message.getReceiptHandle());
  messageHeaders.putAll(additionalHeaders);
  messageHeaders.putAll(getAttributesAsMessageHeaders(message));
  messageHeaders.putAll(getMessageAttributesAsMessageHeaders(message));
  return new GenericMessage<>(message.getBody(), new SqsMessageHeaders(messageHeaders));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-amazon-web-services

void delete(final Collection<Message> messages) {
 for (Message message : messages) {
  if (messagesToDelete.contains(message)) {
   source.getSqs().deleteMessage(source.getRead().queueUrl(), message.getReceiptHandle());
   Instant currentMessageTimestamp = getTimestamp(message);
   if (currentMessageTimestamp.isAfter(oldestPendingTimestamp)) {
    oldestPendingTimestamp = currentMessageTimestamp;
   }
  }
 }
}

相关文章