Пример #1
0
        public void Complete()
        {
            //await _messageSession.Send(command, sendOptions);
            foreach (Object _event in _messages.Events)
            {
                try
                {
                    _logger.Technical().Information($"Publish event: {_event.GetType().FullName}.").Log();
                    _messageSession.Publish(_event).Wait();
                }
                catch (Exception ex)
                {
                    _logger.Technical().Exception(ex).Log();
                }
            }

            // Send commands.
            foreach (Object command in _messages.Commands)
            {
                try
                {
                    _logger.Technical().Information($"Send command: {command.GetType().FullName}.").Log();
                    _messageSession.Send(command).Wait();
                }
                catch (Exception ex)
                {
                    _logger.Technical().Exception(ex).Log();
                }
            }

            _messages.Clear();
        }
Пример #2
0
        /// <summary>
        /// Method that will be used by NServiceBus to process a message.
        /// The real work is implemented in the Handle(T message) abstract method.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Handle(T message, IMessageHandlerContext context)
        {
            try
            {
                // Create the unit of work list of messages.
                MessagesToPublish.Create();

                // business work to implement.
                await Handle(message);

                // Publish events.
                foreach (Object _event in MessagesToPublish.Events)
                {
                    try
                    {
                        await context.Publish(_event);
                    }
                    catch (System.Exception ex)
                    {
                        Logger.Technical.From(typeof(HandleMessageBase <T>)).Exception(ex).Log();
                    }
                }

                // Send commands.
                foreach (Object command in MessagesToPublish.Commands)
                {
                    try
                    {
                        await context.Send(command);
                    }
                    catch (System.Exception ex)
                    {
                        Logger.Technical.From(typeof(HandleMessageBase <T>)).Exception(ex).Log();
                    }
                }
            }
            catch (System.Exception ex)
            {
                Logger.Technical.From(typeof(HandleMessageBase <T>)).Exception(ex).Log();
            }
            finally
            {
                // Clear messages to avoid any sending of undesirable messages by
                // another message received on the bus.
                MessagesToPublish.Clear();
            }
        }
Пример #3
0
        public void Complete()
        {
            if (null == _instance)
            {
                Logger.Technical().From <MessagesScope>().Warning($"Unable to send any events or commands to the IEndpointConfiguration with the name.").Log();
                return;
            }

            // Publish events.
            foreach (Object _event in MessagesToPublish.Events)
            {
                try
                {
                    Logger.Technical().From <MessagesScope>().System($"Publish event: {_event.GetType().FullName}.").Log();
                    _instance.Publish(_event).Wait();
                }
                catch (Exception ex)
                {
                    Logger.Technical().From <MessagesScope>().Exception(ex).Log();
                }
            }

            // Send commands.
            foreach (Object command in MessagesToPublish.Commands)
            {
                try
                {
                    Logger.Technical().From <MessagesScope>().System($"Send command: {command.GetType().FullName}.").Log();
                    _instance.Send(command).Wait();
                }
                catch (Exception ex)
                {
                    Logger.Technical().From <MessagesScope>().Exception(ex).Log();
                }
            }

            MessagesToPublish.Clear();
        }