private QueueListener ConfigureQueueListener(ConfigurationContext context, string inboundQueueName,
                                                     string outboundQueueName)
        {
            var inboundQueue  = _messageQueueProvider.Open(inboundQueueName);
            var outboundQueue = inboundQueueName == outboundQueueName
                ? inboundQueue
                : _messageQueueProvider.Open(outboundQueueName);
            var scopeFactory = new ScopeWrapper(context.ServiceProvider);
            var router       = new MessageRouter
            {
                ReportAnalyzerQueue = outboundQueue,
                AppQueue            = _messageQueueProvider.Open("Messaging")
            };

            var listener = new QueueListener(inboundQueue, router, scopeFactory)
            {
                RetryAttempts = new[]
                { TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2) },
                MessageInvokerFactory = scope =>
                {
                    var invoker = new MessageInvoker(scope);
                    invoker.Logger          += (level, name, message) => _logger.Debug("[" + name + "] " + message);
                    invoker.InvokingHandler += (sender, args) =>
                    {
                        _logger.Debug(
                            $"Invoking {JsonConvert.SerializeObject(args.Message)} ({args.Handler.GetType()}).");
                    };
                    return(invoker);
                },
                Logger = DiagnosticLog
            };

            listener.PoisonMessageDetected += (sender, args) =>
            {
                Err.Report(args.Exception, new { args.Message.Body });
                _logger.Error(inboundQueueName + " Poison message: " + args.Message.Body, args.Exception);
            };
            listener.ScopeCreated += (sender, args) =>
            {
                args.Scope.ResolveDependency <IPrincipalAccessor>().First().Principal = args.Principal;

                _logger.Debug(inboundQueueName + " Running " + args.Message.Body + ", Credentials: " +
                              args.Principal.ToFriendlyString());
            };
            listener.ScopeClosing += (sender, args) =>
            {
                if (args.Exception != null)
                {
                    return;
                }

                var all = args.Scope.ResolveDependency <IAdoNetUnitOfWork>().ToList();
                all[0].SaveChanges();

                var queue = (DomainQueueWrapper)args.Scope.ResolveDependency <IDomainQueue>().First();
                queue.SaveChanges();
            };
            listener.MessageInvokerFactory = MessageInvokerFactory;
            return(listener);
        }
 public ReportController(IMessageQueueProvider queueProvider, IAdoNetUnitOfWork unitOfWork,
                         ConfigurationStore configStore)
 {
     _unitOfWork   = unitOfWork;
     _configStore  = configStore;
     _messageQueue = queueProvider.Open("Reports");
 }
 /// <summary>
 ///     Creates a new instance of <see cref="SaveReportHandler" />.
 /// </summary>
 /// <param name="queueProvider">provider</param>
 public SaveReportHandler(IMessageQueueProvider queueProvider)
 {
     if (queueProvider == null)
     {
         throw new ArgumentNullException("queueProvider");
     }
     _queue = queueProvider.Open("ReportQueue");
 }
 public ReportReceiverController(IMessageQueueProvider queueProvider, IAdoNetUnitOfWork unitOfWork,
                                 ConfigurationStore configStore, IWhitelistService whitelistService)
 {
     _unitOfWork       = unitOfWork;
     _configStore      = configStore;
     _whitelistService = whitelistService;
     _messageQueue     = queueProvider.Open("ErrorReports");
 }
 public ReportReceiverController(IMessageQueueProvider queueProvider, IAdoNetUnitOfWork unitOfWork,
                                 IConfiguration <ReportConfig> reportConfig, IWhitelistService whitelistService)
 {
     _unitOfWork       = unitOfWork;
     _reportConfig     = reportConfig.Value;
     _whitelistService = whitelistService;
     _messageQueue     = queueProvider.Open("ErrorReports");
 }
Пример #6
0
 /// <summary>
 ///     Creates a new instance of <see cref="SaveReportHandler" />.
 /// </summary>
 /// <param name="queueProvider">provider</param>
 /// <param name="connectionFactory">Tries to find connection named "Queue" and uses default if not found.</param>
 /// <exception cref="ArgumentNullException">queueProvider;connectionFactory</exception>
 public SaveReportHandler(IMessageQueueProvider queueProvider, IConnectionFactory connectionFactory)
 {
     if (queueProvider == null)
     {
         throw new ArgumentNullException(nameof(queueProvider));
     }
     _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
     _queue             = queueProvider.Open("ReportQueue");
 }
Пример #7
0
 public QueuedEventBus(IEventBus writeBus, IMessageQueueProvider queueProvider)
 {
     _queue    = queueProvider.Open("EventQueue");
     _writeBus = writeBus;
 }
 public FeedbackController(IMessageQueueProvider queueProvider, IApplicationRepository applicationRepository)
 {
     _applicationRepository = applicationRepository;
     _queue = queueProvider.Open("Feedback");
 }
 public FeedbackController(IMessageQueueProvider queueProvider, IConnectionFactory connectionFactory)
 {
     _connectionFactory = connectionFactory;
     _queue             = queueProvider.Open("FeedbackQueue");
 }
Пример #10
0
 public FeedbackReceiverController(IMessageQueueProvider queueProvider, IApplicationRepository applicationRepository)
 {
     _applicationRepository = applicationRepository;
     _queue = queueProvider.Open("ErrorReports");
 }
 public ScanForNewFeedback(ICommandBus cmdBus, IMessageQueueProvider queueProvider)
 {
     _cmdBus       = cmdBus;
     _messageQueue = queueProvider.Open("FeedbackQueue");
     Interval      = TimeSpan.FromSeconds(1);
 }
Пример #12
0
 /// <summary>
 ///     Creates a new instance of <see cref="ScanForNewErrorReports" />.
 /// </summary>
 /// <param name="analyzer">to analyze inbound reprots</param>
 /// <param name="queueProvider">To be able to read inbound reports</param>
 public ScanForNewErrorReports(Services.ReportAnalyzer analyzer,
                               IMessageQueueProvider queueProvider)
 {
     _analyzer = analyzer;
     _queue    = queueProvider.Open("ReportQueue");
 }
 public FeedbackController(IMessageQueueProvider queueProvider)
 {
     _queue = queueProvider.Open("FeedbackQueue");
 }