PlayFab/consuldotnet

Documentation

Closed this issue · 6 comments

Hello. Could you tell me where to find the documentation on consul in wcf and .net? Based on your example, I was able to register a service in consul using this package.

I'm not really sure what you're asking here. Could you please expand on what you mean by "consul in wcf and .net" or give me an example of what you'd like to do?

In my project, there are two services, thanks to your example, I managed to register services in consul, now I want my services to communicate through consul.

I'm really not sure what you mean by "communicate through consul". Are you attempting to use Consul as a data storage layer that both services watch? It's not a proxy either. I suggest you read about how the Consul API works at https://www.consul.io/api/index.html - it's very similar to how Consul.NET works.

I just want to connect to service "A" service "B", through the consul. (I'm talking about wcf)

Or you will have to use the config files of the service (app or web.config)

Consul can help you with the service discovery portion, yes. Check out the Health endpoint APIs, which also return healthy machines' catalog data (e.g. IP/port), and then you can connect via constructing a URI to talk to the service.

I'm not familiar with WCF, but if you're going by this stackoverflow post:
https://stackoverflow.com/questions/2943148/how-to-programmatically-connect-a-client-to-a-wcf-service#2943206

You would replace the line that reads var myEndpoint = new EndpointAddress("http://localhost/myservice");

with something like this:

using (var client = new ConsulClient())
{
    var nodes = await client.Health.Service("myservice", "", true);
    if (nodes.Response == null || nodes.Response.Length == 0) { throw new YourAppConnectionException("Could not discover myservice from Consul"); }
    var service = nodes.Response.First().Service;
    var myEndpoint = new EndpointAddress("http://"+service.Address+":"+service.Port+"/myservice");
}