use of com.microsoft.azure.storage.queue.CloudQueue in project camel by apache.
the class QueueServiceUtilTest method testGetConfiguredClientUriMismatch.
@Test
public void testGetConfiguredClientUriMismatch() throws Exception {
CloudQueue client = new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue"), newAccountKeyCredentials());
JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
registry.bind("azureQueueClient", client);
QueueServiceComponent component = new QueueServiceComponent(context);
QueueServiceEndpoint endpoint = (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue2?azureQueueClient=#azureQueueClient");
try {
QueueServiceUtil.getConfiguredClient(endpoint.getConfiguration());
fail();
} catch (IllegalArgumentException ex) {
assertEquals("Invalid Client URI", ex.getMessage());
}
}
use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method dequeueFirstQueueMessage.
@NotNull
public QueueMessage dequeueFirstQueueMessage(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
CloudQueueMessage cqm = cloudQueue.retrieveMessage();
String id = "";
String content = "";
Calendar insertionTime = new GregorianCalendar();
Calendar expirationTime = new GregorianCalendar();
int dequeueCount = 0;
if (cqm != null) {
id = Strings.nullToEmpty(cqm.getId());
content = Strings.nullToEmpty(cqm.getMessageContentAsString());
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
dequeueCount = cqm.getDequeueCount();
}
QueueMessage queueMessage = new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount);
if (cqm != null) {
cloudQueue.deleteMessage(cqm);
}
return queueMessage;
} catch (Throwable t) {
throw new AzureCmdException("Error dequeuing the first Queue Message", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method clearQueue.
public void clearQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queue.getName());
cloudQueue.clear();
} catch (Throwable t) {
throw new AzureCmdException("Error clearing the Queue", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createQueue.
@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);
}
}
use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getQueueMessages.
@NotNull
public List<QueueMessage> getQueueMessages(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
List<QueueMessage> qmList = new ArrayList<QueueMessage>();
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
for (CloudQueueMessage cqm : cloudQueue.peekMessages(32)) {
String id = Strings.nullToEmpty(cqm.getId());
String content = Strings.nullToEmpty(cqm.getMessageContentAsString());
Calendar insertionTime = new GregorianCalendar();
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
Calendar expirationTime = new GregorianCalendar();
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
int dequeueCount = cqm.getDequeueCount();
qmList.add(new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount));
}
return qmList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Queue Message list", t);
}
}
Aggregations