Пример #1
0
        async static void ProcessReceivedMessage(Task <BrokeredMessage> t)
        {
            EventHubProcessor processor = new EventHubProcessor();

            BrokeredMessage message = t.Result;

            if (message != null)
            {
                var messagestring = message.GetBody <String>();
                try
                {
                    processor.ProcessMessage(JsonConvert.DeserializeObject <Request>(messagestring));
                    //var a = 0;
                    //var i = 1 / a;
                    count = count + 1;
                    Console.WriteLine("Total Count :- {0}", count);
                    message.CompleteAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error :- {0} - {1}", ex.Message, ex.InnerException);
                    message.Abandon();
                }
            }
        }
Пример #2
0
        private static async Task MainServiceBusAsync()
        {
            EventHubProcessor processor = new EventHubProcessor();

            clients.ForEach(serviceClient => serviceClient
                            .OnMessage(message =>
            {
                var messagestring = message.GetBody <String>();
                try
                {
                    processor.ProcessMessage(JsonConvert.DeserializeObject <Request>(messagestring));
                    //var a = 0;
                    //var i = 1 / a;
                    count = count + 1;
                    Console.WriteLine("Total Count1 :- {0}", count);
                    message.CompleteAsync();
                }
                catch (Exception ex)
                {
                    Request objRequest = new Request();
                    objRequest         = JsonConvert.DeserializeObject <Request>(messagestring);
                    //Console.WriteLine("Error :- {0} - {1}", ex.Message, ex.InnerException);
                    //Console.WriteLine("Error :- {0}", messagestring);
                    //Console.WriteLine("Error :- {0} - {1} - {2} -{3}", ex.Message, objRequest.BlobFile,objRequest.Blob,objRequest.ApiAction);
                    message.AbandonAsync();


                    //new  InsertExceptionLog(ex.Message, busMessage.BlobFile);
                }
            }, new OnMessageOptions()
            {
                MaxConcurrentCalls = 100, AutoComplete = false
            })
                            );

            Console.WriteLine("Receiving. Press ENTER to stop worker.");
            Console.ReadLine();
            clients.ForEach(sbclient => sbclient.Close());
        }
Пример #3
0
        private static async Task MainAsync()
        {
            EventHubProcessor processor = new EventHubProcessor();

            clients.ForEach(serviceClient => serviceClient
                            .OnMessage(message =>
            {
                var messagestring = message.GetBody <String>();
                try
                {
                    processor.ProcessMessage(JsonConvert.DeserializeObject <Request>(messagestring));
                    message.CompleteAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error :- {0} - {1}", ex.Message, ex.InnerException);
                    message.AbandonAsync();
                }
            }, new OnMessageOptions()
            {
                MaxConcurrentCalls = 100, AutoComplete = false
            })
                            );
        }