public void SendOneWay(string queueName, object requestDto) { Publish(queueName, MessageFactory.Create(requestDto)); }
public void ProcessMessage(IMessageQueueClient mqClient, IMessage <T> message) { this.MqClient = mqClient; bool msgHandled = false; try { var response = processMessageFn(message); var responseEx = response as Exception; if (responseEx == null) { var responseStatus = response.GetResponseStatus(); var isError = responseStatus?.ErrorCode != null; if (isError) { responseEx = new MessagingException(responseStatus, response); } } if (responseEx != null) { TotalMessagesFailed++; if (message.ReplyTo != null) { var replyClient = ReplyClientFactory(message.ReplyTo); if (replyClient != null) { replyClient.SendOneWay(message.ReplyTo, response); } else { var responseDto = response.GetResponseDto(); mqClient.Publish(message.ReplyTo, MessageFactory.Create(responseDto)); } return; } msgHandled = true; processInExceptionFn(this, message, responseEx); return; } this.TotalMessagesProcessed++; //If there's no response publish the request message to its OutQ if (response == null) { if (message.ReplyTo != null) { response = message.GetBody(); } else { var publishOutqResponses = PublishToOutqWhitelist == null; if (!publishOutqResponses) { var inWhitelist = PublishToOutqWhitelist.Contains(QueueNames <T> .Out); if (!inWhitelist) { return; } } var messageOptions = (MessageOption)message.Options; if (messageOptions.Has(MessageOption.NotifyOneWay)) { mqClient.Notify(QueueNames <T> .Out, message); } } } response = response.GetResponseDto(); if (response != null) { var responseMessage = response as IMessage; var responseType = responseMessage != null ? (responseMessage.Body != null ? responseMessage.Body.GetType() : typeof(object)) : response.GetType(); //If there's no explicit ReplyTo, send it to the typed Response InQ by default var mqReplyTo = message.ReplyTo; if (mqReplyTo == null) { //Disable default handling of MQ Responses if whitelist exists and Response not in whitelist var publishAllResponses = PublishResponsesWhitelist == null; if (!publishAllResponses) { var inWhitelist = PublishResponsesWhitelist.Any( publishResponse => responseType.GetOperationName() == publishResponse || responseType.Name == publishResponse); if (!inWhitelist) { return; } } // Leave as-is to work around a Mono 2.6.7 compiler bug if (!responseType.IsUserType()) { return; } mqReplyTo = new QueueNames(responseType).In; } var replyClient = ReplyClientFactory(mqReplyTo); if (replyClient != null) { try { replyClient.SendOneWay(mqReplyTo, response); return; } catch (Exception ex) { Log.Error($"Could not send response to '{mqReplyTo}' with client '{replyClient.GetType().GetOperationName()}'", ex); // Leave as-is to work around a Mono 2.6.7 compiler bug if (!responseType.IsUserType()) { return; } mqReplyTo = new QueueNames(responseType).In; } } //Otherwise send to our trusty response Queue (inc if replyClient fails) if (responseMessage == null) { responseMessage = MessageFactory.Create(response); } responseMessage.ReplyId = message.Id; mqClient.Publish(mqReplyTo, responseMessage); } } catch (Exception ex) { try { if (ex is AggregateException) { ex = ex.UnwrapIfSingleException(); } TotalMessagesFailed++; msgHandled = true; processInExceptionFn(this, message, ex); } catch (Exception exHandlerEx) { Log.Error("Message exception handler threw an error", exHandlerEx); } } finally { if (!msgHandled) { mqClient.Ack(message); } this.TotalNormalMessagesReceived++; LastMessageProcessed = DateTime.UtcNow; } }
public void SendOneWay(object requestDto) { Publish(MessageFactory.Create(requestDto)); }