Esempio n. 1
0
        public virtual async Task SubscribeAsync()
        {
            await _subscriber.SubscribeAsync((Action <T>) CallBack, _useLock).ConfigureAwait(false);

            var messageName = typeof(T).Name;

            LogInformation($"{messageName} subscription created");
        }
Esempio n. 2
0
        public async Task SubscribeAsync()
        {
            void CallBack(ItemsRemovedFromInventory data)
            {
                _logger.LogInformation($"Beginning processing of ItemsRemovedFromInventory event for AggregateId {data.Id}");
                InMemoryDatabase.Details[data.Id].CurrentCount -= data.Count;
                _logger.LogInformation($"Completed processing of ItemsRemovedFromInventory event for AggregateId {data.Id}");
            }

            await _subscriber.SubscribeAsync((Action <ItemsRemovedFromInventory>) CallBack);

            _logger.LogInformation("ItemsRemovedFromInventory subscription created");
        }
        public async Task SubscribeAsync()
        {
            void CallBack(InventoryItemRenamed data)
            {
                _logger.LogInformation($"Beginning processing of InventoryItemRenamed event for AggregateId {data.Id}");
                InMemoryDatabase.Details[data.Id].Name = data.Name;
                _logger.LogInformation($"Completed processing of InventoryItemRenamed event for AggregateId {data.Id}");
            }

            await _subscriber.SubscribeAsync((Action <InventoryItemRenamed>) CallBack);

            _logger.LogInformation("InventoryItemRenamed subscription created");
        }
Esempio n. 4
0
        public async Task SubscribeAsync()
        {
            void CallBack(InventoryItemCreated data)
            {
                _logger.LogInformation($"Beginning processing of InventoryItemCreated event for AggregateId {data.Id}");
                var inventoryItem = new InventoryItemDetails(data.Id, data.Name, 0, data.Version);

                InMemoryDatabase.Details.Add(data.Id, inventoryItem);
                _logger.LogInformation($"Completed processing of InventoryItemCreated event for AggregateId {data.Id}");
            }

            await _subscriber.SubscribeAsync((Action <InventoryItemCreated>) CallBack);

            _logger.LogInformation("InventoryItemCreated subscription created");
        }
Esempio n. 5
0
        public async Task StreamAsync(String topic, CancellationToken cancellationToken, Func <String, Task> receiveFunction)
        {
            using (var subscription = await eventSubscriber.SubscribeAsync(topic))
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var messages = await subscription.ReceiveAsync(cancellationToken);

                    foreach (var message in messages)
                    {
                        await receiveFunction(message);
                    }
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// add event handler for event
 /// </summary>
 /// <typeparam name="TEvent">TEvent</typeparam>
 /// <typeparam name="TEventHandler">TEventHandler</typeparam>
 /// <returns>whether the operation success</returns>
 public static Task <bool> SubscribeAsync <TEvent, TEventHandler>(this IEventSubscriber subscriber)
     where TEventHandler : class, IEventHandler <TEvent>
     where TEvent : class, IEventBase
 {
     return(subscriber.SubscribeAsync(typeof(TEvent), typeof(TEventHandler)));
 }