@Test public void serviceRegistration() throws Exception { AstrixServiceRegistry serviceRegistry = clientContext.getBean(AstrixServiceRegistry.class); ServiceRegistryClient serviceRegistryClient = clientContext.getBean(ServiceRegistryClient.class); ServiceRegistryExporterClient exporterClient1 = new ServiceRegistryExporterClient(serviceRegistry, "default", "app-instance-1"); ServiceRegistryExporterClient exporterClient2 = new ServiceRegistryExporterClient(serviceRegistry, "default", "app-instance-2"); ServiceProperties server1Props = new ServiceProperties(); server1Props.getProperties().put("myProp", "1"); ServiceProperties server2 = new ServiceProperties(); server2.getProperties().put("myProp", "1"); exporterClient1.register(SomeService.class, server1Props, 10000); exporterClient2.register(SomeService.class, server2, 10000); exporterClient2.register(AnotherService.class, new ServiceProperties(), 10000); List<ServiceProperties> providers = serviceRegistryClient.list(AstrixBeanKey.create(SomeService.class)); assertEquals(2, providers.size()); server1Props = new ServiceProperties(); server1Props.getProperties().put("myProp", "3"); exporterClient1.register(SomeService.class, server1Props, 10000); providers = serviceRegistryClient.list(AstrixBeanKey.create(SomeService.class)); assertEquals(2, providers.size()); ServiceProperties serviceProperties = getPropertiesForAppInstance("app-instance-1", providers); assertEquals("3", serviceProperties.getProperty("myProp")); }
private ServiceProperties getPropertiesForAppInstance( String appInstanceId, List<ServiceProperties> providers) { for (ServiceProperties properties : providers) { if (appInstanceId.equals( properties.getProperties().get(ServiceProperties.APPLICATION_INSTANCE_ID))) { return properties; } } return null; }