当前位置: 首页>>代码示例>>Java>>正文


Java SendMessageResult类代码示例

本文整理汇总了Java中com.amazonaws.services.sqs.model.SendMessageResult的典型用法代码示例。如果您正苦于以下问题:Java SendMessageResult类的具体用法?Java SendMessageResult怎么用?Java SendMessageResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SendMessageResult类属于com.amazonaws.services.sqs.model包,在下文中一共展示了SendMessageResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSend

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void testSend() throws Exception {
    BasicSQSMsgSender msgSender =
        new BasicSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey");

    Channel mockChannel = mock(Channel.class);
    Event mockEvent = mock(Event.class);
    when(mockEvent.getBody()).thenReturn("This is a test event message".getBytes());
    when(mockChannel.take()).thenReturn(mockEvent);

    AmazonSQS mockSqs = mock(AmazonSQS.class);
    when(mockSqs.sendMessage(any(SendMessageRequest.class))).thenReturn(new SendMessageResult());
    msgSender.setAmazonSQS(mockSqs);

    int eventCount = msgSender.send(mockChannel);
    assertEquals(1, eventCount);
}
 
开发者ID:dpandya,项目名称:flume-ng-aws-sqs-sink,代码行数:18,代码来源:BasicSQSMsgSenderTest.java

示例2: testSendEventWithEmptyBody

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void testSendEventWithEmptyBody() throws Exception {
    BasicSQSMsgSender msgSender =
        new BasicSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey");

    Channel mockChannel = mock(Channel.class);
    Event mockEvent = mock(Event.class);
    when(mockEvent.getBody()).thenReturn("".getBytes());
    when(mockChannel.take()).thenReturn(mockEvent);

    AmazonSQS mockSqs = mock(AmazonSQS.class);
    when(mockSqs.sendMessage(any(SendMessageRequest.class))).thenReturn(new SendMessageResult());
    msgSender.setAmazonSQS(mockSqs);

    int eventCount = msgSender.send(mockChannel);
    assertEquals(0, eventCount);
}
 
开发者ID:dpandya,项目名称:flume-ng-aws-sqs-sink,代码行数:18,代码来源:BasicSQSMsgSenderTest.java

