Exemple #1
0
        public async Task Receive(string queueName, Type type)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_ConnectionString);
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
            CloudQueue          queue          = queueClient.GetQueueReference(queueName);

            string messageText = "";

            do
            {
                var message = await ReceiveMessageAsync(queue);

                if (message == null)
                {
                    continue;
                }

                messageText = message.ToString();
                try
                {
                    CustomerCommandHandler obj = new CustomerCommandHandler(_CustomerService);

                    var CustomerCommand = Newtonsoft.Json.JsonConvert.DeserializeObject(messageText, type);

                    var context = obj.GetType();

                    var method = context.GetMethod("Handle", new Type[] { type });

                    method.Invoke(obj, new object[] { CustomerCommand });
                }
                catch (Exception ex) { Console.WriteLine(messageText); };
                System.Threading.Thread.Sleep(1000);
            } while (true);
        }