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


Java CloudQueueClient.getQueueReference方法代码示例

本文整理汇总了Java中com.microsoft.azure.storage.queue.CloudQueueClient.getQueueReference方法的典型用法代码示例。如果您正苦于以下问题:Java CloudQueueClient.getQueueReference方法的具体用法?Java CloudQueueClient.getQueueReference怎么用?Java CloudQueueClient.getQueueReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.storage.queue.CloudQueueClient的用法示例。


在下文中一共展示了CloudQueueClient.getQueueReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createQueue

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
/**
 * Creates and returns a queue for the sample application to use.
 *
 * @param queueClient CloudQueueClient object
 * @param queueName Name of the queue to create
 * @return The newly created CloudQueue object
 *
 * @throws StorageException
 * @throws RuntimeException
 * @throws IOException
 * @throws URISyntaxException
 * @throws IllegalArgumentException
 * @throws InvalidKeyException
 * @throws IllegalStateException
 */
private static CloudQueue createQueue(CloudQueueClient queueClient, String queueName) throws StorageException, RuntimeException, IOException, InvalidKeyException, IllegalArgumentException, URISyntaxException, IllegalStateException {

    // Create a new queue
    CloudQueue queue = queueClient.getQueueReference(queueName);
    try {
        if (queue.createIfNotExists() == false) {
            throw new IllegalStateException(String.format("Queue with name \"%s\" already exists.", queueName));
        }
    }
    catch (StorageException s) {
        if (s.getCause() instanceof java.net.ConnectException) {
            System.out.println("Caught connection exception from the client. If running with the default configuration please make sure you have started the storage emulator.");
        }
        throw s;
    }

    return queue;
}
 
开发者ID:Azure-Samples,项目名称:storage-queue-java-getting-started,代码行数:34,代码来源:QueueBasics.java

示例2: createQueueIfNotExists

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
/**
 * 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();
    } 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();
        LOGGER.debug(messages.getMessage("debug.QueueCreated", queueRef.getName()));
    }

    return creationResult;
}
 
开发者ID:Talend,项目名称:components,代码行数:29,代码来源:AzureStorageQueueService.java

示例3: testQueueDownloadAttributes

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
private static void testQueueDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode,
        StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList)
        throws URISyntaxException, StorageException {
    CloudQueueClient client = TestHelper.createCloudQueueClient();
    CloudQueue queue = client.getQueueReference(QueueTestHelper.generateRandomQueueName());

    MultiLocationTestHelper helper = new MultiLocationTestHelper(queue.getServiceClient().getStorageUri(),
            initialLocation, retryContextList, retryInfoList);

    queue.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode);
    QueueRequestOptions options = new QueueRequestOptions();

    options.setLocationMode(optionsLocationMode);
    options.setRetryPolicyFactory(helper.retryPolicy);

    try {
        queue.downloadAttributes(options, helper.operationContext);
    }
    catch (StorageException ex) {
        assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode());
    }
    finally {
        helper.close();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:26,代码来源:SecondaryTests.java

示例4: testCloudStorageAccountClientUriVerify

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
@Test
public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException {
    StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY);
    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true);

    CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString());

    CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString());

    CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString());

    CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient();
    CloudFileShare share = fileClient.getShareReference("share1");
    assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString());
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:22,代码来源:StorageAccountTests.java

示例5: getQueue

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
/**
 * 获取队列
 * @param queueClient  队列管理类
 * @param queueName    队列名
 * @return
 */
public static CloudQueue getQueue(CloudQueueClient queueClient, String queueName) {
	DebugLog.d(TAG, "getQueue() queueName = " + queueName);
	
	try {
		//获取队列,如果队列不存在,则创建队列
		CloudQueue queue = queueClient.getQueueReference(queueName);
		queue.createIfNotExists();
		
		return queue;
	} catch (Exception e) {
		DebugLog.e(TAG, "getQueue()", e);
		return null;
	}
}
 
开发者ID:leleliu008,项目名称:Newton_for_Android_AS,代码行数:21,代码来源:AzureStorage.java