示例3: testShouldGetFailedResponseAfterSendingTheEvent

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void testShouldGetFailedResponseAfterSendingTheEvent() {
    final GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult();
    getQueueUrlResult.setQueueUrl(randomAlphabetic(10));

    final SendMessageResult sendMessageResult = new SendMessageResult();

    final SdkHttpMetadata responseMetadata = mock(SdkHttpMetadata.class);
    when(responseMetadata.getHttpStatusCode()).thenReturn(400);
    sendMessageResult.setSdkHttpMetadata(responseMetadata);

    when(amazonSQS.sendMessage(any(SendMessageRequest.class))).thenThrow(new RuntimeException("expected"));

    assertThatThrownBy(() ->
                                    sqsErrorHandler.onError(randomAlphabetic(10), new RuntimeException(),
                                        EventTypePartition.of(EventType.of(randomAlphabetic(10)),
                                            randomAlphabetic(1)), randomNumeric(10), randomAlphabetic(50)))
        .isInstanceOf(RuntimeException.class).hasMessageContaining("expected");
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:20,代码来源:SQSErrorHandlerTest.java

示例4: testShouldSendEventToSQS

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void testShouldSendEventToSQS() throws JsonProcessingException {
    final SendMessageResult sendMessageResult = new SendMessageResult();

    final SdkHttpMetadata responseMetadata = mock(SdkHttpMetadata.class);
    when(responseMetadata.getHttpStatusCode()).thenReturn(200);
    sendMessageResult.setSdkHttpMetadata(responseMetadata);

    when(amazonSQS.sendMessage(any(SendMessageRequest.class))).thenReturn(sendMessageResult);

    sqsErrorHandler.onError(randomAlphabetic(10), new RuntimeException(),
        EventTypePartition.of(EventType.of(randomAlphabetic(10)), randomAlphabetic(1)), randomNumeric(10),
        randomAlphabetic(50));

    verify(objectMapper).writeValueAsString(anyString());
    verify(amazonSQS).sendMessage(any(SendMessageRequest.class));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:18,代码来源:SQSErrorHandlerTest.java

示例5: process

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    String body = exchange.getIn().getBody(String.class);
    SendMessageRequest request = new SendMessageRequest(getQueueUrl(), body);
    request.setMessageAttributes(translateAttributes(exchange.getIn().getHeaders(), exchange));
    addDelay(request, exchange);

    LOG.trace("Sending request [{}] from exchange [{}]...", request, exchange);
    
    SendMessageResult result = getClient().sendMessage(request);
    
    LOG.trace("Received result [{}]", result);
    
    Message message = getMessageForResponse(exchange);
    message.setHeader(SqsConstants.MESSAGE_ID, result.getMessageId());
    message.setHeader(SqsConstants.MD5_OF_BODY, result.getMD5OfMessageBody());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:SqsProducer.java

示例6: setup

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    underTest = new SqsProducer(sqsEndpoint);
    sendMessageResult = new SendMessageResult().withMD5OfMessageBody(MESSAGE_MD5).withMessageId(MESSAGE_ID);
    sqsConfiguration = new SqsConfiguration();
    HeaderFilterStrategy headerFilterStrategy = new SqsHeaderFilterStrategy();
    sqsConfiguration.setDelaySeconds(Integer.valueOf(0));
    when(sqsEndpoint.getClient()).thenReturn(amazonSQSClient);
    when(sqsEndpoint.getConfiguration()).thenReturn(sqsConfiguration);
    when(amazonSQSClient.sendMessage(any(SendMessageRequest.class))).thenReturn(sendMessageResult);
    when(exchange.getOut()).thenReturn(outMessage);
    when(exchange.getIn()).thenReturn(inMessage);
    when(exchange.getPattern()).thenReturn(ExchangePattern.InOnly);
    when(inMessage.getBody(String.class)).thenReturn(SAMPLE_MESSAGE_BODY);
    when(sqsEndpoint.getQueueUrl()).thenReturn(QUEUE_URL);
    when(sqsEndpoint.getHeaderFilterStrategy()).thenReturn(headerFilterStrategy);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SqsProducerTest.java

示例7: sendMessage

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Override
public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) throws AmazonServiceException, AmazonClientException {
    Message message = new Message();
    message.setBody(sendMessageRequest.getMessageBody());
    message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
    message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
    message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5zC9+4QMqJZ0DJ3gVOmjI2Gh/oFnb0IeJqy5Zc8kH4JX7GVpfjcEDjaAPSeOkXQZRcaBqt"
            + "4lOtyfj0kcclVV/zS7aenhfhX5Ixfgz/rHhsJwtCPPvTAdgQFGYrqaHly+etJiawiNPVc=");
 
    synchronized (messages) {
        messages.add(message);
    }
    
    SendMessageResult result = new SendMessageResult();
    result.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
    result.setMD5OfMessageBody("6a1559560f67c5e7a7d5d838bf0272ee");
    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:AmazonSQSClientMock.java

示例8: sendMessage

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Override
public SendMessageResult sendMessage(AwsParamsDto awsParamsDto, String queueName, String messageText, List<MessageHeader> messageHeaders)
{
    Map<String, MessageAttributeValue> messageAttributes = null;

    if (CollectionUtils.isNotEmpty(messageHeaders))
    {
        messageAttributes = new HashMap<>();

        for (MessageHeader messageHeader : messageHeaders)
        {
            messageAttributes.put(messageHeader.getKey(), new MessageAttributeValue().withDataType("String").withStringValue(messageHeader.getValue()));
        }
    }

    return sqsOperations.sendMessage(queueName, messageText, messageAttributes, awsClientFactory.getAmazonSQSClient(awsParamsDto));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:18,代码来源:SqsDaoImpl.java

示例9: sendMessage

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Override
public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS)
{
    // Throw a throttling exception for a specific queue name for testing purposes.
    if (queueName.equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION))
    {
        AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception");
        throttlingException.setErrorCode("ThrottlingException");
        throw throttlingException;
    }

    // Throw an illegal state exception for a specific queue name for testing purposes.
    if (queueName.equals(MOCK_SQS_QUEUE_NOT_FOUND_NAME))
    {
        throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName));
    }

    // Nothing else to do in the normal case since our unit tests aren't reading messages once they have been published.
    return new SendMessageResult().withMessageId(AbstractDaoTest.MESSAGE_ID);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:21,代码来源:MockSqsOperationsImpl.java

