Exemple #1
0
 public StaticConsumeContext(ReceiveContext receiveContext, object message, Header[] headers)
     : base(receiveContext)
 {
     _message        = message;
     _binaryHeaders  = headers;
     _supportedTypes = GetSupportedMessageTypes().ToArray();
     _messageTypes   = new Dictionary <Type, ConsumeContext>();
     _consumeTasks   = new PendingTaskCollection(4);
 }
        public RawJsonConsumeContext(JsonSerializer deserializer, ReceiveContext receiveContext, JToken messageToken, Guid?messageId = default)
            : base(receiveContext)
        {
            _messageToken = messageToken ?? new JObject();
            _messageId    = messageId;

            _deserializer = deserializer;
            _messageTypes = new Dictionary <Type, ConsumeContext>();
            _consumeTasks = new PendingTaskCollection(4);
        }
Exemple #3
0
        public RawJsonConsumeContext(JsonSerializer deserializer, ReceiveContext receiveContext, JToken messageToken)
            : base(receiveContext)
        {
            _messageToken = messageToken ?? new JObject();

            _deserializer = deserializer;
            _messageTypes = new Dictionary <Type, ConsumeContext>();
            _consumeTasks = new PendingTaskCollection(4);

            MessageId     = receiveContext.TransportHeaders.Get <Guid>(nameof(MessageContext.MessageId));
            CorrelationId = receiveContext.TransportHeaders.Get <Guid>(nameof(MessageContext.CorrelationId));
            RequestId     = receiveContext.TransportHeaders.Get <Guid>(nameof(MessageContext.RequestId));
        }
        public JsonConsumeContext(JsonSerializer deserializer, ReceiveContext receiveContext, MessageEnvelope envelope)
            : base(receiveContext)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            _envelope       = envelope;
            _deserializer   = deserializer;
            _messageToken   = GetMessageToken(envelope.Message);
            _supportedTypes = envelope.MessageType.ToArray();
            _messageTypes   = new Dictionary <Type, ConsumeContext>();
            _consumeTasks   = new PendingTaskCollection(4);
        }
        public Task CancelAllScheduledMessages()
        {
            ScheduledMessage[] scheduledMessages;

            lock (_listLock)
                scheduledMessages = _scheduledMessages.ToArray();

            var tasks = new PendingTaskCollection(scheduledMessages.Length);

            foreach (var scheduledMessage in scheduledMessages)
            {
                tasks.Add(_context.CancelScheduledSend(scheduledMessage.Destination, scheduledMessage.TokenId));
            }

            return(tasks.Completed());
        }
        public async Task ExecutePendingActions(bool concurrentMessageDelivery)
        {
            _clearToSend.TrySetResult(this);

            Func <Task>[] pendingActions;
            lock (_pendingActions)
                pendingActions = _pendingActions.ToArray();

            if (pendingActions.Length > 0)
            {
                if (concurrentMessageDelivery)
                {
                    var collection = new PendingTaskCollection(pendingActions.Length);

                    collection.Add(pendingActions.Select(action => action()));

                    await collection.Completed().ConfigureAwait(false);
                }
                else
                {
                    foreach (Func <Task> action in pendingActions)
                    {
                        var task = action();
                        if (task != null)
                        {
                            await task.ConfigureAwait(false);
                        }
                    }
                }
            }

            if (_outboxSchedulerContext != null)
            {
                try
                {
                    await _outboxSchedulerContext.ExecutePendingActions().ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    LogContext.Warning?.Log(e, "One or more messages could not be unscheduled.", e);
                }
            }
        }
        protected BaseReceiveContext(bool redelivered, ReceiveEndpointContext receiveEndpointContext, params object[] payloads)
            : base(receiveEndpointContext, payloads)
        {
            _receiveTimer = Stopwatch.StartNew();

            _cancellationTokenSource = new CancellationTokenSource();
            _receiveEndpointContext  = receiveEndpointContext;

            InputAddress = receiveEndpointContext.InputAddress;
            Redelivered  = redelivered;

            _headers = new Lazy <Headers>(() => new JsonTransportHeaders(HeaderProvider));

            _contentType  = new Lazy <ContentType>(GetContentType);
            _receiveTasks = new PendingTaskCollection(4);

            _sendEndpointProvider    = new Lazy <ISendEndpointProvider>(GetSendEndpointProvider);
            _publishEndpointProvider = new Lazy <IPublishEndpointProvider>(GetPublishEndpointProvider);
        }
        protected BaseReceiveContext(Uri inputAddress, bool redelivered, CancellationTokenSource source, ReceiveEndpointContext receiveEndpointContext)
            : base(new PayloadCacheScope(receiveEndpointContext), source.Token)
        {
            _receiveTimer = Stopwatch.StartNew();

            _cancellationTokenSource = source;
            _receiveEndpointContext  = receiveEndpointContext;

            InputAddress = inputAddress;
            Redelivered  = redelivered;

            _headers = new Lazy <Headers>(() => new JsonHeaders(ObjectTypeDeserializer.Instance, HeaderProvider));

            _contentType  = new Lazy <ContentType>(GetContentType);
            _receiveTasks = new PendingTaskCollection(source.Token);

            _sendEndpointProvider    = new Lazy <ISendEndpointProvider>(GetSendEndpointProvider);
            _publishEndpointProvider = new Lazy <IPublishEndpointProvider>(GetPublishEndpointProvider);
        }
        public Task ExecutePendingActions()
        {
            Func <Task>[] cancelMessages;
            lock (_listLock)
            {
                if (_cancelMessages.Count == 0)
                {
                    return(TaskUtil.Completed);
                }

                cancelMessages = _cancelMessages.ToArray();
            }

            var tasks = new PendingTaskCollection(cancelMessages.Length);

            foreach (Func <Task> cancel in cancelMessages)
            {
                tasks.Add(cancel());
            }

            return(tasks.Completed());
        }
 protected DeserializerConsumeContext(ReceiveContext receiveContext)
     : base(receiveContext)
 {
     _consumeTasks = new PendingTaskCollection(4);
 }