Search in sources :

Example 1 with ShenyuServerRegisterRepository

use of org.apache.shenyu.register.server.api.ShenyuServerRegisterRepository in project incubator-shenyu by apache.

the class RegisterCenterConfiguration method shenyuServerRegisterRepository.

/**
 * Shenyu server register repository server register repository.
 *
 * @param shenyuRegisterCenterConfig the shenyu register center config
 * @param shenyuClientRegisterService the shenyu client register service
 * @return the shenyu server register repository
 */
@Bean(destroyMethod = "close")
public ShenyuServerRegisterRepository shenyuServerRegisterRepository(final ShenyuRegisterCenterConfig shenyuRegisterCenterConfig, final List<ShenyuClientRegisterService> shenyuClientRegisterService) {
    String registerType = shenyuRegisterCenterConfig.getRegisterType();
    ShenyuServerRegisterRepository registerRepository = ExtensionLoader.getExtensionLoader(ShenyuServerRegisterRepository.class).getJoin(registerType);
    RegisterServerDisruptorPublisher publisher = RegisterServerDisruptorPublisher.getInstance();
    Map<String, ShenyuClientRegisterService> registerServiceMap = shenyuClientRegisterService.stream().collect(Collectors.toMap(ShenyuClientRegisterService::rpcType, e -> e));
    publisher.start(registerServiceMap);
    registerRepository.init(publisher, shenyuRegisterCenterConfig);
    return registerRepository;
}
Also used : Configuration(org.springframework.context.annotation.Configuration) ExtensionLoader(org.apache.shenyu.spi.ExtensionLoader) ShenyuRegisterCenterConfig(org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig) List(java.util.List) ShenyuClientRegisterService(org.apache.shenyu.admin.service.register.ShenyuClientRegisterService) RegisterServerDisruptorPublisher(org.apache.shenyu.admin.disruptor.RegisterServerDisruptorPublisher) Map(java.util.Map) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) ShenyuServerRegisterRepository(org.apache.shenyu.register.server.api.ShenyuServerRegisterRepository) Bean(org.springframework.context.annotation.Bean) Collectors(java.util.stream.Collectors) ShenyuServerRegisterRepository(org.apache.shenyu.register.server.api.ShenyuServerRegisterRepository) RegisterServerDisruptorPublisher(org.apache.shenyu.admin.disruptor.RegisterServerDisruptorPublisher) ShenyuClientRegisterService(org.apache.shenyu.admin.service.register.ShenyuClientRegisterService) Bean(org.springframework.context.annotation.Bean)

Example 2 with ShenyuServerRegisterRepository

use of org.apache.shenyu.register.server.api.ShenyuServerRegisterRepository in project incubator-shenyu by apache.

the class RegisterCenterConfigurationTest method testShenyuServerRegisterRepository.

@Test
public void testShenyuServerRegisterRepository() {
    ShenyuRegisterCenterConfig shenyuRegisterCenterConfig = mock(ShenyuRegisterCenterConfig.class);
    List<ShenyuClientRegisterService> shenyuClientRegisterService = new ArrayList<>();
    when(shenyuRegisterCenterConfig.getRegisterType()).thenReturn("http");
    ShenyuServerRegisterRepository registerRepository = registerCenterConfiguration.shenyuServerRegisterRepository(shenyuRegisterCenterConfig, shenyuClientRegisterService);
    assertNotNull(registerRepository);
}
Also used : ShenyuRegisterCenterConfig(org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig) ShenyuServerRegisterRepository(org.apache.shenyu.register.server.api.ShenyuServerRegisterRepository) ArrayList(java.util.ArrayList) ShenyuClientRegisterService(org.apache.shenyu.admin.service.register.ShenyuClientRegisterService) Test(org.junit.jupiter.api.Test)

Aggregations

ShenyuClientRegisterService (org.apache.shenyu.admin.service.register.ShenyuClientRegisterService)2 ShenyuRegisterCenterConfig (org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig)2 ShenyuServerRegisterRepository (org.apache.shenyu.register.server.api.ShenyuServerRegisterRepository)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 RegisterServerDisruptorPublisher (org.apache.shenyu.admin.disruptor.RegisterServerDisruptorPublisher)1 ExtensionLoader (org.apache.shenyu.spi.ExtensionLoader)1 Test (org.junit.jupiter.api.Test)1 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1