public override void Run() { //Read messages while (true) { BrokeredMessage inputMessage = null; Stream messageStream = null; string messageBody; try { inputMessage = _inputQueueClient.Receive(); Trace.WriteLine(string.Format("Message received: {0}, {1}", inputMessage.SequenceNumber, inputMessage.MessageId)); inputMessage.Complete(); //Retrieve meessage body messageStream = inputMessage.GetBody <Stream>(); TextReader reader = new StreamReader(messageStream, true); //Problem with schema messageBody = reader.ReadToEnd(); var inputMessageObject = JsonConvert.DeserializeObject <Message>(messageBody); //Perform request to third-party notification service. Skeleton implementation IPublishNotificationMessageManager messageManager = new PubNubNotificationMessageManager(); messageManager.Publish(inputMessageObject); } catch (Exception ex) { //Handle failure and send message. Post a copy of the input message to error queue. if (inputMessage != null) { var errorMessage = new BrokeredMessage(messageStream, true); //We are adding and information about the occured exeption. errorMessage.Properties.Add("Exception", ex.Message); errorMessage.Properties.Add("ExceptionStackTrace", ex.StackTrace); _errorQueueClient.Send(errorMessage); } } finally { if (messageStream != null) { messageStream.Close(); } } Thread.Sleep(3000); } // ReSharper disable FunctionNeverReturns }
public override void Run() { //Read messages while (true) { BrokeredMessage inputMessage = null; Stream messageStream = null; string messageBody; try { inputMessage = _inputQueueClient.Receive(); Trace.WriteLine(string.Format("Message received: {0}, {1}", inputMessage.SequenceNumber, inputMessage.MessageId)); inputMessage.Complete(); //Retrieve meessage body messageStream = inputMessage.GetBody<Stream>(); TextReader reader = new StreamReader(messageStream, true); //Problem with schema messageBody = reader.ReadToEnd(); var inputMessageObject = JsonConvert.DeserializeObject<Message>(messageBody); //Perform request to third-party notification service. Skeleton implementation IPublishNotificationMessageManager messageManager = new PubNubNotificationMessageManager(); messageManager.Publish(inputMessageObject); } catch (Exception ex) { //Handle failure and send message. Post a copy of the input message to error queue. if (inputMessage != null) { var errorMessage = new BrokeredMessage(messageStream, true); //We are adding and information about the occured exeption. errorMessage.Properties.Add("Exception", ex.Message); errorMessage.Properties.Add("ExceptionStackTrace", ex.StackTrace); _errorQueueClient.Send(errorMessage); } } finally { if (messageStream != null) messageStream.Close(); } Thread.Sleep(3000); } // ReSharper disable FunctionNeverReturns }