Closed zhou-hao closed 2 years ago
after microservices has started its already an immutable object. microservices are automatically registered and discovered within a node and they publish locally and remotely the services they host within a Microservices node in the network of microservices based on SWIM.
you can checkout the examples and the tests inside the project
https://github.com/scalecube/scalecube-services/tree/master/services-examples
the main idea is that any node can be a seed
one address that allows all services to join the cluster of services.
using gossip and SWIM discovery protocol once a member joined the cluster all other members automatically aware of it
it means that seed is only used for first handshake and act as a well known address to join the cluster
after this there is no need of seed until next member want to join.
so its not mandatory to join the cluster via seed in case somehow you know the address of the any node.
when a member joins a cluster he can just start or start pointing to some seed member.
final Address seedAddress = seed.discovery().address();
.membership(cfg -> cfg.seedMembers(seedAddress)))
// 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)
.startAwait();
final Address seedAddress = seed.discovery().address();
// Construct a ScaleCube node which joins the cluster hosting the Greeting Service
Microservices ms =
Microservices.builder()
.discovery(
"ms",
endpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(endpoint))
.membership(cfg -> cfg.seedMembers(seedAddress)))
.transport(RSocketServiceTransport::new)
.services(new GreetingServiceImpl())
.startAwait();
``
Sorry,Maybe you don't understand my scenes.
ServiceMethodRegistry registry = new ServiceMethodRegistryImpl();
Microservices ms =
Microservices.builder()
.discovery(
"ms",
endpoint ->
new ScalecubeServiceDiscovery()
.transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))
.options(opts -> opts.metadata(endpoint))
.membership(cfg -> cfg.seedMembers(seedAddress)))
.transport(RSocketServiceTransport::new)
.methodRegistry(registry)
.startAwait();
// register a service after Microservices started
registry.registerService(ServiceInfo
.fromServiceInstance(new GreetingServiceImpl())
....
.build())
ohh i see once microservices is started its immutable. so any change that is done to method registry will not take effect. this is because on start there is introspection of the microservices and registration of them to the cluster. so adding anything to the registry after start does not make any sense.
MembershipEvent
has UPDATED
Type, Is there a plan to support ServiceDiscoveryEvent.Type
?
scalecube is an open source project - anyone is welcome to fork/offer improvements. pull request are considered/accepted with a reasoning what is the motivation for the improvement.
ok thanks
发自我的iPhone
------------------ Original ------------------ From: Ronen @.> Date: Thu,Nov 18,2021 6:44 PM To: scalecube/scalecube-services @.> Cc: 老周 @.>, Author @.> Subject: Re: [scalecube/scalecube-services] How to dynamically register services (Issue #825)
scalecube is an open source project - anyone is welcome to fork/offer improvements. pull request are considered/accepted with a reasoning what is the motivation for the improvement.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Some scenes,I need dynamically register services after
Microservices
started.