Exemple #1
0
        public async Task AQ_Standalone_2()
        {
            queueName = "Test-2-".ToLower() + Guid.NewGuid();
            AzureQueueDataManager manager = await GetTableManager(queueName);

            IEnumerable <CloudQueueMessage> msgs = await manager.GetQueueMessages();

            Assert.IsTrue(msgs == null || msgs.Count() == 0);

            int         numMsgs  = 10;
            List <Task> promises = new List <Task>();

            for (int i = 0; i < numMsgs; i++)
            {
                promises.Add(manager.AddQueueMessage(new CloudQueueMessage(i.ToString())));
            }
            Task.WaitAll(promises.ToArray());
            Assert.AreEqual(numMsgs, await manager.GetApproximateMessageCount());

            msgs = new List <CloudQueueMessage>(await manager.GetQueueMessages(numMsgs));
            Assert.AreEqual(numMsgs, msgs.Count());
            Assert.AreEqual(numMsgs, await manager.GetApproximateMessageCount());

            promises = new List <Task>();
            foreach (var msg in msgs)
            {
                promises.Add(manager.DeleteQueueMessage(msg));
            }
            Task.WaitAll(promises.ToArray());
            Assert.AreEqual(0, await manager.GetApproximateMessageCount());
        }
Exemple #2
0
        public async Task AQ_Standalone_4()
        {
            TimeSpan visibilityTimeout = TimeSpan.FromSeconds(2);

            queueName = "Test-5-".ToLower() + Guid.NewGuid();
            AzureQueueDataManager manager = await GetTableManager(queueName, visibilityTimeout);

            Assert.Equal(0, await manager.GetApproximateMessageCount());

            var inMessage = "Hello, World";
            await manager.AddQueueMessage(inMessage);

            Assert.Equal(1, await manager.GetApproximateMessageCount());

            QueueMessage outMessage = await manager.GetQueueMessage();

            logger.Info("GetQueueMessage: {0}", PrintQueueMessage(outMessage));
            Assert.Equal(inMessage, outMessage.MessageText);

            await Task.Delay(visibilityTimeout);

            Assert.Equal(1, await manager.GetApproximateMessageCount());

            QueueMessage outMessage2 = await manager.GetQueueMessage();

            Assert.Equal(inMessage, outMessage2.MessageText);

            await manager.DeleteQueueMessage(outMessage2);

            Assert.Equal(0, await manager.GetApproximateMessageCount());
        }
        public async Task QueueMessageBatchAsync <T>(Guid streamGuid, String streamNamespace, IEnumerable <T> events, StreamSequenceToken token, Dictionary <string, object> requestContext)
        {
            if (events == null)
            {
                throw new ArgumentNullException("events", "Trying to QueueMessageBatchAsync null data.");
            }
            //int count = events.Count();
            //if (count != 1)
            //{
            //    throw new OrleansException("Trying to QueueMessageBatchAsync a batch of more than one event. " +
            //                               "SimpleAzureQueueAdapter does not support batching. Instead, you can batch in your application code.");
            //}

            object data     = events.First();
            bool   isBytes  = data is byte[];
            bool   isString = data is string;

            if (data != null && !isBytes && !isString)
            {
                throw new OrleansException(
                          string.Format(
                              "Trying to QueueMessageBatchAsync a type {0} which is not a byte[] and not string. " +
                              "SimpleAzureQueueAdapter only supports byte[] or string.", data.GetType()));
            }

            if (Queue == null)
            {
                var tmpQueue = new AzureQueueDataManager(this.loggerFactory, QueueName, DataConnectionString);
                await tmpQueue.InitQueueAsync();

                if (Queue == null)
                {
                    Queue = tmpQueue;
                }
            }
            CloudQueueMessage cloudMsg = null;

            if (isBytes)
            {
                //new CloudQueueMessage(byte[]) not supported in netstandard
                cloudMsg = new CloudQueueMessage(null as string);
                cloudMsg.SetMessageContent2(data as byte[]);
            }
            else if (isString)
            {
                cloudMsg = new CloudQueueMessage(data as string);
            }
            else if (data == null)
            {
                // It's OK to pass null data. why should I care?
                cloudMsg = new CloudQueueMessage(null as string);
            }
            await Queue.AddQueueMessage(cloudMsg);
        }
