本文整理汇总了Java中com.amazonaws.services.sqs.model.CreateQueueRequest类的典型用法代码示例。如果您正苦于以下问题:Java CreateQueueRequest类的具体用法?Java CreateQueueRequest怎么用?Java CreateQueueRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateQueueRequest类属于com.amazonaws.services.sqs.model包,在下文中一共展示了CreateQueueRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPurgeQueue_shouldRemoveAll
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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: getUrlForQueue
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
/**
* Retrieves queue url for the given queue name. If the queue does not exist, tries to create it.
*
* @param queueName the queue name to get url for
* @return an optional String representing the queue url
*/
Optional<String> getUrlForQueue(String queueName) {
Optional<String> queueUrl = Optional.empty();
try {
GetQueueUrlResult queueUrlResult = sqs.getQueueUrl(queueName);
if (queueUrlResult.getQueueUrl() != null) {
queueUrl = Optional.of(queueUrlResult.getQueueUrl());
}
} catch (QueueDoesNotExistException e) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Queue " + queueName + " does not exist, try to create it",e);
}
CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
try {
queueUrl = Optional.of(sqs.createQueue(createQueueRequest).getQueueUrl());
} catch (AmazonClientException e2) {
LOGGER.error("Could not create queue " + queueName + ", bundle won't work",e2);
}
}
return queueUrl;
}
示例3: shouldCreateNewQueueWhenNoQueueUrlIsFound
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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);
}
示例4: initQueue
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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();
}
}
示例5: sendAndReceiveMessage
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
@Test
public void sendAndReceiveMessage() {
final String queueName = "bizo";
final String messageBody = "hi everybody";
final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
sqs.createQueue(createQueueRequest);
final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
final String queueUrl = getQueueUrlResult.getQueueUrl();
final SendMessageRequest sendMessageRequest =
new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
sqs.sendMessage(sendMessageRequest);
final int maxNumberOfMessages = 10;
final ReceiveMessageRequest receiveMessageRequest =
new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);
final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
final List<Message> messages = receiveMessageResult.getMessages();
assertThat(messages.size(), equalTo(1));
assertThat(messages.get(0).getBody(), equalTo(messageBody));
}
示例6: initialize
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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);
}
}
示例7: createQueue
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
/**
* Creates a new SQS queue on AWS.
* @param name queue name
* @return the queue URL or null
*/
public static String createQueue(String name) {
if (StringUtils.isBlank(name)) {
return null;
}
String queueURL = getQueueURL(name);
if (queueURL == null) {
try {
queueURL = getClient().createQueue(new CreateQueueRequest(name)).getQueueUrl();
} catch (AmazonServiceException ase) {
logException(ase);
} catch (AmazonClientException ace) {
logger.error("Could not reach SQS. {0}", ace.toString());
}
}
return queueURL;
}
示例8: resolveDestination
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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);
}
}
}
示例9: popFrom
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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;
}
示例10: getCount
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
public static int getCount(String name) {
try {
String queueUrl = getConnection().createQueue(
new CreateQueueRequest(name)).getQueueUrl();
List<String> attributeNames = new ArrayList<String>();
attributeNames.add("All");
// list the attributes of the queue we are interested in
GetQueueAttributesRequest request = new GetQueueAttributesRequest(queueUrl);
request.setAttributeNames(attributeNames);
Map<String, String> attributes = sqs.getQueueAttributes(request).getAttributes();
int messages = Integer.parseInt(attributes.get("ApproximateNumberOfMessages"));
//System.out.println("Messages in the queue: " + messages);
return messages;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
示例11: createRequest
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
@VisibleForTesting
static CreateQueueRequest createRequest(SqsQueueConfig config) {
//TODO: add deadletter config
return new CreateQueueRequest()
.withQueueName(config.getName())
.withAttributes(config.getAttributes().getStringMap());
}
示例12: testCreateGetUrlListQueue_shouldCreateReturnUrlAndListQueue
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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");
}
示例13: getOrCreateQueue
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的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);
}
}
示例14: createQueueMessage
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
SendMessageResult createQueueMessage(ImageCreateRequest request, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = request.getQueueName();
final String sqsEndpoint = request.getSqsEndpoint();
if (queueName == null || sqsEndpoint == null) {
logger.log("skip create queue. [" + request + "]");
return null;
}
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
request.setSendMessageTimeMillis(System.currentTimeMillis());
try {
CreateQueueRequest req = new CreateQueueRequest(queueName);
String queueUrl = client.createQueue(req).getQueueUrl();
SendMessageRequest sendMessage = new SendMessageRequest();
sendMessage.setQueueUrl(queueUrl);
ObjectMapper om = new ObjectMapper();
sendMessage.setMessageBody(om.writeValueAsString(request));
Future<SendMessageResult> result = client.sendMessageAsync(sendMessage);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error occured in the create queue request.", e);
} finally {
client.shutdown();
}
}
示例15: createQueueMessage
import com.amazonaws.services.sqs.model.CreateQueueRequest; //导入依赖的package包/类
SendMessageResult createQueueMessage(InstanceRequest instanceRequest, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = instanceRequest.getQueueName();
final String sqsEndpoint = instanceRequest.getSqsEndpoint();
if (queueName == null || sqsEndpoint == null) {
logger.log("skip create queue. instanceRequest[" + instanceRequest + "]");
return null;
}
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
try {
CreateQueueRequest req = new CreateQueueRequest(queueName);
String queueUrl = client.createQueue(req).getQueueUrl();
instanceRequest.setSendMessageTimeMillis(System.currentTimeMillis());
SendMessageRequest sendMessage = new SendMessageRequest();
sendMessage.setQueueUrl(queueUrl);
ObjectMapper om = new ObjectMapper();
sendMessage.setMessageBody(om.writeValueAsString(instanceRequest));
Future<SendMessageResult> result = client.sendMessageAsync(sendMessage);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error occured in the create queue request.", e);
} finally {
client.shutdown();
}
}