本文整理汇总了Java中com.amazonaws.services.sqs.model.CreateQueueResult类的典型用法代码示例。如果您正苦于以下问题:Java CreateQueueResult类的具体用法?Java CreateQueueResult怎么用?Java CreateQueueResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateQueueResult类属于com.amazonaws.services.sqs.model包,在下文中一共展示了CreateQueueResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPurgeQueue_shouldRemoveAll
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的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: shouldCreateNewQueueWhenNoQueueUrlIsFound
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Test
public void shouldCreateNewQueueWhenNoQueueUrlIsFound() throws Exception {
//GIVEN
AmazonSQS sqs = mock(AmazonSQS.class);
field("sqs").ofType(AmazonSQS.class).in(bundle).set(sqs);
String queueUrl = "https://eu-central-1/queue.amazonaws.com/123456/test-queue";
when(sqs.getQueueUrl("test-queue")).thenThrow(new QueueDoesNotExistException("Simulates that queue does not exist"));
when(sqs.createQueue(new CreateQueueRequest("test-queue"))).thenReturn(new CreateQueueResult().withQueueUrl(queueUrl));
//WHEN
Optional<String> urlForQueue = bundle.getUrlForQueue("test-queue");
//THEN
assertThat(urlForQueue.isPresent()).isTrue();
assertThat(urlForQueue.get()).isEqualTo(queueUrl);
}
示例3: initQueue
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
private void initQueue() {
this.sqs = new AmazonSQSClient(); // Do we need to use new
// ClientConfiguration().withMaxConnections(256)
// ?
this.sqs.configureRegion(region);
try {
// Check to see if queue exists
GetQueueUrlResult queueUrlResult = this.sqs.getQueueUrl(getSqsQueueName());
this.queueUrl = queueUrlResult.getQueueUrl();
} catch (QueueDoesNotExistException queueDoesNotExist) {
// Queue does not exist, need to create one
CreateQueueRequest createQueueRequest = new CreateQueueRequest();
createQueueRequest.setQueueName(getSqsQueueName());
createQueueRequest.addAttributesEntry("VisibilityTimeout", "" + getVisibilityTimeout());
CreateQueueResult createQueueResult = this.sqs.createQueue(createQueueRequest);
this.queueUrl = createQueueResult.getQueueUrl();
}
}
示例4: initialize
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Override
public void initialize(JSONObject config) throws Exception {
String endpoint = config.getString(PARAM_ENDPOINT);
String queueName = config.getString(GenericQueue.PARAM_NAME);
String accessKey = config.getString(PARAM_ACCESS_KEY);
String secretKey = config.getString(PARAM_SECRET_KEY);
if(accessKey==null) throw new Exception(PARAM_ACCESS_KEY+" is required!");
if(secretKey==null) throw new Exception(PARAM_SECRET_KEY+" is required!");
try {
this.client = new AmazonSQSAsyncClient(new BasicAWSCredentials(accessKey,secretKey));
this.client.setEndpoint(endpoint);
CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
CreateQueueResult createQueueResult = this.client.createQueue(createQueueRequest);
this.queueUrl = createQueueResult.getQueueUrl();
} catch (Throwable e){
throw new Exception(e);
}
}
示例5: resolveDestination
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Override
public String resolveDestination(String name) throws DestinationResolutionException {
String queueName = name;
if (this.resourceIdResolver != null) {
queueName = this.resourceIdResolver.resolveToPhysicalResourceId(name);
}
if (isValidQueueUrl(queueName)) {
return queueName;
}
if (this.autoCreate) {
//Auto-create is fine to be called even if the queue exists.
CreateQueueResult createQueueResult = this.amazonSqs.createQueue(new CreateQueueRequest(queueName));
return createQueueResult.getQueueUrl();
} else {
try {
GetQueueUrlResult getQueueUrlResult = this.amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueName));
return getQueueUrlResult.getQueueUrl();
} catch (QueueDoesNotExistException e) {
throw new DestinationResolutionException(e.getMessage(), e);
}
}
}
示例6: testAssertQueueAlreadyExistsAndMatches
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Test
public void testAssertQueueAlreadyExistsAndMatches() {
when(requestSenderMock.sendRequest(any(CreateQueueAction.class))).thenReturn(Single.just(
new CreateQueueResult().withQueueUrl(QUEUE_URL)
));
SqsQueue<String> queue = client.upsertQueue(QUEUE_CONFIG).blockingGet();
assertThat(queue.getQueueUrl()).isEqualTo(QUEUE_URL);
verify(requestSenderMock).sendRequest(any(CreateQueueAction.class));
}
示例7: testCreateGetUrlListQueue_shouldCreateReturnUrlAndListQueue
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Test
public void testCreateGetUrlListQueue_shouldCreateReturnUrlAndListQueue() {
// create first queue
CreateQueueResult createdQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-earl-grey-queue"));
assertNotNull("verify that, on creation, queue url was returned",createdQueue.getQueueUrl());
// create other queues
CreateQueueResult secondTeaQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-mate-queue"));
CreateQueueResult anotherQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("coffee-queue"));
// get queue url
GetQueueUrlResult queueUrlResult = sqs.getQueueUrl(new GetQueueUrlRequest()
.withQueueName("tea-earl-grey-queue").withQueueOwnerAWSAccountId("some owner"));
assertNotNull("verify that, on fetch, queue url was returned", queueUrlResult.getQueueUrl());
// get all queues
ListQueuesResult allQueues = sqs.listQueues();
assertEquals("verify all queues are returned", 3, allQueues.getQueueUrls().size());
assertTrue("verify that all queues contain first queue", allQueues.getQueueUrls().contains(createdQueue.getQueueUrl()));
assertTrue("verify that all queues contain second tea queue", allQueues.getQueueUrls().contains(secondTeaQueue.getQueueUrl()));
assertTrue("verify that all queues contain coffee queue", allQueues.getQueueUrls().contains(anotherQueue.getQueueUrl()));
// get only queues that start with 'tea'
ListQueuesResult teaQueues = sqs.listQueues(new ListQueuesRequest("tea"));
assertEquals("verify only tea queues are returned", 2, teaQueues.getQueueUrls().size());
assertTrue("verify that tea queues contain first queue", teaQueues.getQueueUrls().contains(createdQueue.getQueueUrl()));
assertTrue("verify that tea queues contain second tea queue", teaQueues.getQueueUrls().contains(secondTeaQueue.getQueueUrl()));
assertNotNull("verify that delete queue returned ok", sqs.deleteQueue(new DeleteQueueRequest().withQueueUrl(queueUrlResult.getQueueUrl())));
assertFalse("verify that the queue was removed", sqs.listQueues().getQueueUrls().stream()
.anyMatch( queueUrl -> StringUtils.equals(queueUrl,queueUrlResult.getQueueUrl()) ));
// cleanup
getQueues().remove("tea-earl-grey-queue");
getQueues().remove("tea-mate-queue");
getQueues().remove("coffee-queue");
}
示例8: getOrCreateQueue
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@VisibleForTesting
String getOrCreateQueue() {
List<String> queueUrls = listQueues(queueName);
if (queueUrls == null || queueUrls.isEmpty()) {
CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
CreateQueueResult result = client.createQueue(createQueueRequest);
return result.getQueueUrl();
} else {
return queueUrls.get(0);
}
}
示例9: Scanner
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
public Scanner(ScanConfig config) {
opt = config;
ProfileCredentialsProvider creds = new ProfileCredentialsProvider(opt.profile());
creds.getCredentials(); // credible credential criteria
s3 = new AmazonS3Client(creds);
sqs = new AmazonSQSClient(creds);
CreateQueueResult queueResult = sqs.createQueue(opt.queue());
queueUrl = queueResult.getQueueUrl();
filter = Pattern.compile(opt.filter(), Pattern.CASE_INSENSITIVE);
max = Long.parseLong(opt.max());
}
示例10: main
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
public static void main(String[] args)
{
final String queue_name = "testQueue" + new Date().getTime();
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
// first, create a queue (unless it exists already)
try {
CreateQueueResult cq_result = sqs.createQueue(queue_name);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
final String queue_url = sqs.getQueueUrl(queue_name).getQueueUrl();
// Send some messages to the queue
for (int i = 0; i < 20; i++) {
sqs.sendMessage(queue_url, "This is message " + i);
}
// change visibility timeout (single)
changeMessageVisibilitySingle(queue_url, 3600);
// change visibility timeout (multiple)
changeMessageVisibilityMultiple(queue_url, 2000);
}
示例11: main
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
public static void main(String[] args)
{
final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
try {
CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
SendMessageRequest send_msg_request = new SendMessageRequest()
.withQueueUrl(queueUrl)
.withMessageBody("hello world")
.withDelaySeconds(5);
sqs.sendMessage(send_msg_request);
// Send multiple messages to the queue
SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest()
.withQueueUrl(queueUrl)
.withEntries(
new SendMessageBatchRequestEntry(
"msg_1", "Hello from message 1"),
new SendMessageBatchRequestEntry(
"msg_2", "Hello from message 2")
.withDelaySeconds(10));
sqs.sendMessageBatch(send_batch_request);
// receive messages from the queue
List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();
// delete messages from the queue
for (Message m : messages) {
sqs.deleteMessage(queueUrl, m.getReceiptHandle());
}
}
示例12: createQueue
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
protected void createQueue(AmazonSQS client) {
LOG.trace("Queue '{}' doesn't exist. Will create it...", configuration.getQueueName());
// creates a new queue, or returns the URL of an existing one
CreateQueueRequest request = new CreateQueueRequest(configuration.getQueueName());
if (getConfiguration().getDefaultVisibilityTimeout() != null) {
request.getAttributes().put(QueueAttributeName.VisibilityTimeout.name(), String.valueOf(getConfiguration().getDefaultVisibilityTimeout()));
}
if (getConfiguration().getMaximumMessageSize() != null) {
request.getAttributes().put(QueueAttributeName.MaximumMessageSize.name(), String.valueOf(getConfiguration().getMaximumMessageSize()));
}
if (getConfiguration().getMessageRetentionPeriod() != null) {
request.getAttributes().put(QueueAttributeName.MessageRetentionPeriod.name(), String.valueOf(getConfiguration().getMessageRetentionPeriod()));
}
if (getConfiguration().getPolicy() != null) {
request.getAttributes().put(QueueAttributeName.Policy.name(), String.valueOf(getConfiguration().getPolicy()));
}
if (getConfiguration().getReceiveMessageWaitTimeSeconds() != null) {
request.getAttributes().put(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), String.valueOf(getConfiguration().getReceiveMessageWaitTimeSeconds()));
}
if (getConfiguration().getRedrivePolicy() != null) {
request.getAttributes().put(QueueAttributeName.RedrivePolicy.name(), getConfiguration().getRedrivePolicy());
}
LOG.trace("Creating queue [{}] with request [{}]...", configuration.getQueueName(), request);
CreateQueueResult queueResult = client.createQueue(request);
queueUrl = queueResult.getQueueUrl();
LOG.trace("Queue created and available at: {}", queueUrl);
}
示例13: createQueue
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Override
public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws AmazonServiceException, AmazonClientException {
String queueName = "https://queue.amazonaws.com/541925086079/" + createQueueRequest.getQueueName();
queues.put(queueName, createQueueRequest);
CreateQueueResult result = new CreateQueueResult();
result.setQueueUrl(queueName);
return result;
}
示例14: produceMsg
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
public void produceMsg(String[] msgs, boolean purgeFirst) throws Exception
{
CreateQueueResult res = sqs.createQueue(getCurrentQueueName());
if (purgeFirst) {
PurgeQueueRequest purgeReq = new PurgeQueueRequest(res.getQueueUrl());
sqs.purgeQueue(purgeReq);
}
for (String text : msgs) {
sqs.sendMessage(res.getQueueUrl(), text);
}
}
示例15: createQueue
import com.amazonaws.services.sqs.model.CreateQueueResult; //导入依赖的package包/类
@Override
public Queue createQueue(CreateQueueRequest request,
ResultCapture<CreateQueueResult> extractor) {
ActionResult result = service.performAction("CreateQueue", request,
extractor);
if (result == null) return null;
return new QueueImpl(result.getResource());
}