use of io.scalecube.cluster.ClusterConfig in project scalecube by scalecube.
the class ServiceTest method test_services_contribute_to_cluster_metadata.
@Test
public void test_services_contribute_to_cluster_metadata() {
Map<String, String> metadata = new HashMap<>();
metadata.put("HOSTNAME", "host1");
Builder clusterConfig = ClusterConfig.builder().metadata(metadata);
Microservices ms = Microservices.builder().clusterConfig(clusterConfig).services(new GreetingServiceImpl()).build();
assertTrue(ms.cluster().member().metadata().containsKey("HOSTNAME"));
assertTrue(ServiceInfo.from(ms.cluster().member().metadata().entrySet().stream().filter(item -> item.getValue().equals("service")).findFirst().get().getKey()).getServiceName().equals("io.scalecube.services.GreetingService"));
}
use of io.scalecube.cluster.ClusterConfig in project scalecube by scalecube.
the class ClusterJoinExamples method main.
/**
* Main method.
*/
public static void main(String[] args) throws Exception {
// Start seed member Alice
Cluster alice = Cluster.joinAwait();
// Join Bob to cluster with Alice
Cluster bob = Cluster.joinAwait(alice.address());
// Join Carol to cluster with metadata
Map<String, String> metadata = ImmutableMap.of("name", "Carol");
Cluster carol = Cluster.joinAwait(metadata, alice.address());
// Start Dan on port 3000
ClusterConfig configWithFixedPort = ClusterConfig.builder().seedMembers(alice.address()).portAutoIncrement(false).port(3000).build();
Cluster dan = Cluster.joinAwait(configWithFixedPort);
// Start Eve in separate cluster (separate sync group)
ClusterConfig configWithSyncGroup = ClusterConfig.builder().seedMembers(alice.address(), bob.address(), carol.address(), // won't join anyway
dan.address()).syncGroup("another cluster").build();
Cluster eve = Cluster.joinAwait(configWithSyncGroup);
// Print cluster members of each node
System.out.println("Alice (" + alice.address() + ") cluster: " + alice.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
System.out.println("Bob (" + bob.address() + ") cluster: " + bob.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
System.out.println("Carol (" + carol.address() + ") cluster: " + carol.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
System.out.println("Dan (" + dan.address() + ") cluster: " + dan.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
System.out.println(// alone in cluster
"Eve (" + eve.address() + ") cluster: " + eve.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
}
Aggregations