示例6: peekMessages

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public Iterable<CloudQueueMessage> peekMessages(String queueName, int numberOfMessages)
        throws InvalidKeyException, URISyntaxException, StorageException {

    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.peekMessages(numberOfMessages);
}
 
开发者ID:Talend,项目名称:components,代码行数:8,代码来源:AzureStorageQueueService.java

示例7: retrieveMessages

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public Iterable<CloudQueueMessage> retrieveMessages(String queueName, int numberOfMessages)
        throws InvalidKeyException, URISyntaxException, StorageException {

    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.retrieveMessages(numberOfMessages);
}
 
开发者ID:Talend,项目名称:components,代码行数:8,代码来源:AzureStorageQueueService.java

示例8: deleteMessage

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public void deleteMessage(String queueName, CloudQueueMessage message)
        throws InvalidKeyException, URISyntaxException, StorageException {

    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    queueRef.deleteMessage(message);
}
 
开发者ID:Talend,项目名称:components,代码行数:8,代码来源:AzureStorageQueueService.java

示例9: testUserAgentString

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
@Test
public void testUserAgentString() throws URISyntaxException, StorageException {
    // Test with a blob request
    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    OperationContext sendingRequestEventContext = new OperationContext();
    sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {

        @Override
        public void eventOccurred(SendingRequestEvent eventArg) {
            assertEquals(
                    Constants.HeaderConstants.USER_AGENT_PREFIX
                            + "/"
                            + Constants.HeaderConstants.USER_AGENT_VERSION
                            + " "
                            + String.format(Utility.LOCALE_US, "(Android %s; %s; %s)",
                            android.os.Build.VERSION.RELEASE, android.os.Build.BRAND,
                            android.os.Build.MODEL), ((HttpURLConnection) eventArg.getConnectionObject())
                            .getRequestProperty(Constants.HeaderConstants.USER_AGENT));
        }
    });
    container.exists(null, null, sendingRequestEventContext);

    // Test with a queue request
    CloudQueueClient queueClient = TestHelper.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    queue.exists(null, sendingRequestEventContext);

    // Test with a table request
    CloudTableClient tableClient = TestHelper.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    table.exists(null, sendingRequestEventContext);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:34,代码来源:GenericTests.java

示例10: testQueueMaximumExecutionTime

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class })
public void testQueueMaximumExecutionTime() throws URISyntaxException, StorageException {
    OperationContext opContext = new OperationContext();
    setDelay(opContext, 2500);

    // set the maximum execution time
    QueueRequestOptions options = new QueueRequestOptions();
    options.setMaximumExecutionTimeInMs(2000);

    // set the location mode to secondary, secondary request should fail
    // so set the timeout low to save time failing (or fail with a timeout)
    options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY);
    options.setTimeoutIntervalInMs(1000);

    CloudQueueClient queueClient = TestHelper.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference(generateRandomName("queue"));

    try {
        // 1. download attributes will fail as the queue does not exist
        // 2. the executor will attempt to retry as it is accessing secondary
        // 3. maximum execution time should prevent the retry from being made
        queue.downloadAttributes(options, opContext);
        fail("Maximum execution time was reached but request did not fail.");
    }
    catch (StorageException e) {
        assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage());
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:30,代码来源:MaximumExecutionTimeTests.java

示例11: testUserAgentString

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
@Test
public void testUserAgentString() throws URISyntaxException, StorageException {
    // Test with a blob request
    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    OperationContext sendingRequestEventContext = new OperationContext();
    sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {

        @Override
        public void eventOccurred(SendingRequestEvent eventArg) {
            assertEquals(
                    Constants.HeaderConstants.USER_AGENT_PREFIX
                            + "/"
                            + Constants.HeaderConstants.USER_AGENT_VERSION
                            + " "
                            + String.format(Utility.LOCALE_US, "(JavaJRE %s; %s %s)",
                                    System.getProperty("java.version"),
                                    System.getProperty("os.name").replaceAll(" ", ""),
                                    System.getProperty("os.version")), ((HttpURLConnection) eventArg
                            .getConnectionObject()).getRequestProperty(Constants.HeaderConstants.USER_AGENT));
        }
    });
    container.exists(null, null, sendingRequestEventContext);

    // Test with a queue request
    CloudQueueClient queueClient = TestHelper.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    queue.exists(null, sendingRequestEventContext);

    // Test with a table request
    CloudTableClient tableClient = TestHelper.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    table.exists(null, sendingRequestEventContext);
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:35,代码来源:GenericTests.java

