Skip to content
This repository has been archived by the owner on Aug 19, 2018. It is now read-only.

add service registry events allowing to listen on service references #237

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

ronenhamias
Copy link
Owner

@ronenhamias ronenhamias commented Aug 6, 2018

add service registry events allowing to listen on service references changed

Motivation:

the idea is to be subscribed to specific service reference and not to service endpoint from discovery.
for example in service layer i want to know when a service is available to subscribe to it.

in such case i can subscribe in discovery and start filtering the relevant reference.
but in routing context i dont usually have access to discovery.

by listening on service registry i can subscribe to references and filter / handle service reference discovery.

@ronenhamias ronenhamias requested a review from a team August 6, 2018 05:51
@@ -22,6 +29,11 @@
private final Map<String, ServiceEndpoint> serviceEndpoints = new NonBlockingHashMap<>();
private final Map<String, List<ServiceReference>> referencesByQualifier = new NonBlockingHashMap<>();

private final FluxProcessor<RegistryEvent, RegistryEvent> events =
DirectProcessor.<RegistryEvent>create().serialize();
Copy link
Contributor

@segabriel segabriel Aug 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better .serialize() need to move to sink like:

FluxSink<RegistryEvent> sink = events.serialize().sink();

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason you think its better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can emit some events from different threads therefor we need that our sink will be with serialize(). And in another hand, to subscribe to events we don't need use redundant .serialize() and it's it is unnecessary for FluxProcessor<RegistryEvent, RegistryEvent> events

referencesByQualifier.values().forEach(list -> list.removeIf(sr -> sr.endpointId().equals(endpointId)));
referencesByQualifier.values()
.forEach(list -> {
list.stream().filter(sr -> sr.endpointId().equals(endpointId)).collect(Collectors.toSet())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove redundant creating a set .collect(Collectors.toSet())

@artem-v
Copy link
Contributor

artem-v commented Aug 16, 2018

What's the practical purpose? Uses cases?

@ronenhamias
Copy link
Owner Author

Motivation:

the idea is to be subscribed to specific service reference and not to service endpoint from discovery.
for example in service layer i want to know when a service is available to subscribe to it.

in such case i can subscribe in discovery and start filtering the relevant reference.
but in routing context i dont usually have access to discovery.

by listening on service registry i can subscribe to references and filter / handle service reference discovery.

@artem-v
Copy link
Contributor

artem-v commented Aug 17, 2018

Looks like this doubles functionality that we already have.
This is how:
the ServiceDiscovery already has Flux<DiscoveryEvent> listen() method, so we can listen add/remove and etc.; then in DiscoveryEvent there's a field serviceEndpoint which by turn has Collection<ServiceRegistration> serviceRegistrations field, where ServiceRegistration, by turn, has Collection<ServiceMethodDefinition> methods field.
So we are already all set to build ServiceReference object out of given ServiceEndpoint.

@ronenhamias
Copy link
Owner Author

its not same api where from discovery you get service endpoints and not service references

@dmytro-lazebnyi
Copy link
Contributor

dmytro-lazebnyi commented Aug 17, 2018

@ronenhamias
PR looks interesting, but I'm not sure that I completely understand purpose of this functionality.

the idea is to be subscribed to specific service reference and not to service endpoint from discovery.

What are benefits from knowledge that some particular service reference is added or removed?
I mean, imagine that we have 3 service nodes (references) related to some ExampleService.
What do we achieve if we get event with information that 4th service reference is added or some of this 3 is removed?

@ronenhamias
Copy link
Owner Author

ronenhamias commented Aug 17, 2018

@dmytro-lazebnyi
for example you are dependent on this service and you want to subscribe to all (or some) instances of this type once it appears at the cluster.

you need to manage the lifecycle of these services are beeing added removed:

lets imagine i want to subscribe to all quote services in the cluster as they appear for example

becouse new instrument are elastically appearing in the cluster

and i want to make sure i subscribe only once to specific reference.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants