Skip to content

Commit

Permalink
Merge pull request #324 from nacos-group/dev
Browse files Browse the repository at this point in the history
Minor update for 1.3.9
  • Loading branch information
catcherwong authored Sep 25, 2024
2 parents 0b0dc17 + 86ba5d8 commit 85b9a43
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions samples/App3/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
o.RefreshPeriod = TimeSpan.FromSeconds(60);
})
.AddConfigurationServiceEndpointProvider()
.AddNacosSrvServiceEndpointProvider();
.AddNacosServiceEndpointProvider();

builder.Services.ConfigureHttpClientDefaults(static http =>
{
http.AddServiceDiscovery();
});

// 使用IHttpClientFactory
// use IHttpClientFactory
builder.Services.AddHttpClient("app1", cfg =>
{
cfg.BaseAddress = new Uri("http://app1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ namespace Microsoft.Extensions.Hosting;

public static class NacosServiceDiscoveryExtensions
{
public static IServiceCollection AddNacosSrvServiceEndpointProvider(this IServiceCollection services)
/// <summary>
/// Configures a service discovery endpoint provider which uses <see cref="T:Nacos.V2.INacosNamingService" /> to resolve endpoints.
/// </summary>
/// <param name="services">The service collection.</param>
/// <returns>The service collection.</returns>
public static IServiceCollection AddNacosServiceEndpointProvider(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

Expand Down
2 changes: 1 addition & 1 deletion src/Nacos.Microsoft.Extensions.ServiceDiscovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ builder.Services.AddServiceDiscovery(o =>
o.RefreshPeriod = TimeSpan.FromSeconds(60);
})
.AddConfigurationServiceEndpointProvider()
.AddNacosSrvServiceEndpointProvider();
.AddNacosServiceEndpointProvider();
```

## Links
Expand Down
12 changes: 10 additions & 2 deletions src/Nacos/V2/Naming/Remote/Grpc/Redo/NamingGrpcRedoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void InstanceDeregister(string serviceName, string groupName)
if (_registeredInstances.TryGetValue(key, out var data))
{
data.Unregistering = true;
data.ExpectedRegistered = false;
}
}

Expand All @@ -125,7 +126,10 @@ public void RemoveInstanceForRedo(string serviceName, string groupName)
{
string key = NamingUtils.GetGroupedName(serviceName, groupName);

_registeredInstances.TryRemove(key, out _);
if (_registeredInstances.TryGetValue(key, out var data) && data != null && !data.ExpectedRegistered)
{
_registeredInstances.TryRemove(key, out _);
}
}

/// <summary>
Expand Down Expand Up @@ -190,6 +194,7 @@ public void SubscriberDeregister(string serviceName, string groupName, string cl
if (_subscribes.TryGetValue(key, out var data))
{
data.Unregistering = true;
data.ExpectedRegistered = false;
}
}

Expand All @@ -203,7 +208,10 @@ public void RemoveSubscriberForRedo(string serviceName, string groupName, string
{
string key = ServiceInfo.GetKey(NamingUtils.GetGroupedName(serviceName, groupName), cluster);

_subscribes.TryRemove(key, out _);
if (_subscribes.TryGetValue(key, out var data) && data != null && !data.ExpectedRegistered)
{
_subscribes.TryRemove(key, out _);
}
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Nacos/V2/Naming/Remote/Grpc/Redo/RedoData{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ protected RedoData(string serviceName, string groupName)
{
this.ServiceName = serviceName;
this.GroupName = groupName;
this.ExpectedRegistered = true;
}

public string ServiceName { get; private set; }

public string GroupName { get; private set; }

public bool ExpectedRegistered { get; set; }

public T Data { get; set; }

public bool Registered { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/Nacos/V2/Naming/Remote/Grpc/Redo/RedoScheduledTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private async Task RedoForInstance(InstanceRedoData redoData)
case RedoType.REGISTER:
if (IsClientDisabled()) return;

if (redoData is BatchInstanceRedoData batchInstanceRedoData)
{
await _clientProxy.BatchRegisterServiceAsync(serviceName, groupName, batchInstanceRedoData.Instances).ConfigureAwait(false);
}

await _clientProxy.DoRegisterService(serviceName, groupName, redoData.Data).ConfigureAwait(false);
break;
case RedoType.UNREGISTER:
Expand Down

0 comments on commit 85b9a43

Please sign in to comment.