/// <summary>
        /// Dependency inject a message publisher to the service collection
        /// </summary>
        /// <param name="services">The service collection</param>
        /// <param name="connectionUri">The uri connection string</param>
        public static void AddMessagePublisher(this IServiceCollection services, string connectionUri)
        {
            var connection = new RabbitConnectionFactory(connectionUri);

            services.AddSingleton(connection);

            services.AddScoped <IMessageQueuePublisher, RabbitQueuePublisher>();
        }
 public RabbitQueueReader(
     IServiceProvider serviceProvider,
     RabbitConnectionFactory connection,
     QueueName queueName,
     MessageHandlerRepository messageHandlerRepository
     )
 {
     _serviceProvider          = serviceProvider;
     _connection               = connection;
     _queueName                = queueName;
     _messageHandlerRepository = messageHandlerRepository;
 }
        /// <summary>
        /// Dependency inject a message consumer to the service collection
        /// </summary>
        /// <param name="services">The service collection</param>
        /// <param name="connectionUri">The uri connection string</param>
        /// <param name="queueName">The name of the queue</param>
        /// <param name="builderFn">The message builder</param>
        public static void AddMessageConsumer(this IServiceCollection services, string connectionUri, string queueName, Action <MessagingBuilder> builderFn = null)
        {
            var builder = new MessagingBuilder(services);

            services.AddHostedService <RabbitQueueReader>();
            services.AddSingleton(new MessageHandlerRepository(builder.MessageHandlers));

            builderFn?.Invoke(builder);

            var queueNameService = new QueueName(queueName);

            services.AddSingleton(queueNameService);

            var connection = new RabbitConnectionFactory(connectionUri);

            services.AddSingleton(connection);
        }
Ejemplo n.º 4
0
 public RabbitQueuePublisher(RabbitConnectionFactory connection)
 {
     _connection = connection;
 }