use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.
the class ServiceRegistryImpl method unregisterService.
@Override
public ServiceEndpoint unregisterService(String endpointId) {
ServiceEndpoint serviceEndpoint = serviceEndpoints.remove(endpointId);
if (serviceEndpoint != null) {
LOGGER.debug("ServiceEndpoint unregistered: {}", serviceEndpoint);
List<ServiceReference> serviceReferencesOfEndpoint = serviceReferencesByQualifier.values().stream().flatMap(Collection::stream).filter(sr -> sr.endpointId().equals(endpointId)).collect(Collectors.toList());
serviceReferencesOfEndpoint.forEach(sr -> {
computeServiceReferences(sr.qualifier(), sr);
computeServiceReferences(sr.oldQualifier(), sr);
});
}
return serviceEndpoint;
}
use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.
the class ScalecubeServiceDiscoveryTest method testMetadataCodec.
@ParameterizedTest
@MethodSource("metadataCodecSource")
public void testMetadataCodec(MetadataCodec metadataCodec) {
ServiceEndpoint serviceEndpoint = ServiceEndpoint.builder().id(UUID.randomUUID().toString()).tags(Collections.singletonMap("K", "V")).contentTypes(Collections.singleton("json")).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action0", Collections.singletonMap("KKK0", "VVV"), true))))).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action1", Collections.singletonMap("KKK1", "VVV"), true))))).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action2", Collections.singletonMap("KKK2", "VVV"), true))))).build();
ByteBuffer buffer = metadataCodec.serialize(serviceEndpoint);
ServiceEndpoint serviceEndpoint1 = (ServiceEndpoint) metadataCodec.deserialize(buffer);
Assertions.assertEquals(serviceEndpoint.id(), serviceEndpoint1.id());
Assertions.assertEquals(1, serviceEndpoint1.tags().size());
Assertions.assertEquals(1, serviceEndpoint1.contentTypes().size());
List<ServiceRegistration> serviceRegistrations = new ArrayList<>(serviceEndpoint1.serviceRegistrations());
Assertions.assertEquals(3, serviceRegistrations.size());
for (ServiceRegistration serviceRegistration : serviceRegistrations) {
Assertions.assertEquals(1, serviceRegistration.methods().size());
Assertions.assertEquals(1, serviceRegistration.tags().size());
}
}
use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.
the class CompositeProfileAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(call -> Collections.singletonList(ServiceInfo.fromServiceInstance(new SecuredServiceByCompositeProfileImpl()).authenticator(compositeAuthenticator()).build())).startAwait();
Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
ServiceMessage response = caller.call().requestOne(ServiceMessage.builder().qualifier("securedServiceByCompositeProfile/hello").header("userProfile.name", "SEGA").header("userProfile.role", "ADMIN").data("hello world").build(), String.class).block(Duration.ofSeconds(3));
System.err.println("### Received 'caller' response: " + response.data());
}
use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.
the class ServiceTransportAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(new SecuredServiceByUserProfileImpl()).startAwait();
Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String response = caller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'caller' response: " + response);
}
use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.
the class PrincipalMapperAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(ServiceInfo.fromServiceInstance(new SecuredServiceByApiKeyImpl()).principalMapper(PrincipalMapperAuthExample::apiKeyPrincipalMapper).build()).services(ServiceInfo.fromServiceInstance(new SecuredServiceByUserProfileImpl()).principalMapper(PrincipalMapperAuthExample::userProfilePrincipalMapper).build()).startAwait();
Microservices userProfileCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String responseByUserProfile = userProfileCaller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'userProfileCaller' response: " + responseByUserProfile);
Microservices apiKeyCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String responseByApiKey = apiKeyCaller.call().api(SecuredServiceByApiKey.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'apiKeyCaller' response: " + responseByApiKey);
}
Aggregations