dlouwers / reactive-consul

Consul client for Scala
MIT License
18 stars 7 forks source link

selectConnection gets called before addConnectionProvider in LoadBalancerActor #18

Open sjoerdmulder opened 7 years ago

sjoerdmulder commented 7 years ago

Having the example new ServiceBroker and immediately call withService then the selectConnection is called on the LoadBalancerActor before the connection providers are added causing an ServiceUnavailableException exception

Example:

val serviceBroker = ServiceBroker(new URL("http://consul.service.consul:8500"), connectionStrategies)
serviceBroker.withService[String, Unit]("my-service") { value => ... }
dlouwers commented 7 years ago

Hi @sjoerdmulder,

What do you feel would be reasonable behavior? I could either introduce the concept of 'readiness' to the ServiceBroker constructor, having it return a Future[ServiceBroker] or I could build some mechanism into withService that would await the first query of Consul along with the construction of connections. I feel that the latter option would probably be the most user-friendly, agreed?

sjoerdmulder commented 7 years ago

Yeah, last option is better since it's already returns a Future. Great project BTW! If you need any help or want a PR let me know.

dlouwers commented 6 years ago

Hi @sjoerdmulder. I am now stashing GetConnection messages until the first consul query has been done. This means that you might still not get a connection if Consul isn't aware of it ofc. Please try the 0.4.0 snapshot.

sjoerdmulder commented 6 years ago

Cool, i have not yet had time to test will do this hopefully within couple of weeks for you.

dlouwers commented 6 years ago

Hi @sjoerdmulder. I have given it some thought and have come to the conclusion that this feature has added far more complexity than it solves. In a next release, I will remove this feature in favor of advising people to use a retry mechanism from the outside.

sjoerdmulder commented 6 years ago

Ok, no problem. The problem is likely not happening in real code since the creation of ServiceBroker happens on startup and after some time when the service is ready / started it will start using the .withService