Skip to content

Commit

Permalink
Done with build (WIP on tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Oct 5, 2024
1 parent 503fd1c commit a33d688
Show file tree
Hide file tree
Showing 39 changed files with 1,010 additions and 1,066 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.scalecube.services.auth.Authenticator.deferSecured;

import io.scalecube.services.Microservices;
import io.scalecube.services.Microservices.Context;
import io.scalecube.services.ServiceEndpoint;
import io.scalecube.services.ServiceInfo;
import io.scalecube.services.api.ServiceMessage;
Expand All @@ -25,27 +26,29 @@ public class CompositeProfileAuthExample {
*/
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.start(
new Context()
.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())));

Microservices caller =
Microservices.builder()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier()))
.startAwait();
Microservices.start(
new Context()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() ->
new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())));

ServiceMessage response =
caller
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.scalecube.services.examples.auth;

import io.scalecube.services.Microservices;
import io.scalecube.services.Microservices.Context;
import io.scalecube.services.ServiceEndpoint;
import io.scalecube.services.ServiceInfo;
import io.scalecube.services.auth.Authenticator;
Expand All @@ -24,29 +25,30 @@ public class PrincipalMapperAuthExample {
*/
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.start(
new Context()
.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()));

Microservices userProfileCaller =
Microservices.builder()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier()))
.startAwait();
Microservices.start(
new Context()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() ->
new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())));

String responseByUserProfile =
userProfileCaller
Expand All @@ -58,11 +60,12 @@ public static void main(String[] args) {
System.err.println("### Received 'userProfileCaller' response: " + responseByUserProfile);

Microservices apiKeyCaller =
Microservices.builder()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier()))
.startAwait();
Microservices.start(
new Context()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() ->
new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())));

String responseByApiKey =
apiKeyCaller
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.scalecube.services.examples.auth;

import io.scalecube.services.Microservices;
import io.scalecube.services.Microservices.Context;
import io.scalecube.services.ServiceEndpoint;
import io.scalecube.services.auth.Authenticator;
import io.scalecube.services.discovery.ScalecubeServiceDiscovery;
Expand All @@ -22,22 +23,23 @@ public class ServiceTransportAuthExample {
*/
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.start(
new Context()
.discovery(
serviceEndpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(serviceEndpoint)))
.transport(() -> new RSocketServiceTransport().authenticator(authenticator()))
.services(new SecuredServiceByUserProfileImpl()));

Microservices caller =
Microservices.builder()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier()))
.startAwait();
Microservices.start(
new Context()
.discovery(endpoint -> discovery(service, endpoint))
.transport(
() ->
new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())));

String response =
caller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.scalecube.services.Address;
import io.scalecube.services.Microservices;
import io.scalecube.services.Microservices.Context;
import io.scalecube.services.discovery.ScalecubeServiceDiscovery;
import io.scalecube.services.examples.helloworld.service.GreetingServiceImpl;
import io.scalecube.services.examples.helloworld.service.api.GreetingsService;
Expand All @@ -22,30 +23,31 @@ public class Example1 {
public static void main(String[] args) {
// ScaleCube Node with no members
Microservices seed =
Microservices.builder()
.discovery(
serviceEndpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(serviceEndpoint)))
.transport(RSocketServiceTransport::new)
.defaultContentType(PROTOSTUFF) // set explicit default data format
.startAwait();
Microservices.start(
new Context()
.discovery(
serviceEndpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(serviceEndpoint)))
.transport(RSocketServiceTransport::new)
// .defaultContentType(PROTOSTUFF) // set explicit default data format
);

final Address seedAddress = seed.discoveryAddress();

// Construct a ScaleCube node which joins the cluster hosting the Greeting Service
Microservices ms =
Microservices.builder()
.discovery(
endpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(endpoint))
.membership(cfg -> cfg.seedMembers(seedAddress.toString())))
.transport(RSocketServiceTransport::new)
.services(new GreetingServiceImpl())
.startAwait();
Microservices.start(
new Context()
.discovery(
endpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(endpoint))
.membership(cfg -> cfg.seedMembers(seedAddress.toString())))
.transport(RSocketServiceTransport::new)
.services(new GreetingServiceImpl()));

seed.call()
.api(GreetingsService.class)
Expand All @@ -64,7 +66,7 @@ public static void main(String[] args) {
.sayHello("bob (on java native Serializable/Externalizable dataFormat)")
.subscribe(consumer -> System.out.println(consumer.message()));

seed.onShutdown().block();
ms.onShutdown().block();
seed.close();
ms.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.scalecube.services.Address;
import io.scalecube.services.Microservices;
import io.scalecube.services.Microservices.Context;
import io.scalecube.services.ServiceInfo;
import io.scalecube.services.discovery.ScalecubeServiceDiscovery;
import io.scalecube.services.transport.rsocket.RSocketServiceTransport;
Expand All @@ -18,45 +19,48 @@ public class ExceptionMapperExample {
*/
public static void main(String[] args) throws InterruptedException {
Microservices ms1 =
Microservices.builder()
.discovery(
serviceEndpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(serviceEndpoint)))
.transport(RSocketServiceTransport::new)
.defaultErrorMapper(new ServiceAProviderErrorMapper()) // default mapper for whole node
.services(
ServiceInfo.fromServiceInstance(new ServiceAImpl())
.errorMapper(new ServiceAProviderErrorMapper()) // mapper per service instance
.build())
.startAwait();
Microservices.start(
new Context()
.discovery(
serviceEndpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(serviceEndpoint)))
.transport(RSocketServiceTransport::new)
.defaultErrorMapper(
new ServiceAProviderErrorMapper()) // default mapper for whole node
.services(
ServiceInfo.fromServiceInstance(new ServiceAImpl())
.errorMapper(
new ServiceAProviderErrorMapper()) // mapper per service instance
.build()));

System.err.println("ms1 started: " + ms1.serviceAddress());

final Address address1 = ms1.discoveryAddress();

Microservices ms2 =
Microservices.builder()
.discovery(
endpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(endpoint))
.membership(cfg -> cfg.seedMembers(address1.toString())))
.transport(RSocketServiceTransport::new)
.services(
call -> {
ServiceA serviceA =
call.errorMapper(
new ServiceAClientErrorMapper()) // service client error mapper
.api(ServiceA.class);
Microservices.start(
new Context()
.discovery(
endpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(endpoint))
.membership(cfg -> cfg.seedMembers(address1.toString())))
.transport(RSocketServiceTransport::new)
.services(
call -> {
ServiceA serviceA =
call.errorMapper(
new ServiceAClientErrorMapper()) // service client error mapper
.api(ServiceA.class);

ServiceB serviceB = new ServiceBImpl(serviceA);
ServiceB serviceB = new ServiceBImpl(serviceA);

return Collections.singleton(ServiceInfo.fromServiceInstance(serviceB).build());
})
.startAwait();
return Collections.singleton(
ServiceInfo.fromServiceInstance(serviceB).build());
}));

System.err.println("ms2 started: " + ms2.serviceAddress());

Expand Down

This file was deleted.

Loading

0 comments on commit a33d688

Please sign in to comment.