private static void RegisterRabbitMq(IServiceCollection serviceCollection,
                                             PublisherRabbitMqSettings rabbitMqSettings,
                                             Action <IRabbitMqBusFactoryConfigurator, IBusRegistrationContext> rabbitMqBusConfiguratorAction = null,
                                             Action <IServiceCollectionBusConfigurator> configuratorAction = null)
        {
            serviceCollection.AddEventsMassTransitSerializers();

            serviceCollection.AddMassTransit(configurator =>
            {
                configurator.UsingRabbitMq((context, factoryConfigurator) =>
                {
                    factoryConfigurator.Host(rabbitMqSettings.Host, hostConfigurator =>
                    {
                        hostConfigurator.Username(rabbitMqSettings.Username);
                        hostConfigurator.Password(rabbitMqSettings.Password);
                        hostConfigurator.ConfigureBatchPublish(publishConfigurator =>
                        {
                            publishConfigurator.Enabled = true;
                            publishConfigurator.Timeout = TimeSpan.FromMilliseconds(50);
                        });
                    });

                    factoryConfigurator.MessageTopology.SetEntityNameFormatter(
                        new EventNamespaceNameFormatter(
                            factoryConfigurator.MessageTopology.EntityNameFormatter,
                            context.GetRequiredService <IEventNameProvider>()));

                    factoryConfigurator.SetMessageSerializer(context
                                                             .GetRequiredService <EventNamespaceMessageSerializer>);
                    factoryConfigurator.AddMessageDeserializer(JsonMessageSerializer.JsonContentType,
                                                               context.GetRequiredService <EventNamespaceMessageDeserializer>);

                    rabbitMqBusConfiguratorAction?.Invoke(factoryConfigurator, context);
                });

                configuratorAction?.Invoke(configurator);
            });
        }
 public static void RegisterRabbitMqPublisher(this IServiceCollection serviceCollection,
                                              PublisherRabbitMqSettings rabbitMqSettings)
 {
     RegisterRabbitMq(serviceCollection, rabbitMqSettings);
 }
 public EventsPublisherBuilder ToRabbitMq(PublisherRabbitMqSettings rabbitMqSettings)
 {
     _publisherRabbitMqSettings = rabbitMqSettings;
     return(this);
 }