本文整理汇总了Java中com.microsoft.azure.storage.CloudStorageAccount.createCloudQueueClient方法的典型用法代码示例。如果您正苦于以下问题:Java CloudStorageAccount.createCloudQueueClient方法的具体用法?Java CloudStorageAccount.createCloudQueueClient怎么用?Java CloudStorageAccount.createCloudQueueClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.createCloudQueueClient方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
/**
* 初始化
* @return 初始化成功
*/
private synchronized boolean init() {
DebugLog.d(TAG, "init()");
if (blobClient != null && queueClient != null) {
return true;
}
//先查看缓存
Configuration configuration = null;
String azure = configuration.getAzureConf();
Charset charset = Charset.forName("utf-8");
String result = new String(SymmetricalEncryption.decrypt(Algorithm.AES, Base64.decode(azure.getBytes(charset)), MyApp.getApp().a().getBytes(charset)));
String[] result2 = result.split("\\|");
accountName = result2[0];
String key = result2[1];
CloudStorageAccount account = AzureStorage.getAccount(accountName, key);
if (account != null) {
blobClient = account.createCloudBlobClient();
queueClient = account.createCloudQueueClient();
}
DebugLog.d(TAG, "blobClient = " + blobClient);
DebugLog.d(TAG, "queueClient = " + queueClient);
return blobClient != null && queueClient != null;
}
示例2: main
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的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");
}
}
示例3: main
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
/**
* Executes the sample.
*
* @param args
* No input args are expected from users.
* @throws URISyntaxException
* @throws InvalidKeyException
*/
public static void main(String[] args) throws InvalidKeyException, URISyntaxException {
Utility.printSampleStartInfo("QueueBasics");
// Setup the cloud storage account.
CloudStorageAccount account = CloudStorageAccount.parse(Utility.storageConnectionString);
// Create a queue service client
CloudQueueClient queueClient = account.createCloudQueueClient();
try {
// Retrieve a reference to a queue
// Append a random UUID to the end of the queue name so that this
// sample can be run more than once in quick succession.
CloudQueue queue = queueClient.getQueueReference("queuebasics"
+ UUID.randomUUID().toString().replace("-", ""));
// Create the queue if it doesn't already exist
queue.createIfNotExists();
// Create messages and add it to the queue
CloudQueueMessage message1 = new CloudQueueMessage("Hello, World1");
queue.addMessage(message1);
CloudQueueMessage message2 = new CloudQueueMessage("Hello, World2");
queue.addMessage(message2);
CloudQueueMessage message3 = new CloudQueueMessage("Hello, World3");
queue.addMessage(message3);
CloudQueueMessage message4 = new CloudQueueMessage("Hello, World4");
queue.addMessage(message4);
CloudQueueMessage message5 = new CloudQueueMessage("Hello, World5");
queue.addMessage(message5);
// Peek at the next message
CloudQueueMessage peekedMessage = queue.peekMessage();
System.out.println(String.format("Peeked Message : %s", peekedMessage.getMessageContentAsString()));
// Modify the message content and set it to be visible immediately
// Retrieve the first visible message in the queue
CloudQueueMessage updateMessage = queue.retrieveMessage();
updateMessage.setMessageContent("Updated contents.");
EnumSet<MessageUpdateFields> updateFields =
EnumSet.of(MessageUpdateFields.CONTENT, MessageUpdateFields.VISIBILITY);
queue.updateMessage(updateMessage, 0, updateFields, null, null);
// Retrieve 3 messages from the queue with a visibility timeout of 1 second
queue.retrieveMessages(3, 1, null, null);
// Sleep for 2 seconds so the messages become visible and can be processed/deleted
Thread.sleep(2000);
// Retrieve the messages in the queue with a visibility timeout of 30 seconds and delete them
CloudQueueMessage retrievedMessage;
while((retrievedMessage = queue.retrieveMessage(30, null /*options*/, null /*opContext*/)) != null) {
// Process the message in less than 30 seconds, and then delete the message.
System.out.println(retrievedMessage.getMessageContentAsString());
queue.deleteMessage(retrievedMessage);
}
// Delete a queue
queue.deleteIfExists();
}catch (Throwable t) {
Utility.printException(t);
}
Utility.printSampleCompleteInfo("QueueBasics");
}