/// <summary> /// Reposts the specified message identifier. It retrieves a message previously posted via Post, from the Message Store, and publishes it /// onto the Work Queue again. /// </summary> /// <param name="messageId">The message identifier.</param> public void Repost(Guid messageId) { var requestedMessageid = messageId; //avoid closure on this logger.InfoFormat("Resend of message: {0}", requestedMessageid); /* * NOTE: Don't rewrite with await, compiles but Policy does not call await on the lambda so becomes fire and forget, * see http://blogs.msdn.com/b/pfxteam/archive/2012/02/08/10265476.aspx */ RetryAndBreakCircuit(() => { var task = messageStore.Get(messageId); task.Wait(); var message = task.Result; if (message.Header.MessageType == MessageType.MT_NONE) { logger.WarnFormat("Message {0} not found", requestedMessageid); return; } messagingGateway.Send(message); }); }
/// <summary> /// Flushes the message box message given by <param name="posts"> to the broker. /// Intended for use with the Outbox pattern: http://gistlabs.com/2014/05/the-outbox/ <see cref="DepositPostBox"/> /// <param name="posts">The posts to flush</param> public void ClearPostBox(params Guid[] posts) { if (_messageStore == null) { throw new InvalidOperationException("No message store defined."); } if (_messageProducer == null) { throw new InvalidOperationException("No mesage producer defined."); } foreach (var messageId in posts) { var message = _messageStore.Get(messageId); if (message == null) { throw new NullReferenceException($"Message with Id {messageId} not found in the Message Store"); } _logger.Value.InfoFormat("Decoupled invocation of message: Topic:{0} Id:{1}", message.Header.Topic, messageId.ToString()); RetryAndBreakCircuit(() => { _messageProducer.Send(message); }); } }
/// <summary> /// Gets the selected messages from the store /// </summary> /// <param name="messageStore">The store to retrieve from</param> /// <param name="messageIds">The messages to retrieve</param> /// <returns></returns> private static IEnumerable<Message> GetMessagesFromStore(IAmAMessageStore<Message> messageStore, IReadOnlyCollection<string> messageIds) { IEnumerable<Message> foundMessages = messageIds .Select(messageId => messageStore.Get(Guid.Parse(messageId))) .Where(fm => fm != null) .ToList(); if (foundMessages.Count() < messageIds.Count) { throw new SystemException("Cannot find messages " + string.Join(",", messageIds.Where(id => foundMessages.All(fm => fm.Id.ToString() != id.ToString())).ToArray())); } return foundMessages; }
/// <summary> /// Gets the selected messages from the store /// </summary> /// <param name="messageStore">The store to retrieve from</param> /// <param name="messageIds">The messages to retrieve</param> /// <returns></returns> private static IEnumerable <Message> GetMessagesFromStore(IAmAMessageStore <Message> messageStore, IReadOnlyCollection <string> messageIds) { IEnumerable <Message> foundMessages = messageIds .Select(messageId => messageStore.Get(Guid.Parse(messageId))) .Where(fm => fm != null) .ToList(); if (foundMessages.Count() < messageIds.Count) { throw new IndexOutOfRangeException("Cannot find messages " + string.Join(",", messageIds.Where(id => foundMessages.All(fm => fm.Id.ToString() != id.ToString())).ToArray())); } return(foundMessages); }
/// <summary> /// Reposts the specified message identifier. It retrieves a message previously posted via Post, from the Message Store, and publishes it /// onto the Work Queue again. /// </summary> /// <param name="messageId">The message identifier.</param> public void Repost(Guid messageId) { var requestedMessageid = messageId; //avoid closure on this logger.Info(m => m("Resend of request: {0}", requestedMessageid)); /* * NOTE: Don't rewrite with await, compiles but Policy does not call await on the lambda so becomes fire and forget, * see http://blogs.msdn.com/b/pfxteam/archive/2012/02/08/10265476.aspx */ RetryAndBreakCircuit(() => { var task = messageStore.Get(messageId); task.Wait(); var message = task.Result; messagingGateway.Send(message); }); }