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

x33g5p2x  于2022-01-29 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(103)

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

ReceiveMessageRequest.withMessageAttributeNames介绍

[英]The name of the message attribute, where N is the index.

  • The name can contain alphanumeric characters and the underscore (_), hyphen (-), and period (.).
  • The name is case-sensitive and must be unique among all attribute names for the message.
  • The name must not start with AWS-reserved prefixes such as AWS. or Amazon. (or any casing variants).
  • The name must not start or end with a period (.), and it should not have periods in succession ( ..).
  • The name can be up to 256 characters long.

When using ReceiveMessage, you can send a list of attribute names to receive, or you can return all of the attributes by specifying All or .* in your request. You can also use all message attributes starting with a prefix, for example bar.*.
[中]消息属性的名称,其中N是索引。
*名称可以包含字母数字字符和下划线(_、连字符(-)和句点(.)。
*名称区分大小写,并且在消息的所有属性名称中必须是唯一的。
*名称不得以AWS保留前缀开头,例如AWS.Amazon.(或任何大小写变体)。
*名称不得以句点(.开头或结尾,且不应连续出现句点(..)。
*名称最长可达256个字符。
使用ReceiveMessage时,可以发送要接收的属性名称列表,也可以通过在请求中指定All.*返回所有属性。您还可以使用以前缀开头的所有消息属性,例如bar.*

代码示例

代码示例来源:origin: com.netflix.spinnaker.echo/echo-pubsub-aws

private void listenForMessages() {
 while (isEnabled.get()) {
  ReceiveMessageResult receiveMessageResult = amazonSQS.receiveMessage(
   new ReceiveMessageRequest(queueId)
    .withMaxNumberOfMessages(AWS_MAX_NUMBER_OF_MESSAGES)
    .withVisibilityTimeout(subscription.getVisibilityTimeout())
    .withWaitTimeSeconds(subscription.getWaitTimeSeconds())
    .withMessageAttributeNames("All")
  );
  if (receiveMessageResult.getMessages().isEmpty()) {
   log.debug("Received no messages for queue: {}", queueARN);
   continue;
  }
  receiveMessageResult.getMessages().forEach(this::handleMessage);
 }
}

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

@Override
public Message<String> receive(long timeout) {
  ReceiveMessageResult receiveMessageResult = this.amazonSqs.receiveMessage(
      new ReceiveMessageRequest(this.queueUrl).
          withMaxNumberOfMessages(1).
          withWaitTimeSeconds(Long.valueOf(timeout).intValue()).
          withAttributeNames(ATTRIBUTE_NAMES).
          withMessageAttributeNames(MESSAGE_ATTRIBUTE_NAMES));
  if (receiveMessageResult.getMessages().isEmpty()) {
    return null;
  }
  com.amazonaws.services.sqs.model.Message amazonMessage = receiveMessageResult.getMessages().get(0);
  Message<String> message = createMessage(amazonMessage);
  this.amazonSqs.deleteMessage(new DeleteMessageRequest(this.queueUrl, amazonMessage.getReceiptHandle()));
  return message;
}

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

@Override
public Message<String> receive(long timeout) {
  ReceiveMessageResult receiveMessageResult = this.amazonSqs.receiveMessage(
      new ReceiveMessageRequest(this.queueUrl).
          withMaxNumberOfMessages(1).
          withWaitTimeSeconds(Long.valueOf(timeout).intValue()).
          withAttributeNames(ATTRIBUTE_NAMES).
          withMessageAttributeNames(MESSAGE_ATTRIBUTE_NAMES));
  if (receiveMessageResult.getMessages().isEmpty()) {
    return null;
  }
  com.amazonaws.services.sqs.model.Message amazonMessage = receiveMessageResult.getMessages().get(0);
  Message<String> message = createMessage(amazonMessage);
  this.amazonSqs.deleteMessage(new DeleteMessageRequest(this.queueUrl, amazonMessage.getReceiptHandle()));
  return message;
}

代码示例来源:origin: awslabs/amazon-sqs-java-messaging-lib

.withMaxNumberOfMessages(prefetchBatchSize)
.withAttributeNames(ALL)
.withMessageAttributeNames(ALL)
.withWaitTimeSeconds(WAIT_TIME_SECONDS);

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

public ReceiveMessageRequest getReceiveMessageRequest() {
  ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(this.destinationUrl).
      withAttributeNames(RECEIVING_ATTRIBUTES).
      withMessageAttributeNames(RECEIVING_MESSAGE_ATTRIBUTES);
  if (this.maxNumberOfMessages != null) {
    receiveMessageRequest.withMaxNumberOfMessages(this.maxNumberOfMessages);
  } else {
    receiveMessageRequest.withMaxNumberOfMessages(DEFAULT_MAX_NUMBER_OF_MESSAGES);
  }
  if (this.visibilityTimeout != null) {
    receiveMessageRequest.withVisibilityTimeout(this.visibilityTimeout);
  }
  if (this.waitTimeOut != null) {
    receiveMessageRequest.setWaitTimeSeconds(this.waitTimeOut);
  }
  return receiveMessageRequest;
}

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

public ReceiveMessageRequest getReceiveMessageRequest() {
  ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(this.destinationUrl).
      withAttributeNames(RECEIVING_ATTRIBUTES).
      withMessageAttributeNames(RECEIVING_MESSAGE_ATTRIBUTES);
  if (this.maxNumberOfMessages != null) {
    receiveMessageRequest.withMaxNumberOfMessages(this.maxNumberOfMessages);
  } else {
    receiveMessageRequest.withMaxNumberOfMessages(DEFAULT_MAX_NUMBER_OF_MESSAGES);
  }
  if (this.visibilityTimeout != null) {
    receiveMessageRequest.withVisibilityTimeout(this.visibilityTimeout);
  }
  if (this.waitTimeOut != null) {
    receiveMessageRequest.setWaitTimeSeconds(this.waitTimeOut);
  }
  return receiveMessageRequest;
}

代码示例来源:origin: com.amazonaws/amazon-sqs-java-messaging-lib

.withMaxNumberOfMessages(prefetchBatchSize)
.withAttributeNames(ALL)
.withMessageAttributeNames(ALL)
.withWaitTimeSeconds(WAIT_TIME_SECONDS);

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

@Bean
public AmazonSQSAsync amazonSqs() {
  AmazonSQSAsync sqs = mock(AmazonSQSAsync.class);
  given(sqs.getQueueUrl(new GetQueueUrlRequest("testQueue")))
      .willReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com"));
  given(sqs.receiveMessage(new ReceiveMessageRequest("http://testQueue.amazonaws.com")
      .withAttributeNames("All")
      .withMessageAttributeNames("All")
      .withMaxNumberOfMessages(10)
      .withWaitTimeSeconds(20)))
      .willReturn(new ReceiveMessageResult()
          .withMessages(new Message().withBody("messageContent"),
              new Message().withBody("messageContent2")))
      .willReturn(new ReceiveMessageResult());
  given(sqs.getQueueAttributes(any(GetQueueAttributesRequest.class)))
      .willReturn(new GetQueueAttributesResult());
  return sqs;
}

相关文章

微信公众号

最新文章

更多