vert-x3 / vertx-service-discovery

Some tools one can use for doing microservices with Vert.x
Apache License 2.0
115 stars 67 forks source link

service discovery `getRecord` most likely return the first matched record #91

Closed upwell closed 6 years ago

upwell commented 6 years ago

I found service discovery getRecord always return the first matched record while there were multiple service instance published with the same service name and type.

I check the source code below.

https://github.com/vert-x3/vertx-service-discovery/blob/2e117cb28a1b76b02c8d65c3a10ac7cd1f3468c8/vertx-service-discovery/src/main/java/io/vertx/servicediscovery/impl/DiscoveryImpl.java#L367-L387

At L378, the findAny() method most likely return the first one.

I wrote some test code. The findAny() method always returns the first element if in non-parallel pipline.

        System.out.println(IntStream.range(0, 100).findAny().getAsInt());
        System.out.println(IntStream.range(0, 100).findAny().getAsInt());
        System.out.println(IntStream.range(0, 100).findAny().getAsInt());
        System.out.println(IntStream.range(0, 100).findAny().getAsInt());

I googled and got some prove on stackoverflow about this behavior.

Please help check if this is by design or it's a bug.

tsegismont commented 6 years ago

I will answer your question on the user forum. Please do not cross post a question on GitHub.