Browse Source

add NodeId config to options.

master
Savorboard 7 years ago
parent
commit
90ee75c3f9
4 changed files with 8 additions and 4 deletions
  1. +2
    -0
      src/DotNetCore.CAP/NodeDiscovery/CAP.DiscoveryOptions.cs
  2. +4
    -2
      src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.Consul.cs
  3. +1
    -1
      src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.cs
  4. +1
    -1
      src/DotNetCore.CAP/NodeDiscovery/Node.cs

+ 2
- 0
src/DotNetCore.CAP/NodeDiscovery/CAP.DiscoveryOptions.cs View File

@@ -26,6 +26,8 @@


public string CurrentNodeHostName { get; set; } public string CurrentNodeHostName { get; set; }
public int CurrentNodePort { get; set; } public int CurrentNodePort { get; set; }

public int NodeId { get; set; }
public string NodeName { get; set; } public string NodeName { get; set; }
public string MatchPath { get; set; } public string MatchPath { get; set; }
} }


+ 4
- 2
src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.Consul.cs View File

@@ -4,11 +4,11 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Consul; using Consul;
using System.Security.Cryptography;
using System.Net;


namespace DotNetCore.CAP.NodeDiscovery namespace DotNetCore.CAP.NodeDiscovery
{ {
class ConsulNodeDiscoveryProvider : INodeDiscoveryProvider, IDisposable
public class ConsulNodeDiscoveryProvider : INodeDiscoveryProvider, IDisposable
{ {
private ConsulClient _consul; private ConsulClient _consul;
private readonly DiscoveryOptions _options; private readonly DiscoveryOptions _options;
@@ -34,6 +34,7 @@ namespace DotNetCore.CAP.NodeDiscovery


var nodes = services.Response.Select(x => new Node var nodes = services.Response.Select(x => new Node
{ {
Id = x.Key,
Name = x.Value.Service, Name = x.Value.Service,
Address = x.Value.Address, Address = x.Value.Address,
Port = x.Value.Port, Port = x.Value.Port,
@@ -47,6 +48,7 @@ namespace DotNetCore.CAP.NodeDiscovery
{ {
return _consul.Agent.ServiceRegister(new AgentServiceRegistration return _consul.Agent.ServiceRegister(new AgentServiceRegistration
{ {
ID = _options.NodeId.ToString(),
Name = _options.NodeName, Name = _options.NodeName,
Address = _options.CurrentNodeHostName, Address = _options.CurrentNodeHostName,
Port = _options.CurrentNodePort, Port = _options.CurrentNodePort,


+ 1
- 1
src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.cs View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;


namespace DotNetCore.CAP.NodeDiscovery namespace DotNetCore.CAP.NodeDiscovery
{ {
interface INodeDiscoveryProvider
public interface INodeDiscoveryProvider
{ {
Task<IList<Node>> GetNodes(); Task<IList<Node>> GetNodes();




+ 1
- 1
src/DotNetCore.CAP/NodeDiscovery/Node.cs View File

@@ -4,7 +4,7 @@ using System.Text;


namespace DotNetCore.CAP.NodeDiscovery namespace DotNetCore.CAP.NodeDiscovery
{ {
class Node
public class Node
{ {
public string Id { get; set; } public string Id { get; set; }




Loading…
Cancel
Save