In one of my stateless service I would like to include two listeners:
- Listener provided by Service Fabric for internal communication between services
- Listener based on OWIN Self-Host implemented according to examples (https://github.com/Azure/azure-content/blob/master/articles/service-fabric/service-fabric-reliable-services-communication-webapi.md)
When I try to register created listeners in standard manner I have a problem that listener based on OWIN is automaticaly closed after initialization:
Part responsible for registering services:
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new List<ServiceReplicaListener>
{
new ServiceReplicaListener(parameters => new OwinCommunicationListener("account",new Startup(), parameters)),
new ServiceReplicaListener(parameters => new ServiceRemotingListener<AccountService>(parameters, this))
};
}
ServiceManifest ports setup:
<Resources>
<Endpoints>
<Endpoint Name="ServiceEndpoint" />
<Endpoint Name="WebApiEndpoint" Type="Input" Protocol="http" Port="8083"/>
<Endpoint Name="ReplicatorEndpoint" />
</Endpoints>
</Resources>
OwinCommunicationListener:
public class OwinCommunicationListener: ICommunicationListener
{
private readonly IOwinAppBuilder startup;
private readonly string appRoot;
private IDisposable serverHandle;
private string listeningAddress;
private readonly ServiceInitializationParameters serviceInitializationParameters;
public OwinCommunicationListener(string appRoot, IOwinAppBuilder startup, ServiceInitializationParameters serviceInitializationParameters)
{
this.startup = startup;
this.appRoot = appRoot;
this.serviceInitializationParameters = serviceInitializationParameters;
}
public Task<string> OpenAsync(CancellationToken cancellationToken)
{
EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("WebApiEndpointB");
int port = serviceEndpoint.Port;
listeningAddress = string.Format(CultureInfo.InvariantCulture,"http://+:{0}/{1}",port,string.IsNullOrWhiteSpace(appRoot)? string.Empty: appRoot.TrimEnd('/') + '/');
serverHandle = WebApp.Start(listeningAddress, appBuilder => startup.Configuration(appBuilder));
string publishAddress = listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN);
ServiceEventSource.Current.Message("Listening on {0}", publishAddress);
return Task.FromResult(publishAddress);
}
...
}
How can I sove this problem and have these two listeners registered?