private RabbitConnectionInfos GetConnectionInfos() => RabbitConnectionInfos.FromConnectionFactory(new ConnectionFactory { HostName = "localhost", UserName = "******", Password = "******" }, "pub1");
/// <summary> /// Use RabbitMQ as Pub/Sub system. /// </summary> /// <param name="bootstrapper">Bootstrapper instance to configure</param> /// <returns>Configured bootstrapper instance</returns> public static Bootstrapper UseRabbitMQ( this Bootstrapper bootstrapper, RabbitConnectionInfos connectionInfos, RabbitNetworkInfos networkInfos, Action <RabbitSubscriberConfiguration> subscriberConfiguration = null, Action <RabbitPublisherConfiguration> publisherConfiguration = null) { var service = RabbitMQBootstrappService.Instance; var subscriberConf = new RabbitSubscriberConfiguration { ConnectionInfos = connectionInfos, NetworkInfos = networkInfos }; subscriberConfiguration?.Invoke(subscriberConf); service.BootstrappAction += (ctx) => { var publisherConf = new RabbitPublisherConfiguration() { ConnectionInfos = connectionInfos, NetworkInfos = networkInfos }; publisherConfiguration?.Invoke(publisherConf); bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(subscriberConf, typeof(RabbitSubscriberConfiguration))); bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(publisherConf, typeof(RabbitPublisherConfiguration))); bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(RabbitPublisher), true)); bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(RabbitSubscriber), true)); if (publisherConf.RoutingKeyFactory != null) { bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(publisherConf.RoutingKeyFactory, typeof(IRoutingKeyFactory))); } }; bootstrapper.AddService(service); bootstrapper.OnPostBootstrapping += (c) => { ILoggerFactory loggerFactory = null; IScopeFactory scopeFactory = null; if (c.Scope != null) { loggerFactory = c.Scope.Resolve <ILoggerFactory>(); scopeFactory = c.Scope.Resolve <IScopeFactory>(); } if (loggerFactory == null) { loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(new DebugLoggerProvider()); } RabbitMQBootstrappService.RabbitSubscriber = new RabbitSubscriber( loggerFactory, subscriberConf, scopeFactory); RabbitMQBootstrappService.RabbitSubscriber.Start(); }; return(bootstrapper); }
/// <summary> /// Creates a new instance of <see cref="RabbitSubscriberConfiguration"/>. /// </summary> /// <param name="connectionInfos">Connection infos to reach Rabbit instance/cluster</param> /// <param name="networkInfos">Network topology informations</param> public RabbitSubscriberConfiguration( RabbitConnectionInfos connectionInfos, RabbitNetworkInfos networkInfos) { ConnectionInfos = connectionInfos ?? throw new ArgumentNullException(nameof(connectionInfos)); NetworkInfos = networkInfos ?? throw new ArgumentNullException(nameof(networkInfos)); }
public static RabbitConnectionInfos GetConnectionInfos(string service) => RabbitConnectionInfos.FromConnectionFactory(new ConnectionFactory { HostName = "localhost", UserName = "******", Password = "******" }, service);
/// <summary> /// Creates a new Rabbit publishing configuration. /// </summary> /// <param name="connectionInfos">Connection infos to reach Rabbit instance/cluster</param> /// <param name="networkInfos">Network topology informations</param> /// <param name="eventsLifetime">Collection of event lifetime informations.</param> public RabbitPublisherConfiguration( RabbitConnectionInfos connectionInfos, RabbitNetworkInfos networkInfos, IEnumerable <EventLifeTimeConfiguration>?eventsLifetime = null) : base(eventsLifetime ?? Enumerable.Empty <EventLifeTimeConfiguration>()) { ConnectionInfos = connectionInfos ?? throw new System.ArgumentNullException(nameof(connectionInfos)); NetworkInfos = networkInfos ?? throw new System.ArgumentNullException(nameof(networkInfos)); }
private static RabbitConnectionInfos GetConnectionInfos() { return(RabbitConnectionInfos.FromConnectionFactory( new ConnectionFactory { HostName = "localhost", UserName = "******", Password = "******" }, "sub1" )); }