public BrokeredMessage Submit(BrokeredMessage message) { BrokeredMessage brokeredMessage; if (string.IsNullOrEmpty(message.MessageType)) { throw new FaultException("MessageType is not specified"); } if (string.IsNullOrEmpty(message.BodyJson)) { throw new FaultException("BodyJson is not specified"); } //get the appropriate message handler for the message var handler = MessageHandlerFactory.GetHandler(message.MessageType); var returnMessage = handler.HandleMessage(message); if (!(returnMessage is BrokeredMessage)) { brokeredMessage = new BrokeredMessage(); brokeredMessage.MessageType = message.MessageType; var serializer = new JsonNetSerializer(); var str = serializer.Serialize(returnMessage.GetType(), returnMessage) as string; brokeredMessage.BodyJson = str; } else { brokeredMessage = (BrokeredMessage)returnMessage; } return(brokeredMessage); }
private async Task HandleNextMessageAsync(string messageEnvelopeAsString) { try { var payload = JsonConvert.DeserializeObject <MessageBrokerEnvelope <MessageBrokerExternalOrderResponseDto> >(messageEnvelopeAsString); var handler = MessageHandlerFactory.GetHandler(MessageTypes.OrderItemsProcessedByProvider); await handler.ExecuteAsync(payload); } catch (Exception ex) { throw new Exception("Message processing failed.", ex); } }
private void OnMapRequestHandler() { if (ProcessingFinished) { return; } _handler = _factory.GetHandler(Context.Request); if (_handler is NullMessageHandler) { // TODO: handle error here. CompleteProcessing(); } }