コード例 #1
0
        /// <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"/>
        /// </summary>
        /// <param name="posts">The posts to flush</param>
        public void ClearOutbox(params Guid[] posts)
        {
            if (_outBox == null)
            {
                throw new InvalidOperationException("No outbox defined.");
            }
            if (_messageProducer == null)
            {
                throw new InvalidOperationException("No message producer defined.");
            }


            foreach (var messageId in posts)
            {
                var message = _outBox.Get(messageId);
                if (message == null)
                {
                    throw new NullReferenceException($"Message with Id {messageId} not found in the Outbox");
                }

                _logger.Value.InfoFormat("Decoupled invocation of message: Topic:{0} Id:{1}", message.Header.Topic, messageId.ToString());

                RetryAndBreakCircuit(() => { _messageProducer.Send(message); });
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the selected messages from the store
        /// </summary>
        /// <param name="outBox">The store to retrieve from</param>
        /// <param name="messageIds">The messages to retrieve</param>
        /// <returns></returns>
        private static IEnumerable <Message> GetMessagesFromOutBox(IAmAnOutbox <Message> outBox, IReadOnlyCollection <string> messageIds)
        {
            IEnumerable <Message> foundMessages = messageIds
                                                  .Select(messageId => outBox.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);
        }