示例#1
0
        private HttpServer(IHttpServerConfiguration configuration)
        {
            _baseUri = configuration.BaseUri;

            _metricsCollector  = new HttpMetricsCollector();
            _diagnosticService = configuration.DiagnosticService;
            _diagnosticService.AddSink(_metricsCollector);

            _subscriptionTrackingService = configuration.SubscriptionTrackingService;
            _messageQueueingService      = configuration.MessageQueueingService;
            _messageJournal = configuration.MessageJournal;

            var transportServiceOptions = new HttpTransportServiceOptions(_baseUri, _messageQueueingService, _subscriptionTrackingService)
            {
                DiagnosticService = configuration.DiagnosticService,
                Endpoints         = configuration.Endpoints,
                MessageJournal    = configuration.MessageJournal,
                BypassTransportLocalDestination = configuration.BypassTransportLocalDestination
            };

            TransportService = new HttpTransportService(transportServiceOptions);

            _bus = new Bus(configuration, _baseUri, TransportService, _messageQueueingService);

            var authorizationService = configuration.AuthorizationService;

            _resourceRouter = new ResourceTypeDictionaryRouter(configuration.BaseUri)
            {
                { "message", new MessageController(TransportService.ReceiveMessage, authorizationService) },
                { "topic", new TopicController(_subscriptionTrackingService, configuration.Topics, authorizationService) },
                { "journal", new JournalController(configuration.MessageJournal, configuration.AuthorizationService) },
                { "metrics", new MetricsController(_metricsCollector) }
            };
            _httpListener = InitHttpListener(_baseUri, configuration.AuthenticationSchemes);

            var acceptBlockOptions = new ExecutionDataflowBlockOptions
            {
                CancellationToken = _cancellationTokenSource.Token
            };

            if (configuration.ConcurrencyLimit > 0)
            {
                acceptBlockOptions.MaxDegreeOfParallelism = configuration.ConcurrencyLimit;
            }

            _acceptBlock = new ActionBlock <HttpListenerContext>(async ctx => await Accept(ctx), acceptBlockOptions);
        }
示例#2
0
        /// <summary>
        /// Initializes a new <see cref="HttpTransportService"/>
        /// </summary>
        /// <param name="options">The HTTP transport service configuration</param>
        public HttpTransportService(HttpTransportServiceOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _baseUri   = options.BaseUri.WithTrailingSlash();
            _endpoints = options.Endpoints = options.Endpoints ?? EndpointCollection.Empty;

            _messageQueueingService          = options.MessageQueueingService;
            _messageJournal                  = options.MessageJournal;
            _subscriptionTrackingService     = options.SubscriptionTrackingService;
            _bypassTransportLocalDestination = options.BypassTransportLocalDestination;
            _diagnosticService               = options.DiagnosticService ?? DiagnosticService.DefaultInstance;
            _httpClientFactory               = options.HttpClientFactory ?? new BasicHttpClientFactory();
            _outboundQueueName               = "Outbound";
        }