コード例 #1
0
        public async Task PublishAsync <TEvent>(TEvent @event, ICorrelationContext context, string tenant = null)
            where TEvent : IEvent
        {
            //  Parallel.ForEach(_busClient, busclient => busclient.PublishAsync(@event, ctx => ctx.UseMessageContext(context)));

            IBusClient client = _busClient.Where(x =>
            {
                //PropertyInfo propertyInfo = typeof(BusClient).GetProperty("_contextFactory", BindingFlags.NonPublic | BindingFlags.Instance);

                //MethodInfo getter = propertyInfo.GetGetMethod(nonPublic: true);

                RawRabbit.Pipe.PipeContextFactory pipeContextFactory = typeof(RawRabbit.BusClient).GetField("_contextFactory", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(x) as PipeContextFactory;



                //PropertyInfo propertyInfoPipeContextFactory = typeof(PipeContextFactory).GetProperty("_config", BindingFlags.NonPublic | BindingFlags.Instance);

                //MethodInfo getterPipeContextFactory = propertyInfoPipeContextFactory.GetGetMethod(nonPublic: true);

                //RawRabbitConfiguration RawRabbitConfiguration = (RawRabbitConfiguration)getterPipeContextFactory.Invoke(PipeContextFactory, null);

                RawRabbit.Configuration.RawRabbitConfiguration RawRabbitConfiguration = typeof(RawRabbit.Pipe.PipeContextFactory).GetField("_config", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pipeContextFactory) as RawRabbit.Configuration.RawRabbitConfiguration;

                if (RawRabbitConfiguration.VirtualHost == tenant)
                {
                    return(true);
                }

                return(false);
            }).SingleOrDefault();


            await client.PublishAsync(@event, ctx => ctx.UseMessageContext(context));
        }
コード例 #2
0
        private string GetVirtualHostInRawRabbitConfiguration(object busClient)
        {
            RawRabbit.Pipe.PipeContextFactory pipeContextFactory = typeof(RawRabbit.BusClient).GetField("_contextFactory", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(busClient) as PipeContextFactory;

            RawRabbit.Configuration.RawRabbitConfiguration RawRabbitConfiguration = typeof(RawRabbit.Pipe.PipeContextFactory).GetField("_config", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pipeContextFactory) as RawRabbit.Configuration.RawRabbitConfiguration;

            return(RawRabbitConfiguration.VirtualHost);
        }