/** * Creates the queue if it does not already exist. * * @return A value of <code>true</code> if the queue is created in the storage service, otherwise <code>false</code> * . * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean createIfNotExists() throws StorageException { return this.createIfNotExists(null /* options */, null /* opContext */); }
/** * Creates the queue if it does not already exist. * * @return A value of <code>true</code> if the queue is created in the storage service, otherwise <code>false</code> * . * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean createIfNotExists() throws StorageException { return this.createIfNotExists(null /* options */, null /* opContext */); }
public AzureQueue(String queueName, String storageConnectionString) { try { // Retrieve storage account from connection-string. CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); // Create the queue client. CloudQueueClient queueClient = storageAccount.createCloudQueueClient(); // Retrieve a reference to a queue. _queue = queueClient.getQueueReference(queueName); // Create the queue if it doesn't already exist. _queue.createIfNotExists(); } catch (Exception e) { // Output the stack trace. e.printStackTrace(); } }
private void doCreateQueue(CloudQueue client, QueueServiceRequestOptions opts, Exchange exchange) throws Exception { LOG.trace("Creating the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange); client.createIfNotExists(opts.getRequestOpts(), opts.getOpContext()); ExchangeUtil.getMessageForResponse(exchange) .setHeader(QueueServiceConstants.QUEUE_CREATED, Boolean.TRUE); }
/** * This method create a queue if it doesn't exist */ public boolean createQueueIfNotExists(String queueName) throws InvalidKeyException, URISyntaxException, StorageException { CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient(); CloudQueue queueRef = client.getQueueReference(queueName); boolean creationResult; try { creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); } catch (StorageException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.QUEUE_BEING_DELETED)) { throw e; } LOGGER.warn(messages.getMessage("error.QueueDeleted", queueRef.getName())); // Documentation doesn't specify how many seconds at least to wait. // 40 seconds before retrying. // See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-queue3 try { Thread.sleep(40000); } catch (InterruptedException eint) { throw new RuntimeException(messages.getMessage("error.InterruptedException")); } creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); LOGGER.debug(messages.getMessage("debug.QueueCreated", queueRef.getName())); } return creationResult; }
/** * This method create a queue if it doesn't exist */ public boolean createQueueIfNotExists(String queueName) throws InvalidKeyException, URISyntaxException, StorageException { CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient(); CloudQueue queueRef = client.getQueueReference(queueName); boolean creationResult; try { creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); } catch (StorageException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.QUEUE_BEING_DELETED)) { throw e; } LOGGER.warn(messages.getMessage("error.QueueDeleted", queueRef.getName())); // Documentation doesn't specify how many seconds at least to wait. // 40 seconds before retrying. // See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-queue3 try { Thread.sleep(40000); } catch (InterruptedException eint) { throw new RuntimeException(messages.getMessage("error.InterruptedException")); } creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); LOGGER.debug(messages.getMessage("debug.QueueCreated", queueRef.getName())); } return creationResult; }
@Before public void queueClientGBTestMethodSetUp() throws URISyntaxException, StorageException { this.queue = QueueTestHelper.getRandomQueueReference(); this.queue.createIfNotExists(); }
@Before public void queueTestMethodSetUp() throws URISyntaxException, StorageException { this.queue = QueueTestHelper.getRandomQueueReference(); this.queue.createIfNotExists(); }
@NotNull public Queue createQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException { try { CloudQueueClient client = getCloudQueueClient(storageAccount); CloudQueue cloudQueue = client.getQueueReference(queue.getName()); cloudQueue.createIfNotExists(); cloudQueue.downloadAttributes(); String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : ""; long approximateMessageCount = cloudQueue.getApproximateMessageCount(); queue.setUri(uri); queue.setApproximateMessageCount(approximateMessageCount); return queue; } catch (Throwable t) { throw new AzureCmdException("Error creating the Queue", t); } }
@Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) @Test public void testListQueuesAndListQueuesSegmentedLargeNumber() throws URISyntaxException, StorageException { CloudQueueClient qClient = QueueTestHelper.createCloudQueueClient(); int count = 0; String prefix = UUID.randomUUID().toString(); for (CloudQueue queue : qClient.listQueues(prefix)) { assertNotNull(queue); count++; } int totalLimit = 505; if (count < totalLimit) { NumberFormat myFormat = NumberFormat.getInstance(); myFormat.setMinimumIntegerDigits(4); for (int i = 0; i < totalLimit - count; i++) { CloudQueue q = qClient.getQueueReference(prefix + i); q.createIfNotExists(); } } ResultSegment<CloudQueue> segment = qClient.listQueuesSegmented(prefix, QueueListingDetails.NONE, 500, null, null, null); assertTrue(segment.getLength() == 500); assertTrue(segment.getContinuationToken() != null); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExistsAfterCreate() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); OperationContext createQueueContext2 = new OperationContext(); assertFalse(queue.createIfNotExists(null, createQueueContext2)); } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExists() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext)); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertFalse(queue.createIfNotExists()); } finally { queue.deleteIfExists(); } }
queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_ONLY); try { queue.createIfNotExists(options, context);
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExistsAfterDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); try { queue.createIfNotExists(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateAfterDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); try { queue.create(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.deleteIfExists(); } }