當前位置: 首頁>>代碼示例>>Java>>正文


Java ReceiveMessageRequest.setMaxNumberOfMessages方法代碼示例

本文整理匯總了Java中com.amazonaws.services.sqs.model.ReceiveMessageRequest.setMaxNumberOfMessages方法的典型用法代碼示例。如果您正苦於以下問題:Java ReceiveMessageRequest.setMaxNumberOfMessages方法的具體用法?Java ReceiveMessageRequest.setMaxNumberOfMessages怎麽用?Java ReceiveMessageRequest.setMaxNumberOfMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.sqs.model.ReceiveMessageRequest的用法示例。


在下文中一共展示了ReceiveMessageRequest.setMaxNumberOfMessages方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: peekMessage

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public T peekMessage(int waitFor) throws Exception {
       // Receive messages
	logger.info("Trying to recieve message from: " + _queueName);
       ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(_queueURL);
       receiveMessageRequest.setMaxNumberOfMessages(1);
       receiveMessageRequest.setWaitTimeSeconds(waitFor);
       
       List<Message> messages = _sqs.receiveMessage(receiveMessageRequest).getMessages();
       
       for (Message message : messages) {
       	logger.info("  Got Message");
       	logger.info("    Body:          " + message.getBody());
       	logger.info("    Handle:        " + message.getReceiptHandle());
           
           _lastMessage = message;
           GenericMessage msg =  GenericMessage.fromXML(message.getBody());
   		if (!msg.type.equals(_msgClass.getName()))
   			throw new Exception("Invalid message type recieved.");
   		
           return (T) msg.body;
       }
	return null;
}
 
開發者ID:apelyos,項目名稱:distributed-image-classification,代碼行數:25,代碼來源:Queue.java

示例2: popFrom

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的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

示例3: createReceiveMessageRequest

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
@Override
public ReceiveMessageRequest createReceiveMessageRequest(String queueUrl, final int maxNumberMessages, final int waitTimeSeconds) {
    final ReceiveMessageRequest request = new ReceiveMessageRequest(queueUrl);
    request.setMaxNumberOfMessages(maxNumberMessages);
    request.setWaitTimeSeconds(waitTimeSeconds);
    return request;
}
 
開發者ID:riboseinc,項目名稱:aws-codecommit-trigger-plugin,代碼行數:8,代碼來源:RequestFactoryImpl.java

示例4: run

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
@Override
public void run() {
    String queueUrl = client.getQueueUrl(queue).getQueueUrl();

    ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest(queueUrl);
    receiveRequest.setMaxNumberOfMessages(10);

    while (true) {
        ReceiveMessageResult receiveResult= client.receiveMessage(receiveRequest);
        List<Message> messages = receiveResult.getMessages();

        messages.forEach(System.out::println);
    }
}
 
開發者ID:ShotaOd,項目名稱:carbon,代碼行數:15,代碼來源:PollingTask.java

