本文整理汇总了Java中com.microsoft.azure.storage.queue.CloudQueueClient类的典型用法代码示例。如果您正苦于以下问题:Java CloudQueueClient类的具体用法?Java CloudQueueClient怎么用?Java CloudQueueClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudQueueClient类属于com.microsoft.azure.storage.queue包,在下文中一共展示了CloudQueueClient类的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;
}
示例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;
}
示例3: callUploadServiceProps
import com.microsoft.azure.storage.queue.CloudQueueClient; //导入依赖的package包/类
private void callUploadServiceProps(
ServiceClient client, ServiceProperties props, FileServiceProperties fileProps)
throws StorageException, InterruptedException {
if (client.getClass().equals(CloudBlobClient.class)) {
((CloudBlobClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudTableClient.class)) {
((CloudTableClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudQueueClient.class)) {
((CloudQueueClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudFileClient.class)) {
((CloudFileClient) client).uploadServiceProperties(fileProps);
}
else {
fail();
}
Thread.sleep(30000);
}
示例4: callDownloadServiceProperties
import com.microsoft.azure.storage.queue.CloudQueueClient; //导入依赖的package包/类
private ServiceProperties callDownloadServiceProperties(ServiceClient client) throws StorageException {
if (client.getClass().equals(CloudBlobClient.class)) {
CloudBlobClient blobClient = (CloudBlobClient) client;
return blobClient.downloadServiceProperties();
}
else if (client.getClass().equals(CloudTableClient.class)) {
CloudTableClient tableClient = (CloudTableClient) client;
return tableClient.downloadServiceProperties();
}
else if (client.getClass().equals(CloudQueueClient.class)) {
CloudQueueClient queueClient = (CloudQueueClient) client;
return queueClient.downloadServiceProperties();
}
else {
fail();
}
return null;
}
示例5: 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();
}
}
示例6: 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());
}
示例7: createCloudQueueClient
import com.microsoft.azure.storage.queue.CloudQueueClient; //导入依赖的package包/类
/**
* Creates a new Queue service client.
*
* @return A client object that uses the Queue service endpoint.
*/
public CloudQueueClient createCloudQueueClient() {
if (this.getQueueStorageUri() == null) {
throw new IllegalArgumentException(SR.QUEUE_ENDPOINT_NOT_CONFIGURED);
}
if (this.credentials == null) {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
return new CloudQueueClient(this.getQueueStorageUri(), this.getCredentials());
}
示例8: callUploadServiceProps
import com.microsoft.azure.storage.queue.CloudQueueClient; //导入依赖的package包/类
private void callUploadServiceProps(
ServiceClient client, ServiceProperties props, FileServiceProperties fileProps)
throws StorageException, InterruptedException {
if (client.getClass().equals(CloudBlobClient.class)) {
((CloudBlobClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudTableClient.class)) {
((CloudTableClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudQueueClient.class)) {
((CloudQueueClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudFileClient.class)) {
((CloudFileClient) client).uploadServiceProperties(fileProps);
}
else {
fail();
}
// It may take up to 30 seconds for the settings to take effect, but the new properties are immediately
// visible when querying service properties.
}
示例9: 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;
}
}
示例10: getSchemaNames
import com.microsoft.azure.storage.queue.CloudQueueClient; //导入依赖的package包/类
@Override
public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException {
List<NamedThing> result = new ArrayList<>();
try {
CloudQueueClient client = getStorageQueueClient(container);
for (CloudQueue q : client.listQueues()) {
result.add(new SimpleNamedThing(q.getName(), q.getName()));
}
} catch (InvalidKeyException | URISyntaxException e) {
throw new ComponentException(e);
}
return result;
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: createCloudQueueClient
import com.microsoft.azure.storage.queue.CloudQueueClient; //导入依赖的package包/类
/**
* Creates a new Queue service client.
*
* @return A client object that uses the Queue service endpoint.
*/
public CloudQueueClient createCloudQueueClient() {
if (this.getQueueStorageUri() == null) {
throw new IllegalArgumentException(SR.QUEUE_ENDPOINT_NOT_CONFIGURED);
}
if (this.credentials == null) {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.credentials)) {
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
return new CloudQueueClient(this.getQueueStorageUri(), this.getCredentials());
}
示例15: 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);
}