Reputation: 188
I'm playing around with Microservices at the moment and I also just started using Angular. Now, I am wondering whether/how it is possible to access a service discovery (e.g. Consul) from within Angular? By accessing I mean:
Register angular app as service at registry (so that it knows host and port angular app is running on)
Send REST call to other registered service - in best case just using the name of the service.
To express this a bit more precisely: There was one use case, in which I developed two simple services using Spring Boot, I applied the steps from this Blog to access one service from the other using Consul. Thus, my REST call looks in the end like this:
restTemplate.getForObject(http://city-service/rest/city/capital', ...);
What I like about this is that I can abstract away from the host and the port information. Right now, I would like to do the same thing in Angular. Hence, instead of something like this:
this.http.get('http://localhost:8080/rest/city/capital')
I would like to have something similar to this:
this.http.get('http://city-service/rest/city/capital')
How can I access a service discovery such as Consul (it does not have to be Consul, other ones are fine too) in Angular? As I said, I just started getting to know Angular, so please excuse if this is a stupid question.
I know that some service discoveries (including Consul) provide a REST API to retrieve information about the registered services. However, then I would first need to send a REST request to this explicitly before I could send my actual wanted REST request. I would prefer if there would be another option. Any help is appreciated.
I posted a more general question concerning this before, but I now concretized the question here.
Upvotes: 1
Views: 3466
Reputation: 17803
Consul and other service discovery systems are not designed to be accessible from public web and your question isn't really related to Angular.
You can use a Consul aware load balancer such as https://github.com/fabiolb/fabio or https://traefik.io/ to have traffic routed to services which are registered in Consul according to HOST and/or PATH.
Upvotes: 1