in src/Microsoft.Azure.WebJobs.Extensions.Dapr/Services/DaprServiceListener.cs [67:102]
public async Task EnsureStartedAsync(CancellationToken cancellationToken)
{
if (Interlocked.CompareExchange(ref this.serverStarted, 1, 0) == 0)
{
this.host = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(s => s.AddRouting())
.UseUrls(this.appAddress)
.Configure(app =>
{
var routes = new RouteBuilder(app);
foreach (DaprListenerBase listener in this.listeners)
{
// CONSIDER: Each listener should return a route object (or a collection)
// instead of having direct access to the builder. This will
// improve encapsulation and enable better logging.
listener.AddRoute(routes);
}
// See https://docs.dapr.io/reference/api/pubsub_api/#provide-a-route-for-dapr-to-discover-topic-subscriptions
routes.MapGet("dapr/subscribe", this.GetTopicsAsync);
app.UseRouter(routes.Build());
})
.Build();
this.logger.LogInformation($"Starting Dapr HTTP listener on {this.appAddress} with {this.listeners.Count} function listener(s) registered.");
await this.host.StartAsync(cancellationToken);
this.logger.LogInformation("Dapr HTTP host started successfully.");
if (this.shouldCheckSidecarMetadataOnHostStartup)
{
await this.WarnIfSidecarMisconfigured();
}
}
}