当前位置: 首页>>代码示例>>C#>>正文


C# IMessageContext.Set方法代码示例

本文整理汇总了C#中IMessageContext.Set方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageContext.Set方法的具体用法?C# IMessageContext.Set怎么用?C# IMessageContext.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessageContext的用法示例。


在下文中一共展示了IMessageContext.Set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessageFailedProcessing

        /// <summary>
        /// Invoked when a message has failed to process.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="context">The context.</param>
        /// <param name="exception">The exception.</param>
        public ReceiveMessagesErrorResult MessageFailedProcessing(IReceivedMessageInternal message, IMessageContext context, Exception exception)
        {
            //message failed to process
            if (context.MessageId == null || !context.MessageId.HasValue) return ReceiveMessagesErrorResult.NoActionPossible;

            var info =
                _configuration.TransportConfiguration.RetryDelayBehavior.GetRetryAmount(exception);
            string exceptionType = null;
            if (info.ExceptionType != null)
            {
                exceptionType = info.ExceptionType.ToString();
            }

            var bSendErrorQueue = false;
            if (string.IsNullOrEmpty(exceptionType) || info.MaxRetries <= 0)
            {
                bSendErrorQueue = true;
            }
            else
            {
                //determine how many times this exception has been seen for this message
                var retries =
                    _queryErrorRetryCount.Handle(
                        new GetErrorRetryCountQuery(exceptionType,
                            (long) context.MessageId.Id.Value));
                if (retries >= info.MaxRetries)
                {
                    bSendErrorQueue = true;
                }
                else
                {
                    context.Set(_headers.IncreaseQueueDelay, new SqlQueueDelay(info.Times[retries]));
                    //note zero based index - use the current count not count +1
                    _commandSetErrorCount.Handle(
                        new SetErrorCountCommand(
                            exceptionType, (long) context.MessageId.Id.Value));
                }
            }

            if (!bSendErrorQueue) return ReceiveMessagesErrorResult.Retry;

            _commandMoveRecord.Handle(
                new MoveRecordToErrorQueueCommand(exception, (long)context.MessageId.Id.Value, context));
            //we are done doing any processing - remove the messageID to block other actions
            context.MessageId = null;
            _log.ErrorException("Message with ID {0} has failed and has been moved to the error queue", exception,
                message.MesssageId);
            return ReceiveMessagesErrorResult.Error;
        }
开发者ID:blehnen,项目名称:DotNetWorkQueue,代码行数:55,代码来源:SqLiteMessageQueueReceiveErrorMessage.cs

示例2: GetConnectionAndSetOnContext

        /// <summary>
        /// Creates the connection object for the parent caller and stores it on the worker context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private Connection GetConnectionAndSetOnContext(IMessageContext context)
        {
            var connection = _connectionFactory.Create();
            context.Set(_sqlHeaders.Connection, connection);

            //wire up the context commit/rollback/dispose delegates
            if (!_configuration.Options().EnableHoldTransactionUntilMessageCommited)
            {
                context.Commit += ContextOnCommit;
                context.Rollback += ContextOnRollback;
            }
            else
            {
                context.Commit += ContextOnCommitTransaction;
                context.Rollback += ContextOnRollbackTransaction;
            }
            context.Cleanup += context_Cleanup;
            return connection;
        }
开发者ID:blehnen,项目名称:DotNetWorkQueue,代码行数:24,代码来源:SQLServerMessageQueueReceive.cs


注:本文中的IMessageContext.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。