Commit 90ee75c3 authored by Savorboard's avatar Savorboard

add NodeId config to options.

parent 1d9a1763
...@@ -26,6 +26,8 @@ ...@@ -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,11 +4,11 @@ using System.Collections.Generic; ...@@ -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 ...@@ -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 ...@@ -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,
......
...@@ -5,7 +5,7 @@ using System.Threading.Tasks; ...@@ -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();
......
...@@ -4,7 +4,7 @@ using System.Text; ...@@ -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; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment