Ejemplo n.º 1
0
        public Task Remove(string messageTypeName, ReferenceWrapper reference)
        {
            var myDictionary = _state.GetOrAdd(messageTypeName, s => new ConcurrentDictionary <string, BrokerServiceState>());

            var queueName = CreateQueueName(messageTypeName, reference);

            if (myDictionary.TryGetValue(_storeKey, out BrokerServiceState subscribers))
            {
                var newState = BrokerServiceState.RemoveSubscriber(subscribers, reference);
                myDictionary.AddOrUpdate(_storeKey, newState, (s, state) => newState);
            }

            _queues.TryRemove(queueName, out reference);

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public async Task Remove(string messageTypeName, ReferenceWrapper reference)
        {
            await Initialize(CancellationToken.None);

            var myDictionary = await GetStateFor(messageTypeName);

            var queueName = CreateQueueName(reference, messageTypeName);

            await StateManager.ExecuteInTransaction(async (tx, token, state) =>
            {
                var subscribers = await myDictionary.TryGetValueAsync(tx, _storeKey, LockMode.Update);
                if (subscribers.HasValue)
                {
                    var newState = BrokerServiceState.RemoveSubscriber(subscribers.Value, reference);
                    await myDictionary.SetAsync(tx, _storeKey, newState);
                }

                await StateManager.RemoveAsync(tx, queueName);

                _queues.TryRemove(queueName, out reference);
            });
        }