First, the problem
Today, with Ocelot + Consul projects, micro-services practice, but Ocelot discovery services always fail.
Second, the solution
2.1 Solution:
Ocelot had to download the source code to track the investigation.
2.2 root of the problem:
We found, Ocelot's DownstreamPathTemplate eventually transformed into http: // hostname: port form / url's. Consul is a problem in the registration.
Problems when registering 2.3 Consul correction:
Note that while the hostname is specified by the parameters -node Consul's!
and so,
consul agent -server -datacenter=dc1 -bootstrap -data-dir ./data -ui -node=n1 -bind 192.168.11.211 -client=0.0.0.0
Wherein -node = n1 is a pit. It should be omitted, the system will set itself as its own host name hostname.
So I actually use the configuration file node1.json, also removed the item.
{ "datacenter": "dc1", "data_dir": "c:/data/app/consul/node1", "log_level": "INFO", "server": true, "ui": true, "bind_addr": "192.168.11.211", "client_addr": "127.0.0.1", "advertise_addr": "192.168.11.211", "bootstrap_expect": 1, "ports":{ "http": 8500, "dns": 8600, "server": 8300, "serf_lan": 8301, "serf_wan": 8302 } }
Then call the method:
consul agent -config-dir=e:/consul/node1.json
Then adding another server
consul agent -data-dir /tmp/consul -bind=192.168.11.246 -join 192.168.11.248
Then Consul's web management interface:
It will automatically bring the host name: HNSever and LGB-PC
After registration services, will eventually become http: // hostname: port + form / url template.
2.4 hostname can not modify the access problem
If then, or return an error code HTTP ERROR 500 access failure. Is the hostname can not be converted ipaddress.
So we need to modify windows hosts file :
Open system directory: c: / windows / system32 / drivers / etc to find the hosts file, open the hosts file and add a record in the final surface
, for example:
192.168.11.248 HNServer
192.168.11.211 LGB-PC
Then you can normally find the service!
Third, the reference
netcore ocelot api gateway services combined consul found
Under Windows host name and IP mapping settings