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


Java DeleteMessageRequest类代码示例

本文整理汇总了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;
    }
 
开发者ID:hunterSThompson,项目名称:aws-ski-resort,代码行数:24,代码来源:QueueService.java

示例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());
  }
 
开发者ID:openzipkin,项目名称:zipkin-aws,代码行数:25,代码来源:AmazonSQSRule.java

示例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();
        }
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:19,代码来源:SqsDemoClient.java

示例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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:SqsConsumer.java

示例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;		
}
 
开发者ID:TimShi,项目名称:s3_video,代码行数:24,代码来源:AWSAdapter.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:QueueMessageChannel.java

示例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;
}
 
开发者ID:yancykim,项目名称:support,代码行数:25,代码来源:SQS.java

示例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);
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:9,代码来源:SqsTriggeredJobExecutor.java

示例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()));
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:11,代码来源:SQSScanWorkflow.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:AmazonSQSClientMock.java

示例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;
	}
}
 
开发者ID:apelyos,项目名称:distributed-image-classification,代码行数:9,代码来源:Queue.java

示例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();
    }
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:39,代码来源:AutoScalingEventListener.java

示例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));
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:8,代码来源:SqsReceiverHandler.java

示例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);
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:30,代码来源:SqsReceiverHandlerTest.java

示例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);
       }
}
 
开发者ID:ot4i,项目名称:amazon-sqs-connector,代码行数:40,代码来源:AmazonSQSInputConnector.java


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