Exemple #1
0
        public InboundConsumer(IBroker broker,
                               IEndpoint endpoint,
                               InboundConnectorSettings settings,
                               Func <IEnumerable <IInboundMessage>, IServiceProvider, Task> messagesHandler,
                               Func <IServiceProvider, Task> commitHandler,
                               Func <IServiceProvider, Task> rollbackHandler,
                               IErrorPolicy errorPolicy,
                               IServiceProvider serviceProvider)
        {
            if (broker == null)
            {
                throw new ArgumentNullException(nameof(broker));
            }

            _endpoint    = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
            _settings    = settings ?? throw new ArgumentNullException(nameof(settings));
            _errorPolicy = errorPolicy;

            _messagesHandler = messagesHandler ?? throw new ArgumentNullException(nameof(messagesHandler));
            _commitHandler   = commitHandler ?? throw new ArgumentNullException(nameof(commitHandler));
            _rollbackHandler = rollbackHandler ?? throw new ArgumentNullException(nameof(rollbackHandler));

            _serviceProvider   = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            _logger            = serviceProvider.GetRequiredService <ILogger <InboundConsumer> >();
            _errorPolicyHelper = serviceProvider.GetRequiredService <ErrorPolicyHelper>();

            _consumer = broker.GetConsumer(_endpoint);

            Bind();
        }
        public InboundConsumer(IBroker broker,
                               IEndpoint endpoint,
                               InboundConnectorSettings settings,
                               Action <IEnumerable <IInboundMessage>, IServiceProvider> messagesHandler,
                               Action <IServiceProvider> commitHandler,
                               Action <IServiceProvider> rollbackHandler,
                               IErrorPolicy errorPolicy,
                               IServiceProvider serviceProvider)
        {
            _endpoint    = endpoint;
            _settings    = settings;
            _errorPolicy = errorPolicy;

            _messagesHandler = messagesHandler;
            _commitHandler   = commitHandler;
            _rollbackHandler = rollbackHandler;

            _serviceProvider         = serviceProvider;
            _logger                  = serviceProvider.GetRequiredService <ILogger <InboundConsumer> >();
            _messageLogger           = serviceProvider.GetRequiredService <MessageLogger>();
            _inboundMessageProcessor = serviceProvider.GetRequiredService <InboundMessageProcessor>();

            _consumer = broker.GetConsumer(_endpoint);

            Bind();
        }
Exemple #3
0
        public virtual IInboundConnector Bind(IEndpoint endpoint, IErrorPolicy errorPolicy = null, InboundConnectorSettings settings = null)
        {
            settings = settings ?? new InboundConnectorSettings();

            for (int i = 0; i < settings.Consumers; i++)
            {
                _inboundConsumers.Add(new InboundConsumer(
                                          _broker,
                                          endpoint,
                                          settings,
                                          HandleMessages,
                                          Commit,
                                          Rollback,
                                          errorPolicy,
                                          _serviceProvider));
            }

            // TODO: Carefully test with multiple endpoints!
            // TODO: Test if consumer gets properly disposed etc.
            return(this);
        }