示例5: poll

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
@Override
protected int poll() throws Exception {
    // must reset for each poll
    shutdownRunningTask = null;
    pendingExchanges = 0;
    
    ReceiveMessageRequest request = new ReceiveMessageRequest(getQueueUrl());
    request.setMaxNumberOfMessages(getMaxMessagesPerPoll() > 0 ? getMaxMessagesPerPoll() : null);
    request.setVisibilityTimeout(getConfiguration().getVisibilityTimeout() != null ? getConfiguration().getVisibilityTimeout() : null);
    request.setWaitTimeSeconds(getConfiguration().getWaitTimeSeconds() != null ? getConfiguration().getWaitTimeSeconds() : null);

    if (attributeNames != null) {
        request.setAttributeNames(attributeNames);
    }
    if (messageAttributeNames != null) {
        request.setMessageAttributeNames(messageAttributeNames);
    }

    LOG.trace("Receiving messages with request [{}]...", request);
    
    ReceiveMessageResult messageResult = null;
    try {
        messageResult = getClient().receiveMessage(request);
    } catch (QueueDoesNotExistException e) {
        LOG.info("Queue does not exist....recreating now...");
        reConnectToQueue();
        messageResult = getClient().receiveMessage(request);
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("Received {} messages", messageResult.getMessages().size());
    }
    
    Queue<Exchange> exchanges = createExchanges(messageResult.getMessages());
    return processBatch(CastUtils.cast(exchanges));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:37,代碼來源:SqsConsumer.java

示例6: shouldGetMessages10per10WithAttributes

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
@Test
public void shouldGetMessages10per10WithAttributes() throws Exception {
    //GIVEN
    when(sqs.receiveMessage((ReceiveMessageRequest) anyObject())).thenReturn(new ReceiveMessageResult());

    //WHEN
    receiverHandler.start();

    //THEN
    Thread.sleep(100);
    ReceiveMessageRequest expected = new ReceiveMessageRequest(queueUrl).withMessageAttributeNames("All");
    expected.setMaxNumberOfMessages(10);
    verify(sqs, atLeastOnce()).receiveMessage(expected);
    verify(sqs, never()).receiveMessage(new ReceiveMessageRequest(queueUrl));
}
 
開發者ID:sjarrin,項目名稱:dropwizard-sqs-bundle,代碼行數:16,代碼來源:SqsReceiverHandlerTest.java

示例7: pollQueue

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
/**
 * Poll SQS queue for incoming messages, filter them, and return a list of SQS Messages.
 *
 * @return a list of SQS messages.
 */
public List<Message> pollQueue() {
    boolean success = false;
    ProgressStatus pollQueueStatus = new ProgressStatus(ProgressState.pollQueue, new BasicPollQueueInfo(0, success));
    final Object reportObject = progressReporter.reportStart(pollQueueStatus);

    ReceiveMessageRequest request = new ReceiveMessageRequest().withAttributeNames(ALL_ATTRIBUTES);
    request.setQueueUrl(config.getSqsUrl());
    request.setVisibilityTimeout(config.getVisibilityTimeout());
    request.setMaxNumberOfMessages(DEFAULT_SQS_MESSAGE_SIZE_LIMIT);
    request.setWaitTimeSeconds(DEFAULT_WAIT_TIME_SECONDS);

    List<Message> sqsMessages = new ArrayList<Message>();
    try {

        ReceiveMessageResult result = sqsClient.receiveMessage(request);
        sqsMessages = result.getMessages();
        logger.info("Polled " + sqsMessages.size() + " sqs messages from " + config.getSqsUrl());

        success = true;
    } catch (AmazonServiceException e) {
        LibraryUtils.handleException(exceptionHandler, pollQueueStatus, e, "Failed to poll sqs message.");

    } finally {
        LibraryUtils.endToProcess(progressReporter, success, pollQueueStatus, reportObject);
    }
    return sqsMessages;

}
 
開發者ID:aws,項目名稱:aws-cloudtrail-processing-library,代碼行數:34,代碼來源:SqsManager.java

示例8: getNotifications

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //導入方法依賴的package包/類
public List<CloudtrailSNSNotification> getNotifications() {
    LOG.debug("Fetching SQS CloudTrail notifications.");

    List<CloudtrailSNSNotification> notifications = Lists.newArrayList();

    ReceiveMessageRequest request = new ReceiveMessageRequest(queueName);
    request.setMaxNumberOfMessages(10);
    ReceiveMessageResult result = sqs.receiveMessage(request);

    LOG.debug("Received [{}] SQS CloudTrail notifications.", result.getMessages().size());

    CloudtrailSNSNotificationParser parser = new CloudtrailSNSNotificationParser(objectMapper);

    for (Message message : result.getMessages()) {
        notifications.addAll(parser.parse(message));
    }

    return notifications;
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-aws,代碼行數:20,代碼來源:CloudtrailSQSClient.java


注:本文中的com.amazonaws.services.sqs.model.ReceiveMessageRequest.setMaxNumberOfMessages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。