Exemplo n.º 1
0
        public override void Run()
        {
            Trace.WriteLine("Starting processing of messages");

            InClient.OnMessage((receivedMessage) =>
            {
                try
                {
                    // Process the message
                    Trace.WriteLine("Processing Service Bus message: "
                                    + receivedMessage.SequenceNumber.ToString());

                    var article = receivedMessage.GetBody <Article>();

                    using (var client = CreateClient())
                    {
                        var str     = JsonConvert.SerializeObject(article);
                        var content = new StringContent(str, Encoding.UTF8, "text/json");
                        var result  = client.PostAsync("api/article", content).Result;
                        result.EnsureSuccessStatusCode();
                    }
                }
                catch
                {
                    // Handle any message processing specific exceptions here
                }
            });

            CompletedEvent.WaitOne();
        }
Exemplo n.º 2
0
        public override void Run()
        {
            Trace.WriteLine("Starting processing of messages");

            InClient.OnMessage((receivedMessage) =>
            {
                try
                {
                    Trace.WriteLine("Processing Service Bus message: " +
                                    receivedMessage.SequenceNumber.ToString());

                    var importFile = receivedMessage.GetBody <ImportFile>();
                    var container  = CreateStorageContainer();
                    var blob       = container.GetBlockBlobReference(importFile.Name);

                    var articles = ReadArticles(blob).ToList();

                    articles.ForEach(article =>
                    {
                        var message = new BrokeredMessage(article);
                        OutClient.Send(message);
                    });

                    receivedMessage.Complete();
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Exception: {0} \n Stack Trace: {1}",
                                     ex.Message, ex.StackTrace);
                }
            });

            CompletedEvent.WaitOne();
        }