示例#1
0
        public async Task SendToMinionsAsync(IClaptrapIdentity masterId, IEvent @event)
        {
            if (_minionDesignsLookup.Contains(masterId.TypeCode))
            {
                try
                {
                    var minionDesigns = _minionDesignsLookup[masterId.TypeCode];
                    await Task.WhenAll(SendCore(minionDesigns));

                    IEnumerable <Task> SendCore(IEnumerable <IClaptrapDesign> designs)
                    {
                        foreach (var design in designs)
                        {
                            var proxy = _minionLocator.CreateProxy(new ClaptrapIdentity(masterId.Id,
                                                                                        design.ClaptrapTypeCode));
                            yield return(proxy.MasterEventReceivedAsync(new[] { @event }));
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "something error while calling minions, {identity}", masterId);
                }
            }
            else
            {
                _logger.LogTrace(
                    "can not found minion design in design store for type code : {typeCode}",
                    masterId.TypeCode);
            }
        }
示例#2
0
        private async Task AsyncEventingBasicConsumerOnReceived(object sender,
                                                                BasicDeliverEventArgs args,
                                                                IClaptrapDesign minionDesign)
        {
            _logger.LogDebug("message received from rabbit mq, exchange : {exchange} ,routeKey : {routeKey}",
                             args.Exchange,
                             args.RoutingKey);
            var consumer = (IAsyncBasicConsumer)sender;

            consumer.Model.BasicAck(args.DeliveryTag, false);
            var payload     = Decompress(args);
            var data        = _messageSerializer.Deserialize(payload);
            var evt         = _eventStringSerializer.Deserialize(data);
            var minionId    = new ClaptrapIdentity(evt.ClaptrapIdentity.Id, minionDesign.ClaptrapTypeCode);
            var minionProxy = _minionLocator.CreateProxy(minionId);

            _logger.LogTrace("create minion proxy for {id}", minionId);
            await minionProxy.MasterEventReceivedAsync(new[] { evt });

            _logger.LogDebug("a message sent to minion {minionId}", minionId);
        }