本文整理汇总了Java中com.amazonaws.services.sqs.model.DeleteMessageRequest类的典型用法代码示例。如果您正苦于以下问题:Java DeleteMessageRequest类的具体用法?Java DeleteMessageRequest怎么用?Java DeleteMessageRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeleteMessageRequest类属于com.amazonaws.services.sqs.model包,在下文中一共展示了DeleteMessageRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessages
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public List<QueueMessage> getMessages() {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(_queueDns);
List<Message> messages = _sqs.receiveMessage(receiveMessageRequest).getMessages();
List<QueueMessage> deserializedMessages = new ArrayList<>();
for (Message message : messages) {
String body = message.getBody();
QueueMessage qm = _gson.fromJson(body, QueueMessage.class);
deserializedMessages.add(qm);
System.out.println("query time: " + qm.queryExecutionTime);
System.out.println("exec time: " + qm.totalExecutionTime);
System.out.println("Has ex: " + qm.hasException);
System.out.println("ex message: " + qm.exceptionMessage + "\n");
String receiptHandle = message.getReceiptHandle();
_sqs.deleteMessage(new DeleteMessageRequest(_queueDns, receiptHandle));
}
return deserializedMessages;
}
示例2: getSpans
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public List<Span> getSpans(boolean delete) {
Stream<Span> spans = Stream.empty();
ReceiveMessageResult result = client.receiveMessage(queueUrl);
while(result != null && result.getMessages().size() > 0) {
spans = Stream.concat(spans,
result.getMessages().stream().flatMap(AmazonSQSRule::decodeSpans)
);
result = client.receiveMessage(queueUrl);
if (delete) {
List<DeleteMessageRequest> deletes = result.getMessages().stream()
.map(m -> new DeleteMessageRequest(queueUrl, m.getReceiptHandle()))
.collect(Collectors.toList());
deletes.forEach(d -> client.deleteMessage(d));
}
}
return spans.collect(Collectors.toList());
}
示例3: pollMessages
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
private void pollMessages(AmazonSQS sqs) {
log.info("Polling messages");
while (true) {
List<Message> messages = sqs.receiveMessage(QUEUE_URL).getMessages();
messages.forEach(m -> {
log.info("Message Received: " + m.getBody());
System.out.println(m.getBody());
DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(QUEUE_URL, m.getReceiptHandle());
sqs.deleteMessage(deleteMessageRequest);
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
}
}
示例4: processCommit
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
/**
* Strategy to delete the message after being processed.
*
* @param exchange the exchange
*/
protected void processCommit(Exchange exchange) {
try {
if (shouldDelete(exchange)) {
String receiptHandle = exchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE, String.class);
DeleteMessageRequest deleteRequest = new DeleteMessageRequest(getQueueUrl(), receiptHandle);
LOG.trace("Deleting message with receipt handle {}...", receiptHandle);
getClient().deleteMessage(deleteRequest);
LOG.trace("Deleted message with receipt handle {}...", receiptHandle);
}
} catch (AmazonClientException e) {
getExceptionHandler().handleException("Error occurred during deleting message. This exception is ignored.", exchange, e);
}
}
示例5: pollMessageFromQueueByJobId
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public List<JobStatusNotification> pollMessageFromQueueByJobId(String queueUrl, String jobId) {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest()
.withQueueUrl(queueUrl)
.withMaxNumberOfMessages(MAX_NUMBER_OF_MESSAGES)
.withVisibilityTimeout(VISIBILITY_TIMEOUT)
.withWaitTimeSeconds(WAIT_TIME_SECONDS);
List<JobStatusNotification> jobStatusNotifications = new ArrayList<>();
for (Message message : sqsClient.receiveMessage(receiveMessageRequest).getMessages()) {
try {
JobStatusNotification jobStatusNotification = parseMessage(message.getBody());
if (jobStatusNotification.getJobId().equalsIgnoreCase(jobId)) {
jobStatusNotifications.add(jobStatusNotification);
sqsClient.deleteMessage(new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(message.getReceiptHandle()));
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
return jobStatusNotifications;
}
示例6: receive
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
@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;
}
示例7: popFrom
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public static String popFrom(String name) {
try {
String queueUrl = getConnection().createQueue(
new CreateQueueRequest(name)).getQueueUrl();
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(
queueUrl);
receiveMessageRequest.setMaxNumberOfMessages(1);
if (null != receiveMessageRequest) {
List<Message> messages = getConnection().receiveMessage(
receiveMessageRequest).getMessages();
if (messages.size() > 0) {
String messageRecieptHandle = messages.get(0)
.getReceiptHandle();
getConnection().deleteMessage(
new DeleteMessageRequest(receiveMessageRequest
.getQueueUrl(), messageRecieptHandle));
return messages.get(0).getBody();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例8: deleteMessage
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public void deleteMessage(Message msg) {
DeleteMessageRequest
request =
new DeleteMessageRequest()
.withQueueUrl(this.queueUrl)
.withReceiptHandle(msg.getReceiptHandle());
this.getClient().deleteMessage(request);
}
示例9: releaseScanRangeTask
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
@Override
public void releaseScanRangeTask(ScanRangeTask task) {
// Signal that the range is complete
signalScanRangeComplete(task.getScanId());
// Ack the task
_sqs.deleteMessage(new DeleteMessageRequest()
.withQueueUrl(getQueueUrl(_pendingScanRangeQueue))
.withReceiptHandle(((QueueScanRangeTask) task).getMessageId()));
}
示例10: deleteMessage
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
@Override
public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) throws AmazonClientException {
String receiptHandle = deleteMessageRequest.getReceiptHandle();
if (inFlight.containsKey(receiptHandle)) {
ScheduledFuture inFlightTask = inFlight.get(receiptHandle);
inFlightTask.cancel(true);
}
return new DeleteMessageResult();
}
示例11: deleteLastMessage
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public void deleteLastMessage() {
if (_lastMessage != null) {
// Deletes a message
logger.info("Deleting the last message with handle: " + _lastMessage.getReceiptHandle());
_sqs.deleteMessage(new DeleteMessageRequest(_queueURL, _lastMessage.getReceiptHandle()));
_lastMessage = null;
}
}
示例12: run
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
public void run() {
while (receiveMessages) {
try {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(getQueueUrl());
List<Message> messages = amazonSQS.receiveMessage(receiveMessageRequest).getMessages();
for (Message message : messages) {
JSONObject obj = new JSONObject(message.getBody());
String msg = obj.get("Message").toString();
JSONObject jsonMessage = new JSONObject(msg);
if (jsonMessage.has("Event")) {
AutoScalingEvents event = AutoScalingEvents.fromString((String) jsonMessage.get("Event"));
switch (event) {
case EC2_INSTANCE_TERMINATE: {
if (eventsRepository.findOne(message.getMessageId()) == null) {
clusterEventPublisher.nodeTerminated((String) jsonMessage.get("EC2InstanceId"), message.getMessageId());
amazonSQS.deleteMessage(new DeleteMessageRequest()
.withQueueUrl(getQueueUrl()).withReceiptHandle(message.getReceiptHandle()));
}
break;
}
default: {
LOG.warn("New AutoScaling event: {}", message.toString());
amazonSQS.deleteMessage(new DeleteMessageRequest()
.withQueueUrl(getQueueUrl()).withReceiptHandle(message.getReceiptHandle()));
}
}
} else {
LOG.warn("Unknown event: {}", message.toString());
amazonSQS.deleteMessage(new DeleteMessageRequest()
.withQueueUrl(getQueueUrl()).withReceiptHandle(message.getReceiptHandle()));
}
}
} catch (Exception e) {
LOG.error("Unable to process AutoScaling event", e);
}
sleep();
}
}
示例13: deleteMessage
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
private void deleteMessage(Message message) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Delete message " + message);
}
String messageReceiptHandle = message.getReceiptHandle();
sqs.deleteMessage(new DeleteMessageRequest(queueUrl, messageReceiptHandle));
}
示例14: messageShouldBeDeletedAfterBeingConsumed
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
@Test
public void messageShouldBeDeletedAfterBeingConsumed() throws Exception {
//GIVEN
ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
Message message1 = new Message()
.withMessageId("aaaa-bbbb-cccc-dddd-eeee")
.withBody("Sample test message")
.withReceiptHandle("qwertz");
Message message2 = new Message()
.withMessageId("ffff-gggg-hhhh-iiii-jjjj")
.withBody("Another sample test message")
.withReceiptHandle("asdfgh");
receiveMessageResult.setMessages(Lists.newArrayList(message1, message2));
// simulate at the 2nd call that the message has been deleted on SQS side
when(sqs.receiveMessage((ReceiveMessageRequest) anyObject()))
.thenReturn(receiveMessageResult)
.thenReturn(new ReceiveMessageResult());
DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(queueUrl, "asdfgh");
doNothing().when(sqs).deleteMessage(deleteMessageRequest);
//WHEN
receiverHandler.start();
//THEN
Thread.sleep(100);
verify(sqs, times(1)).deleteMessage(deleteMessageRequest);
}
示例15: poll
import com.amazonaws.services.sqs.model.DeleteMessageRequest; //导入依赖的package包/类
@Override
public void poll(long waitInterval ) {
Properties properties = new Properties();
String access_key_id = getProperty("AccessKeyId");
String secret_access_key = getProperty("SecretAccessKey");
BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);
AmazonSQS sqs = new AmazonSQSClient(credentials);
// Region selection
Region region = Region.getRegion(Regions.fromName(getProperty("region")));
sqs.setRegion(region);
GetQueueUrlResult queueUrl = sqs.getQueueUrl(getProperty("Queue"));
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl.getQueueUrl());
List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
String outputMessage = "";
// if there are messages then do the processing
if(messages.size() > 0){
//append the message properties to the localenv tree
for (Message message : messages) {
properties.setProperty("MessageId", message.getMessageId());
properties.setProperty("ReceiptHandle", message.getReceiptHandle());
properties.setProperty("MD5OfBody", message.getMD5OfBody());
// get the message body to a string
outputMessage = message.getBody();
}
properties.setProperty("queueUrl", queueUrl.getQueueUrl());
// delete the message from the queue
String messageReceiptHandle = messages.get(0).getReceiptHandle();
sqs.deleteMessage(new DeleteMessageRequest(queueUrl.getQueueUrl(), messageReceiptHandle));
ConnectorCallback callback = getCallback();
callback.processInboundData(outputMessage.getBytes(), properties);
}
}