Exemple #4
0
        public async Task QueueMessageBatchAsync <T>(StreamId streamId, IEnumerable <T> events, StreamSequenceToken token, Dictionary <string, object> requestContext)
        {
            if (events == null)
            {
                throw new ArgumentNullException("events", "Trying to QueueMessageBatchAsync null data.");
            }

            object data     = events.First();
            bool   isBytes  = data is byte[];
            bool   isString = data is string;

            if (data != null && !isBytes && !isString)
            {
                throw new OrleansException(
                          string.Format(
                              "Trying to QueueMessageBatchAsync a type {0} which is not a byte[] and not string. " +
                              "SimpleAzureQueueAdapter only supports byte[] or string.", data.GetType()));
            }

            if (Queue == null)
            {
                var tmpQueue = new AzureQueueDataManager(this.loggerFactory, options.QueueName,
                                                         new AzureQueueOptions {
                    ConnectionString = options.ConnectionString, ServiceUri = options.ServiceUri, TokenCredential = options.TokenCredential
                });
                await tmpQueue.InitQueueAsync();

                if (Queue == null)
                {
                    Queue = tmpQueue;
                }
            }

            string cloudMsg = null;

            if (isBytes)
            {
                cloudMsg = Convert.ToBase64String(data as byte[]);
            }
            else if (isString)
            {
                cloudMsg = data as string;
            }

            await Queue.AddQueueMessage(cloudMsg);
        }
Exemple #5
0
        public async Task AQ_Standalone_1()
        {
            queueName = "Test-1-".ToLower() + Guid.NewGuid();
            AzureQueueDataManager manager = await GetTableManager(queueName);

            Assert.AreEqual(0, await manager.GetApproximateMessageCount());

            CloudQueueMessage inMessage = new CloudQueueMessage("Hello, World");
            await manager.AddQueueMessage(inMessage);

            //Nullable<int> count = manager.ApproximateMessageCount;
            Assert.AreEqual(1, await manager.GetApproximateMessageCount());

            CloudQueueMessage outMessage1 = await manager.PeekQueueMessage();

            logger.Info("PeekQueueMessage 1: {0}", AzureStorageUtils.PrintCloudQueueMessage(outMessage1));
            Assert.AreEqual(inMessage.AsString, outMessage1.AsString);

            CloudQueueMessage outMessage2 = await manager.PeekQueueMessage();

            logger.Info("PeekQueueMessage 2: {0}", AzureStorageUtils.PrintCloudQueueMessage(outMessage2));
            Assert.AreEqual(inMessage.AsString, outMessage2.AsString);

            CloudQueueMessage outMessage3 = await manager.GetQueueMessage();

            logger.Info("GetQueueMessage 3: {0}", AzureStorageUtils.PrintCloudQueueMessage(outMessage3));
            Assert.AreEqual(inMessage.AsString, outMessage3.AsString);
            Assert.AreEqual(1, await manager.GetApproximateMessageCount());

            CloudQueueMessage outMessage4 = await manager.GetQueueMessage();

            Assert.IsNull(outMessage4);

            Assert.AreEqual(1, await manager.GetApproximateMessageCount());

            await manager.DeleteQueueMessage(outMessage3);

            Assert.AreEqual(0, await manager.GetApproximateMessageCount());
        }
Exemple #6
0
        public async Task AQ_Standalone_1()
        {
            queueName = "Test-1-".ToLower() + Guid.NewGuid();
            AzureQueueDataManager manager = await GetTableManager(queueName);

            Assert.Equal(0, await manager.GetApproximateMessageCount());

            var inMessage = "Hello, World";
            await manager.AddQueueMessage(inMessage);

            //Nullable<int> count = manager.ApproximateMessageCount;
            Assert.Equal(1, await manager.GetApproximateMessageCount());

            var outMessage1 = await manager.PeekQueueMessage();

            logger.Info("PeekQueueMessage 1: {0}", PrintQueueMessage(outMessage1));
            Assert.Equal(inMessage, outMessage1.MessageText);

            var outMessage2 = await manager.PeekQueueMessage();

            logger.Info("PeekQueueMessage 2: {0}", PrintQueueMessage(outMessage2));
            Assert.Equal(inMessage, outMessage2.MessageText);

            QueueMessage outMessage3 = await manager.GetQueueMessage();

            logger.Info("GetQueueMessage 3: {0}", PrintQueueMessage(outMessage3));
            Assert.Equal(inMessage, outMessage3.MessageText);
            Assert.Equal(1, await manager.GetApproximateMessageCount());

            QueueMessage outMessage4 = await manager.GetQueueMessage();

            Assert.Null(outMessage4);

            Assert.Equal(1, await manager.GetApproximateMessageCount());

            await manager.DeleteQueueMessage(outMessage3);

            Assert.Equal(0, await manager.GetApproximateMessageCount());
        }