本文整理汇总了Java中com.amazonaws.services.sqs.model.SendMessageRequest类的典型用法代码示例。如果您正苦于以下问题:Java SendMessageRequest类的具体用法?Java SendMessageRequest怎么用?Java SendMessageRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SendMessageRequest类属于com.amazonaws.services.sqs.model包,在下文中一共展示了SendMessageRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPurgeQueue_shouldRemoveAll
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Test
public void testPurgeQueue_shouldRemoveAll() {
// create queue
CreateQueueResult createdQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-earl-grey-queue"));
// send messages
String messageBody = "{\"life-universe-everything\":42}";
sqs.sendMessage(new SendMessageRequest().withDelaySeconds(0).withMessageBody(messageBody)
.withMessageGroupId("some-group-id-123").withQueueUrl(createdQueue.getQueueUrl()));
String messageBody2 = "{\"dead-emptyness-nothing\":24}";
sqs.sendMessage(new SendMessageRequest().withDelaySeconds(0).withMessageBody(messageBody2)
.withMessageGroupId("some-group-id-123").withQueueUrl(createdQueue.getQueueUrl()));
// purge queues
PurgeQueueResult result = sqs.purgeQueue(new PurgeQueueRequest().withQueueUrl(createdQueue.getQueueUrl()));
assertNotNull("verify that purge queue returned ok", result);
// verify empty queue
ReceiveMessageResult messageResult = sqs.receiveMessage(new ReceiveMessageRequest()
.withMaxNumberOfMessages(9).withQueueUrl(createdQueue.getQueueUrl()).withVisibilityTimeout(10)
.withWaitTimeSeconds(0));
assertEquals("verify that queue is empty", 0, messageResult.getMessages().size());
// cleanup
getQueues().remove("tea-earl-grey-queue");
}
示例2: processObjects
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
private boolean processObjects(List<S3ObjectSummary> objects) {
Logger.Debug("Scanning next batch of %s ", objects.size());
objects
.parallelStream()
.filter(this::shouldEnqueue)
.forEach(object -> {
numSeen.incrementAndGet();
String path = object.getBucketName() + "/" + object.getKey();
Logger.Info("Posting: %s", path);
SendMessageRequest msg = new SendMessageRequest()
.withQueueUrl(queueUrl)
.withMessageBody(path);
sqs.sendMessage(msg);
});
if (max > -1L && numSeen.incrementAndGet() > max) {
Logger.Info("Added max jobs, quitting");
return false;
}
return true;
}
示例3: send
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Override
public int send(Channel channel) throws EventDeliveryException {
int eventProcessedCounter = 0;
Event event = channel.take();
if (event == null || event.getBody().length == 0) {
// Don't bother with anything if the channel returns null event or an event with empty body
return eventProcessedCounter;
}
try {
this.amazonSQS.sendMessage(new SendMessageRequest(sqsUrl, new String(event.getBody(), "UTF-8").trim()));
// This event is processed successfully to increment the counter
eventProcessedCounter++;
}
catch (AmazonServiceException ase) {
throw new EventDeliveryException("Failure sending message request to Amazon SQS, " +
"the request made it to SQS but was rejected for some reason.", ase);
}
catch (AmazonClientException ace) {
throw new EventDeliveryException("Failure sending message request to Amazon SQS.", ace);
}
catch (UnsupportedEncodingException e) {
throw new EventDeliveryException("Character set UTF-8 not supported.", e);
}
return eventProcessedCounter;
}
示例4: testSend
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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);
}
示例5: testSendEventWithEmptyBody
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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);
}
示例6: testSendFailureAmazonServiceException
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testSendFailureAmazonServiceException() 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)))
.thenThrow(new AmazonServiceException("Mock AmazonServiceException"));
msgSender.setAmazonSQS(mockSqs);
msgSender.send(mockChannel);
}
示例7: testSendFailureAmazonClientException
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testSendFailureAmazonClientException() 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)))
.thenThrow(new AmazonClientException("Mock AmazonClientException"));
msgSender.setAmazonSQS(mockSqs);
msgSender.send(mockChannel);
}
示例8: testShouldGetFailedResponseAfterSendingTheEvent
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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");
}
示例9: testShouldSendEventToSQS
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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));
}
示例10: process
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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());
}
示例11: setup
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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);
}
示例12: isAttributeMessageStringHeaderOnTheRequest
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Test
public void isAttributeMessageStringHeaderOnTheRequest() throws Exception {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(SAMPLE_MESSAGE_HEADER_NAME_1, SAMPLE_MESSAGE_HEADER_VALUE_1);
when(inMessage.getHeaders()).thenReturn(headers);
underTest.process(exchange);
ArgumentCaptor<SendMessageRequest> capture = ArgumentCaptor.forClass(SendMessageRequest.class);
verify(amazonSQSClient).sendMessage(capture.capture());
assertEquals(SAMPLE_MESSAGE_HEADER_VALUE_1,
capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_1)
.getStringValue());
assertNull(capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_1)
.getBinaryValue());
}
示例13: isAttributeMessageByteBufferHeaderOnTheRequest
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Test
public void isAttributeMessageByteBufferHeaderOnTheRequest() throws Exception {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(SAMPLE_MESSAGE_HEADER_NAME_2, SAMPLE_MESSAGE_HEADER_VALUE_2);
when(inMessage.getHeaders()).thenReturn(headers);
underTest.process(exchange);
ArgumentCaptor<SendMessageRequest> capture = ArgumentCaptor.forClass(SendMessageRequest.class);
verify(amazonSQSClient).sendMessage(capture.capture());
assertEquals(SAMPLE_MESSAGE_HEADER_VALUE_2,
capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_2)
.getBinaryValue());
assertNull(capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_2)
.getStringValue());
}
示例14: isAllAttributeMessagesOnTheRequest
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的package包/类
@Test
public void isAllAttributeMessagesOnTheRequest() throws Exception {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(SAMPLE_MESSAGE_HEADER_NAME_1, SAMPLE_MESSAGE_HEADER_VALUE_1);
headers.put(SAMPLE_MESSAGE_HEADER_NAME_2, SAMPLE_MESSAGE_HEADER_VALUE_2);
headers.put(SAMPLE_MESSAGE_HEADER_NAME_3, SAMPLE_MESSAGE_HEADER_VALUE_3);
headers.put(SAMPLE_MESSAGE_HEADER_NAME_4, SAMPLE_MESSAGE_HEADER_VALUE_4);
when(inMessage.getHeaders()).thenReturn(headers);
underTest.process(exchange);
ArgumentCaptor<SendMessageRequest> capture = ArgumentCaptor.forClass(SendMessageRequest.class);
verify(amazonSQSClient).sendMessage(capture.capture());
assertEquals(SAMPLE_MESSAGE_HEADER_VALUE_1,
capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_1)
.getStringValue());
assertEquals(SAMPLE_MESSAGE_HEADER_VALUE_2,
capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_2)
.getBinaryValue());
assertEquals(SAMPLE_MESSAGE_HEADER_VALUE_3,
capture.getValue().getMessageAttributes().get(SAMPLE_MESSAGE_HEADER_NAME_3)
.getStringValue());
assertEquals(3, capture.getValue().getMessageAttributes().size());
}
示例15: sendMessage
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入依赖的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;
}