Skip to content

Commit

Permalink
add enabled registry by ipman
Browse files Browse the repository at this point in the history
  • Loading branch information
ipipman committed Apr 21, 2024
1 parent 1c77d35 commit 63765e9
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.ipman.rpc.core.config.ConsumerConfig;
import cn.ipman.rpc.core.config.ProviderConfig;
import cn.ipman.rpc.core.config.RegistryCenterConfig;
import org.springframework.context.annotation.Import;

import java.lang.annotation.*;
Expand All @@ -10,6 +11,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Import({ProviderConfig.class, ConsumerConfig.class})
@Import({ProviderConfig.class, ConsumerConfig.class, RegistryCenterConfig.class})
@SuppressWarnings("unused")
public @interface EnableRpcMan {
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public Router<InstanceMeta> loadRouter() {
return new GrayRouter(consumerConfigProperties.getGrayRatio());
}

/**
* 创建注册中心实例,默认为ZkRegistryCenter。
* @return RegistryCenter 注册中心实例
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnMissingBean
public RegistryCenter consumerRc() {
return new ZkRegistryCenter();
}
// /**
// * 创建注册中心实例,默认为ZkRegistryCenter。
// * @return RegistryCenter 注册中心实例
// */
// @Bean(initMethod = "start", destroyMethod = "stop")
// @ConditionalOnMissingBean
// public RegistryCenter consumerRc() {
// return new ZkRegistryCenter();
// }


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ public ApplicationRunner providerBootstrapRunner(@Autowired ProviderBootstrap pr
};
}

/**
* 创建注册中心Bean,如果容器中不存在则创建一个新的ZkRegistryCenter实例。
*
* @return RegistryCenter 注册中心实例。
*/
@Bean
@ConditionalOnMissingBean
public RegistryCenter consumer_rc() {
return new ZkRegistryCenter();
}
// /**
// * 创建注册中心实例,默认为ZkRegistryCenter。
// * @return RegistryCenter 注册中心实例
// */
// @Bean(initMethod = "start", destroyMethod = "stop")
// @ConditionalOnMissingBean
// public RegistryCenter providerRc() {
// return new ZkRegistryCenter();
// }

/**
* 创建Netty服务器Bean,用于提供HTTP服务。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cn.ipman.rpc.core.config;

import cn.ipman.rpc.core.api.RegistryCenter;
import cn.ipman.rpc.core.registry.ipman.IpManRegistryCenter;
import cn.ipman.rpc.core.registry.zk.ZkRegistryCenter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Description for this class
*
* @Author IpMan
* @Date 2024/4/21 20:39
*/
@Configuration
public class RegistryCenterConfig {

/**
* 创建注册中心实例,默认为ZkRegistryCenter。
* @return RegistryCenter 注册中心实例
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "rpcman.zk", value = "enabled", havingValue = "true")
public RegistryCenter zkRc() {
return new ZkRegistryCenter();
}


@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnProperty(prefix = "registry-ipman", value = "enabled", havingValue = "true")
public RegistryCenter ipManRc() {
return new IpManRegistryCenter();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private String unRegPath(ServiceMeta service) {
}

private String findAllPath(ServiceMeta service) {
return server + "/findAll?service=" + service.toPath();
return server + "/findall?service=" + service.toPath();
}

private String versionPath(ServiceMeta service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.ipman.rpc.core.annotation.RpcConsumer;
import cn.ipman.rpc.core.api.RpcContext;
import cn.ipman.rpc.core.config.ConsumerConfig;
import cn.ipman.rpc.core.config.RegistryCenterConfig;
import cn.ipman.rpc.demo.api.OrderService;
import cn.ipman.rpc.demo.api.User;
import cn.ipman.rpc.demo.api.UserService;
Expand All @@ -21,7 +22,7 @@
import java.util.Map;

@SpringBootApplication
@Import({ConsumerConfig.class})
@Import({ConsumerConfig.class, RegistryCenterConfig.class})
@RestController
public class RpcmanDemoConsumerApplication {

Expand Down
1 change: 1 addition & 0 deletions rpcman-demo-consumer/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ server:
rpcman:
#providers: http://localhost:8080,http://localhost:8081,http://localhost:8082
zk:
enabled: false
zkServer: localhost:2181
zkRoot: rpcman

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ server:
rpcman:
#providers: http://localhost:8080,http://localhost:8081,http://localhost:8082
zk:
enabled: true
zkServer: localhost:2183
zkRoot: rpcman

Expand Down Expand Up @@ -38,7 +39,7 @@ apollo:

# 作者手写的注册中心:https://github.com/ipipman/registry-man
registry-ipman:
enabled: true
enabled: false
servers: http://localhost:8484

logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.ipman.rpc.core.api.RpcResponse;
import cn.ipman.rpc.core.config.ProviderConfig;
import cn.ipman.rpc.core.config.ProviderConfigProperties;
import cn.ipman.rpc.core.config.RegistryCenterConfig;
import cn.ipman.rpc.core.transport.SpringBootTransport;
import cn.ipman.rpc.demo.api.User;
import cn.ipman.rpc.demo.api.UserService;
Expand All @@ -26,7 +27,7 @@

@SpringBootApplication
@RestController
@Import({ProviderConfig.class})
@Import({ProviderConfig.class, RegistryCenterConfig.class})
@EnableApolloConfig
@Slf4j
public class RpcmanDemoProviderApplication {
Expand Down
1 change: 1 addition & 0 deletions rpcman-demo-provider/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ server:

rpcman:
zk:
enabled: false
zkServer: localhost:2181
zkRoot: rpcman

Expand Down
3 changes: 2 additions & 1 deletion rpcman-demo-provider/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ server:

rpcman:
zk:
enabled: true
zkServer: localhost:2182
zkRoot: rpcman

Expand Down Expand Up @@ -36,7 +37,7 @@ apollo:

# 作者手写的注册中心:https://github.com/ipipman/registry-man
registry-ipman:
enabled: true
enabled: false
servers: http://localhost:8484

logging:
Expand Down

0 comments on commit 63765e9

Please sign in to comment.