Vac*_*ano 6 azure-service-fabric service-fabric-stateless
我正在尝试创建一个服务,它将为我的服务结构集群中运行的应用程序更新服务端点的外部列表.(基本上我需要在我的内部F5负载均衡器中复制Azure负载均衡器.)
在上个月的Service Fabric Q&A中,团队向我指出了RegisterServiceNotificationFilterAsync.
我使用此方法创建了无状态服务,并将其部署到我的开发集群.然后我通过运行ASP.NET Core Stateless服务模板创建了一个新服务.
我期望当我部署第二个服务时,断点将在我的第一个服务中出现,表示已添加服务.但是没有破坏点.
我在互联网上发现这种事情的例子很少,所以我在这里要求跳过其他人这样做,并告诉我哪里出错了.
以下是我的服务代码,它试图捕获应用程序更改:
protected override async Task RunAsync(CancellationToken cancellationToken)
{
var fabricClient = new FabricClient();
long? filterId = null;
try
{
var filterDescription = new ServiceNotificationFilterDescription
{
Name = new Uri("fabric:")
};
fabricClient.ServiceManager.ServiceNotificationFilterMatched += ServiceManager_ServiceNotificationFilterMatched;
filterId = await fabricClient.ServiceManager.RegisterServiceNotificationFilterAsync(filterDescription);
long iterations = 0;
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
ServiceEventSource.Current.ServiceMessage(this.Context, "Working-{0}", ++iterations);
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
}
}
finally
{
if (filterId != null)
await fabricClient.ServiceManager.UnregisterServiceNotificationFilterAsync(filterId.Value);
}
}
private void ServiceManager_ServiceNotificationFilterMatched(object sender, EventArgs e)
{
Debug.WriteLine("Change Occured");
}
Run Code Online (Sandbox Code Playgroud)
如果你有任何关于如何实现这一目标的提示,我很乐意看到它们.
您需要将MatchNamePrefix设置为 true,如下所示:
var filterDescription = new ServiceNotificationFilterDescription
{
Name = new Uri("fabric:"),
MatchNamePrefix = true
};
Run Code Online (Sandbox Code Playgroud)
否则它只会匹配特定的服务。在我的应用程序中,当此参数设置为 时,我可以捕获集群范围的事件true
。
归档时间: |
|
查看次数: |
381 次 |
最近记录: |