/// <inheritdoc /> public void Process(IMqMessageQueueClient mqClient) { foreach (var processQueueName in this.ProcessQueueNames) { this.ProcessQueue(mqClient, processQueueName); } }
private void DisposeMqClient() { // Disposing mqClient causes an EndOfStreamException to be thrown in StartSubscription if (this._mqClient == null) { return; } this._mqClient.Dispose(); this._mqClient = null; }
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" }); }
/// <inheritdoc /> public int ProcessQueue(IMqMessageQueueClient mqClient, string queueName, Func <bool> doNext = null) { var msgsProcessed = 0; try { IMqMessage <T> message; while ((message = mqClient.GetAsync <T>(queueName)) != null) { this.ProcessMessage(mqClient, message); msgsProcessed++; if (doNext != null && !doNext()) { return(msgsProcessed); } } } catch (Exception ex) { this._logger.Error(ex, "Error serializing message from mq server."); } return(msgsProcessed); }
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; } }
/// <inheritdoc /> public void ProcessMessage(IMqMessageQueueClient mqClient, object mqResponse) { var message = mqClient.CreateMessage <T>(mqResponse); this.ProcessMessage(mqClient, message); }