示例10: testSendMessage

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void testSendMessage()
{
    // Send an SQS message.
    assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID),
        sqsDao.sendMessage(new AwsParamsDto(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, NO_MESSAGE_HEADERS));

    // Send an SQS message using proxy settings.
    assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao
        .sendMessage(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT), AWS_SQS_QUEUE_NAME,
            MESSAGE_TEXT, NO_MESSAGE_HEADERS));

    // Publish an SQS message with message headers.
    assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID),
        sqsDao.sendMessage(new AwsParamsDto(), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:17,代码来源:SqsDaoTest.java

示例11: write

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Override
public void write(byte[] bytes) throws IOException {
  if (bytes == null || bytes.length == 0) {
    return;
  }

  final String msg = new String(bytes);

  if (bytes.length > maxMessageSizeInKB * 1024) {
    addWarn(format("Logging event '%s' exceeds the maximum size of %dkB",
        msg, maxMessageSizeInKB));
    return;
  }

  sqs.sendMessageAsync(new SendMessageRequest(queueUrl, msg),
      new AsyncHandler<SendMessageRequest, SendMessageResult>() {
        public void onError(Exception exception) {
          addWarn(format("Appender '%s' failed to send logging event '%s' to '%s'", getName(), msg, queueUrl), exception);
        }
        public void onSuccess(SendMessageRequest request, SendMessageResult result) {
          /** noop **/
        }
      });
}
 
开发者ID:scizeron,项目名称:logback-sqs,代码行数:25,代码来源:SqsAppender.java

示例12: testSendReceiveDelete

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
/**
 * Tests a simple send, receive and delete of a message from the queue
 * resource. Asserts the message contents and its associated attributes.
 */
@Test
@Ignore
public void testSendReceiveDelete() throws InterruptedException {
    SendMessageResult sendMessageResult = queue.sendMessage(TEST_MESSAGE);
    assertNotNull(sendMessageResult);
    assertNotNull(sendMessageResult.getMessageId());

    List<Message> messages = waitForMessagesFromQueue(null);

    assertNotNull(messages);
    assertEquals(1, messages.size());
    Message message = messages.get(0);
    assertMessage(TEST_MESSAGE, sendMessageResult.getMessageId(),
            sendMessageResult.getMD5OfMessageBody(), message);

    queue.deleteMessages(new DeleteMessageBatchRequest()
            .withEntries(new DeleteMessageBatchRequestEntry("msg1", message
                    .getReceiptHandle())));
}
 
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:24,代码来源:SQSResourcesIntegrationTest.java

示例13: sendMessage_validTextMessage_returnsTrue

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void sendMessage_validTextMessage_returnsTrue() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
    when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());

    Message<String> stringMessage = MessageBuilder.withPayload("message content").build();
    MessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    boolean sent = messageChannel.send(stringMessage);

    // Assert
    verify(amazonSqs, only()).sendMessage(any(SendMessageRequest.class));
    assertEquals("message content", sendMessageRequestArgumentCaptor.getValue().getMessageBody());
    assertTrue(sent);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java

示例14: sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
    String mimeTypeAsString = new MimeType("test", "plain", Charset.forName("UTF-8")).toString();
    Message<String> message = MessageBuilder.withPayload("Hello").setHeader(MessageHeaders.CONTENT_TYPE, mimeTypeAsString).build();

    ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
    when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(mimeTypeAsString, sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(MessageHeaders.CONTENT_TYPE).getStringValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java

示例15: sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute

import com.amazonaws.services.sqs.model.SendMessageResult; //导入依赖的package包/类
@Test
public void sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
    MimeType mimeType = new MimeType("test", "plain", Charset.forName("UTF-8"));
    Message<String> message = MessageBuilder.withPayload("Hello").setHeader(MessageHeaders.CONTENT_TYPE, mimeType).build();

    ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
    when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(mimeType.toString(), sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(MessageHeaders.CONTENT_TYPE).getStringValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java


注:本文中的com.amazonaws.services.sqs.model.SendMessageResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。