/// <summary> /// Method to add a custom raw rabbit implementation with options from my appsettings. /// </summary> /// <param name="services"> Add as a singleton service.</param> /// <param name="configuration"> Get the RabbitMq section.</param> /// <returns> IServiceCollection to follow with the pipeline.</returns> public static IServiceCollection AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var rabbitSection = configuration.GetSection("RabbitMq"); var rabbitOptions = new RawRabbitConfiguration(); rabbitSection.Bind(rabbitOptions); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = rabbitOptions }); return(services.AddSingleton <IBusClient>(client)); }
public static void AddRabbitMq(this IServiceCollection service, IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); service.AddSingleton <IBusClient>(_ => client); }
public static IServiceCollection AddRabbitMq(this IServiceCollection service, IConfiguration configuration) { var RabbitMq = new RabbitMqOptions(); var section = configuration.GetSection(nameof(RabbitMq)); section.Bind(RabbitMq); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = RabbitMq }); return(service.AddSingleton <IBusClient>(client)); }
public static void AddRabbitMQ(this IServiceCollection services, IConfiguration configuration, string sectionName = "rabbitmq") { var options = new RabbitMQOptions(); var section = configuration.GetSection(sectionName); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(client); }
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <ImessageBus>(new RabbitQueueMessageBus(client)); }
public static void AddRabbitMQ(this IServiceCollection servi, IConfiguration config) { var opt = new RabbitMQOpt(); var section = config.GetSection("rabbitmq"); section.Bind(opt); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = opt }); servi.AddSingleton <IBusClient>(x => client); }
public override void Load() { Kernel .Bind <IDependencyResolver>() .ToMethod(context => new NinjectAdapter(context)); Kernel .Bind <IInstanceFactory>() .ToMethod(context => RawRabbitFactory.CreateInstanceFactory(context.Kernel.Get <RawRabbitOptions>())) .InSingletonScope(); Kernel .Bind <IBusClient>() .ToMethod(context => context.Kernel.Get <IInstanceFactory>().Create()); }
private static BusClient RabbitMqClientFactory(IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); return(RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options, Plugins = p => p .UseGlobalExecutionId() .UseMessageContext <MessageContext>() })); }
private void ConfigureRabbitMq(IServiceCollection services, IConfigurationSection section) { var options = new RawRabbitConfiguration(); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(_ => client); services.AddSingleton <IFactorialCalculator>(_ => new Factorial()); services.AddTransient <ICommandHandler <CalculateFactorial>, CalculateFactorialHandler>(); }
public static void AddRawRabbit(this IServiceCollection services, IConfiguration configuration) { var settings = new RabbitMQSettings(); var section = configuration.GetSection("rabbitmq"); section.Bind(settings); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = settings, DependencyInjection = ioc => ioc.AddSingleton <ISerializer, CustomSerializer>() }); services.AddSingleton <IBusClient>(client); services.AddScoped <IMessageBus, RawRabbitMessageBus>(); }
private void ConfigureRabbitMq(IServiceCollection services) { var options = new RabbitMqOptions(); var section = Configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(_ => client); services.AddScoped <IEventHandler <ValueCalculated>, ValueCalculatedHandler>(); }
public static void AddBusManager(this IServiceCollection services, IConfiguration configuration) { var options = new RawRabbitConfiguration(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(x => client); services.AddSingleton <BusManager>(x => new BusManager(services, x.GetService <IBusClient>())); services.AddCommandHandler(); }
private void ConfigureRabbitMq(IServiceCollection services) { var options = new RabbitMqOptions(); var section = Configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(_ => client); services.AddSingleton <ICalculator>(_ => new Fast()); services.AddTransient <ICommandHandler <CalculateValue>, CalculateValueHandler>(); }
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("RabbitMq"); section.Bind(options); Console.WriteLine($"Setup RabbitMq on {options.Hostnames[0]}:{options.Port}"); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions() { ClientConfiguration = options }); services.AddSingleton <IBusClient>(client); }
public static IServiceCollection AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { services.Configure <RabbitMqOptions>(configuration.GetSection("RabbitMq")); var provide = services.BuildServiceProvider(); var options = provide.GetService <IOptions <RabbitMqOptions> >(); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options?.Value }); services.AddSingleton <IBusClient>(_ => client); return(services); }
public static IServiceCollection AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var options = new RawRabbitConfiguration(); configuration.GetSection("RabbitMq").Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(_ => client); services.AddScoped <IBusPublisher, BusPublisher>(); return(services); }
private static async Task SendCommand(RawRabbitConfiguration busConfig) { var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = busConfig }); Console.WriteLine("Sending command and waiting for response..."); var submitOrder = new SubmitOrder(Guid.NewGuid(), $"Order - {DateTime.Now}", 1230); var response = await client.RequestAsync <SubmitOrder, SubmitOrderResponse>(submitOrder); Console.WriteLine($"Command {submitOrder.Id} sent successfully."); Console.WriteLine($"Response: {response.Message}"); }
public async Task Should_Honor_Timeout() { /* Setup */ var cfg = RawRabbitConfiguration.Local; cfg.RequestTimeout = TimeSpan.FromMilliseconds(200); var client = RawRabbitFactory.GetExtendableClient(ioc => ioc.AddSingleton(c => cfg)); /* Test */ var chain = client.ExecuteSequence(c => c .PublishAsync <FirstMessage>() .Complete <SecondMessage>() ); /* Assert */ await Assert.ThrowsAsync <TimeoutException>(async() => await chain.Task); }
protected override void Load(ContainerBuilder builder) { builder.Register <IConfiguration>((a, s) => { var configurationBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); return(configurationBuilder.Build()); }).SingleInstance(); builder .Register <IInstanceFactory>(c => RawRabbitFactory.CreateInstanceFactory()) .SingleInstance(); builder .Register <IBusClient>(c => c.Resolve <IInstanceFactory>().Create()); }
public static void AddRabbitMQ( this IServiceCollection serviceCollection, IConfiguration configuration) { RabbitMQOptions options = new RabbitMQOptions(); IConfigurationSection section = configuration.GetSection("RabbitMQ"); section.Bind(options); var client = RawRabbitFactory .CreateSingleton( new RawRabbitOptions { ClientConfiguration = options }); serviceCollection .AddSingleton <IBusClient>(item => client); }
public static IEventBusSubscriber AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var options = new RawRabbitConfiguration(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); var eventsBus = new RabbitMqEventBusWrapper(client); services.AddSingleton <IBusClient>(_ => client); services.AddSingleton <IEventsBus>(_ => eventsBus); var provider = services.BuildServiceProvider(); return(new EventBusSubscriber(eventsBus, provider)); }
static void Main(string[] args) { var rawRabbitOptions = new RawRabbitOptions { ClientConfiguration = GetRawRabbitConfiguration() }; var busClient = RawRabbitFactory.CreateSingleton(); var qq = busClient.SubscribeAsync <CreateInvoiceCommand>(async(msg) => { await Handle(msg); }, CFG => CFG.UseSubscribeConfiguration(F => F.OnDeclaredExchange(E => E.WithName("")) .FromDeclaredQueue(q => q.WithName("createinvoicecommand"))) ); Console.ReadKey(); }
public static void AddRabbitMq(this ContainerBuilder builder) { builder.Register(context => { var configuration = context.Resolve <IConfiguration>(); var options = new RabbitMqOptions(); configuration.GetSection("rabbitmq").Bind(options); return(options); }).SingleInstance(); builder.Register(context => { var configuration = context.Resolve <IConfiguration>(); var options = new RawRabbitConfiguration(); configuration.GetSection("rabbitmq").Bind(options); return(options); }).SingleInstance(); builder.Register <IInstanceFactory>(context => { var options = context.Resolve <RabbitMqOptions>(); var configuration = context.Resolve <RawRabbitConfiguration>(); var namingConventions = new CustomNamingConventions(options.Namespace); var tracer = context.Resolve <ITracer>(); return(RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions { DependencyInjection = ioc => { ioc.AddSingleton(options); ioc.AddSingleton(configuration); ioc.AddSingleton <INamingConventions>(namingConventions); ioc.AddSingleton(tracer); }, ClientConfiguration = options, Plugins = p => p .UseMessageContext <CorrelationContext>() .UseContextForwarding() .UseJaeger(tracer) })); }).SingleInstance(); builder.Register(context => context.Resolve <IInstanceFactory>().Create()); }
protected override void Load(ContainerBuilder builder) { var config = JsonConvert.DeserializeObject <BorrowItRawRabbitConfiguration>(File.ReadAllText(@"./rawrabbit.json")); if (config.Hostnames.Any(x => !x.Equals("localhost"))) { config.Hostnames.Remove("localhost"); } var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = config, DependencyInjection = ioc => ioc.AddSingleton <ISerializer, RabbitSerializer>() }); builder.Register(ctx => client).As <IBusClient>().SingleInstance(); builder.RegisterType <BusPublisher>().As <IBusPublisher>(); builder.Register(ctx => config).As <BorrowItRawRabbitConfiguration>().SingleInstance(); }
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); var namingConventions = new CustomNamingConventions(options.Namespace); section.Bind(options); var rawRabbitOptions = new RawRabbitOptions { ClientConfiguration = options, DependencyInjection = ioc => { ioc.AddSingleton <INamingConventions>(namingConventions); } }; var client = RawRabbitFactory.CreateSingleton(rawRabbitOptions); services.AddSingleton <IBusClient>(_ => client); }
public async Task Should_Use_Routing_Key_Transformer_If_Present() { /* Setup */ var legacyClient = RawRabbitFactory.GetExtendableClient(ioc => ioc.AddSingleton(s => RawRabbitConfiguration.Local.AsLegacy())); var currentClient = RawRabbitFactory.GetExtendableClient(); var legacyTcs = new TaskCompletionSource <BasicMessage>(); var currentTcs = new TaskCompletionSource <BasicMessage>(); currentClient.SubscribeAsync <BasicMessage>((message, context) => { if (!currentTcs.Task.IsCompleted) { currentTcs.SetResult(message); return(currentTcs.Task); } if (!legacyTcs.Task.IsCompleted) { legacyTcs.SetResult(message); return(legacyTcs.Task); } return(Task.FromResult(true)); }); /* Test */ // 1. Verify subscriber currentClient.PublishAsync <BasicMessage>(); await currentTcs.Task; // 2. Change Type await currentClient.UpdateTopologyAsync(c => c .ExchangeForMessage <BasicMessage>() .UseConfiguration( exchange => exchange.WithType(ExchangeType.Direct), bindingKey => bindingKey.Replace(".#", string.Empty)) ); // 3. Verify subscriber legacyClient.PublishAsync <BasicMessage>(); await legacyTcs.Task; /* Assert */ Assert.True(true); }
private static void ConfigureBus <TContext>(IConveyBuilder builder, Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins = null) where TContext : ICorrelationContext, new() { builder.Services.AddSingleton <IInstanceFactory>(serviceProvider => { var register = plugins?.Invoke(new RabbitMqPluginRegister(serviceProvider)); var options = serviceProvider.GetService <RabbitMqOptions>(); var configuration = serviceProvider.GetService <RawRabbitConfiguration>(); var namingConventions = new CustomNamingConventions(options.Namespace); return(RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions { DependencyInjection = ioc => { register?.Register(ioc); ioc.AddSingleton(options); ioc.AddSingleton(configuration); ioc.AddSingleton(serviceProvider); ioc.AddSingleton <INamingConventions>(namingConventions); ioc.AddSingleton <ISerializer, Serializer <TContext> >(ctx => new Serializer <TContext>(ctx.GetService <JsonSerializer>())); }, Plugins = p => { register?.Register(p); p.UseAttributeRouting() .UseRetryLater() .UpdateRetryInfo() .UseMessageContext <TContext>() .UseContextForwarding(); if (options.MessageProcessor?.Enabled == true) { p.ProcessUniqueMessages(); } } })); }); builder.Services.AddTransient(serviceProvider => serviceProvider.GetService <IInstanceFactory>().Create()); }
private static IServiceCollection AddRawRabbitServices(this IServiceCollection collection, Action <IDependencyRegister> ioc) { Action <IDependencyRegister> customServices = register => register.AddSingleton <ISerializer>(new JsonSerializer(new Newtonsoft.Json.JsonSerializer())); if (ioc != null) { customServices += ioc; } collection .AddSingleton <IBusClient>(RawRabbitFactory.CreateSingleton(new RawRabbitOptions { DependencyInjection = customServices })) .AddSingleton <IMessagePublisher, MessagePublisher>() .AddSingleton <IMessageSubscriber, MessageSubscriber>(); return(collection); }
public static void AddRabbitMq(this IServiceCollection service, IConfiguration configuration) { /* * var connectionString = configuration.GetConnectionString("rabbitmq"); * var config = ConnectionStringParser.Parse(connectionString); * var client = BusClientFactory.CreateDefault(config); */ var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); service.AddSingleton <IBusClient>(_ => client); }
private static void ConfigureBus(ContainerBuilder builder) { builder.Register <IInstanceFactory>(context => { var options = context.Resolve <RabbitMqOptions>(); var configuration = context.Resolve <RawRabbitConfiguration>(); var namingConventions = new CustomNamingConventions(options.Namespace); return(RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions { DependencyInjection = ioc => { ioc.AddSingleton(options); ioc.AddSingleton(configuration); ioc.AddSingleton <INamingConventions>(namingConventions); } })); }).SingleInstance(); builder.Register(context => context.Resolve <IInstanceFactory>().Create()); }