Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified service discovery and refactoring of registry events #342

Merged
merged 8 commits into from
Sep 18, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public void beforeAll() {
node =
Microservices.builder()
.metrics(registry())
.seeds(seed.discovery().address())
.seeds(seed.address())
.services(services)
.startAwait();

LOGGER.info(
"Seed address: "
+ seed.discovery().address()
+ seed.address()
+ ", services address: "
+ node.serviceAddress()
+ ", seed serviceRegistry: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void main(String[] args) throws Exception {
System.out.println("Start HelloWorldService with BusinessLogicFacade");
final Microservices node1 =
Microservices.builder()
.seeds(gateway.discovery().address())
.seeds(gateway.address())
.services(
call ->
Collections.singletonList(
Expand All @@ -57,14 +57,14 @@ public static void main(String[] args) throws Exception {
System.out.println("Start ServiceHello");
final Microservices node2 =
Microservices.builder()
.seeds(gateway.discovery().address())
.seeds(gateway.address())
.services(new ServiceHelloImpl())
.startAwait();

System.out.println("Start ServiceWorld");
final Microservices node3 =
Microservices.builder()
.seeds(gateway.discovery().address())
.seeds(gateway.address())
.services(new ServiceWorldImpl())
.startAwait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String[] args) {
// Construct a ScaleCube node which joins the cluster hosting the Greeting Service
Microservices microservices =
Microservices.builder()
.seeds(seed.discovery().address())
.seeds(seed.address())
.services(new GreetingServiceImpl())
.startAwait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void main(String[] args) {
// Construct a ScaleCube node which joins the cluster hosting the Greeting Service
Microservices microservices =
Microservices.builder()
.seeds(seed.discovery().address())
.seeds(seed.address())
.services(new GreetingServiceImpl())
.startAwait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void main(String[] args) throws InterruptedException {

Microservices ms =
Microservices.builder()
.seeds(gateway.discovery().address())
.seeds(gateway.address())
.services(new DefaultMarketDataService())
.startAwait();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.scalecube.services.ServiceLoaderUtil;
import io.scalecube.transport.Address;
import java.util.ServiceLoader;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public interface ServiceDiscovery {
Expand All @@ -26,6 +25,4 @@ static ServiceDiscovery getDiscovery() {
Mono<ServiceDiscovery> start(DiscoveryConfig discoveryConfig);

Mono<Void> shutdown();

Flux<DiscoveryEvent> listen();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.scalecube.services.registry.api;

import io.scalecube.services.ServiceEndpoint;
import io.scalecube.transport.Address;

public class EndpointRegistryEvent {

private ServiceEndpoint serviceEndpoint;
private RegistryEventType type;

public static EndpointRegistryEvent createAdded(ServiceEndpoint serviceEndpoint) {
return new EndpointRegistryEvent(RegistryEventType.ADDED, serviceEndpoint);
}

public static EndpointRegistryEvent createRemoved(ServiceEndpoint serviceEndpoint) {
return new EndpointRegistryEvent(RegistryEventType.REMOVED, serviceEndpoint);
}

private EndpointRegistryEvent(RegistryEventType type, ServiceEndpoint serviceEndpoint) {
this.serviceEndpoint = serviceEndpoint;
this.type = type;
}

private EndpointRegistryEvent(EndpointRegistryEvent e) {
this.serviceEndpoint = e.serviceEndpoint;
this.type = e.type;
}

public ServiceEndpoint serviceEndpoint() {
return this.serviceEndpoint;
}

public boolean isAdded() {
return RegistryEventType.ADDED.equals(type);
}

public boolean isRemoved() {
return RegistryEventType.REMOVED.equals(type);
}

public RegistryEventType type() {
return this.type;
}

public Address address() {
return Address.create(this.serviceEndpoint.host(), this.serviceEndpoint.port());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.scalecube.services.registry.api;

import io.scalecube.services.ServiceReference;
import io.scalecube.transport.Address;

public class ReferenceRegistryEvent {

private ServiceReference serviceReference;
private RegistryEventType type;

public static ReferenceRegistryEvent createAdded(ServiceReference serviceReference) {
return new ReferenceRegistryEvent(RegistryEventType.ADDED, serviceReference);
}

public static ReferenceRegistryEvent createRemoved(ServiceReference serviceReference) {
return new ReferenceRegistryEvent(RegistryEventType.REMOVED, serviceReference);
}

private ReferenceRegistryEvent(RegistryEventType type, ServiceReference serviceReference) {
this.serviceReference = serviceReference;
this.type = type;
}

private ReferenceRegistryEvent(ReferenceRegistryEvent e) {
this.serviceReference = e.serviceReference;
this.type = e.type;
}

public ServiceReference serviceReference() {
return this.serviceReference;
}

public boolean isAdded() {
return RegistryEventType.ADDED.equals(type);
}

public boolean isRemoved() {
return RegistryEventType.REMOVED.equals(type);
}

public RegistryEventType type() {
return this.type;
}

public Address address() {
return Address.create(this.serviceReference.host(), this.serviceReference.port());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.scalecube.services.registry.api;

public enum RegistryEventType {
ADDED,
REMOVED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public interface ServiceRegistry {

ServiceEndpoint unregisterService(String endpointId);

Flux<RegistryEvent> listen();
Flux<ReferenceRegistryEvent> listenReferenceEvents();
Copy link
Member

Choose a reason for hiding this comment

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

i dont like this contract its bloated to have this kind in the interface

maybe we can provide more clean interface?

Copy link
Member

Choose a reason for hiding this comment

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

something like:

listen(RegistryEvent::reference)

listen(RegistryEvent::endpoint)


Flux<EndpointRegistryEvent> listenEndpointEvents();
Copy link
Member

Choose a reason for hiding this comment

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

same as above


Mono<Void> close();
}
Loading