示例12: deleteQueueIfExists

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public boolean deleteQueueIfExists(String queueName) throws InvalidKeyException, URISyntaxException, StorageException {
    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.deleteIfExists();
}
 
开发者ID:Talend,项目名称:components,代码行数:6,代码来源:AzureStorageQueueService.java

示例13: getApproximateMessageCount

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public long getApproximateMessageCount(String queueName) throws InvalidKeyException, URISyntaxException, StorageException {
    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.getApproximateMessageCount();
}
 
开发者ID:Talend,项目名称:components,代码行数:6,代码来源:AzureStorageQueueService.java

示例14: clear

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public void clear(String queueName) throws InvalidKeyException, URISyntaxException, StorageException {
    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    queueRef.clear();
}
 
开发者ID:Talend,项目名称:components,代码行数:6,代码来源:AzureStorageQueueService.java

示例15: main

import com.microsoft.azure.storage.queue.CloudQueueClient; //导入方法依赖的package包/类
public static void main(String[] args) throws InvalidKeyException,
        URISyntaxException, StorageException {

    Utility.printSampleStartInfo("QueueBasicsEncryption");

    // Retrieve storage account information from connection string
    // How to create a storage connection string -
    // https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
    CloudStorageAccount account = CloudStorageAccount
            .parse(Utility.storageConnectionString);
    CloudQueueClient client = account.createCloudQueueClient();
    CloudQueue queue = client.getQueueReference("encryptionqueue"
            + UUID.randomUUID().toString().replace("-", ""));

    try {
        queue.createIfNotExists();

        // Create the IKey used for encryption.
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(1024);
        final KeyPair wrapKey = keyGen.generateKeyPair();

        RsaKey key = new RsaKey("rsaKey1", wrapKey);

        // Create the encryption policy to be used for insert and update.
        QueueEncryptionPolicy insertPolicy = new QueueEncryptionPolicy(key,
                null);

        // Set the encryption policy on the request options.
        QueueRequestOptions insertOptions = new QueueRequestOptions();
        insertOptions.setEncryptionPolicy(insertPolicy);

        String messageStr = UUID.randomUUID().toString();
        CloudQueueMessage message = new CloudQueueMessage(messageStr);

        // Add message
        System.out.println("Inserting the encrypted message.");
        queue.addMessage(message, 0, 0, insertOptions, null);

        // For retrieves, a resolver can be set up that will help pick the
        // key based on the key id.
        LocalResolver resolver = new LocalResolver();
        resolver.add(key);

        QueueEncryptionPolicy retrPolicy = new QueueEncryptionPolicy(null,
                resolver);
        QueueRequestOptions retrieveOptions = new QueueRequestOptions();
        retrieveOptions.setEncryptionPolicy(retrPolicy);

        // Retrieve message
        System.out.println("Retrieving the encrypted message.");
        CloudQueueMessage retrMessage = queue.retrieveMessage(1,
                retrieveOptions, null);

        // Update message
        System.out.println("Updating the encrypted message.");
        String updatedMessage = UUID.randomUUID().toString();
        retrMessage.setMessageContent(updatedMessage);
        queue.updateMessage(retrMessage, 0, EnumSet
                .of(MessageUpdateFields.CONTENT,
                        MessageUpdateFields.VISIBILITY), insertOptions,
                null);

        // Retrieve updated message
        System.out.println("Retrieving the updated encrypted message.");
        retrMessage = queue.retrieveMessage(1, retrieveOptions, null);
    } catch (Throwable t) {
        Utility.printException(t);
    } finally {
        queue.deleteIfExists();
        Utility.printSampleCompleteInfo("QueueBasicsEncryption");
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:74,代码来源:QueueGettingStarted.java


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