private static void Publish_4_NothingHere_messages(IMqMessageQueueClient mqClient) { mqClient.Publish(new NothingHere { Value = "Hello" }); mqClient.Publish(new NothingHere { Value = "World" }); mqClient.Publish(new NothingHere { Value = "TheOne" }); mqClient.Publish(new NothingHere { Value = "Redis" }); }
internal static void Publish_4_messages(IMqMessageQueueClient mqClient) { mqClient.Publish(new Reverse { Value = "Hello" }); mqClient.Publish(new Reverse { Value = "World" }); mqClient.Publish(new Reverse { Value = "TheOne" }); mqClient.Publish(new Reverse { Value = "Redis" }); }
public void ProcessMessage(IMqMessageQueueClient mqClient, IMqMessage <T> message) { this.MqClient = mqClient; var msgHandled = false; try { var response = this._processMessageFn(message); if (response is Exception responseEx) { this.TotalMessagesFailed++; if (message.ReplyTo != null) { var responseDto = response; mqClient.Publish(message.ReplyTo, MqMessageFactory.Create(responseDto)); return; } if (responseEx is AggregateException) { responseEx = responseEx.UnwrapIfSingleException(); } msgHandled = true; this._processInExceptionFn(this, message, responseEx); return; } this.TotalMessagesProcessed++; // If there's no response, do nothing if (response != null) { var responseMessage = response as IMqMessage; var responseType = responseMessage != 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 ?? new MqQueueNames(responseType).Direct; // Otherwise send to our trusty response Queue if (responseMessage == null) { responseMessage = MqMessageFactory.Create(response); } responseMessage.ReplyId = message.Id; mqClient.Publish(mqReplyTo, responseMessage); } } catch (Exception ex) { try { if (ex is AggregateException) { ex = ex.UnwrapIfSingleException(); } this.TotalMessagesFailed++; msgHandled = true; this._processInExceptionFn(this, message, ex); } catch (Exception exHandlerEx) { this._logger.Error(exHandlerEx, "Message exception handler threw an error."); } } finally { if (!msgHandled) { mqClient.Ack(message); } this.TotalNormalMessagesReceived++; this.LastMessageProcessed = DateTime.Now; } }