提交 ad1038f9 编写于 作者: L lvxuhong

代码优化

上级 4a0c75b2
package github.javaguide;
import github.javaguide.api.Hello;
import github.javaguide.api.HelloService;
import lombok.extern.slf4j.Slf4j;
/**
......
package github.javaguide;
import github.javaguide.api.HelloService;
import github.javaguide.remoting.transport.netty.server.NettyServer;
/**
......@@ -8,6 +9,7 @@ import github.javaguide.remoting.transport.netty.server.NettyServer;
*/
public class NettyServerMain {
public static void main(String[] args) {
HelloService helloService = new HelloServiceImpl();
NettyServer nettyServer = new NettyServer("127.0.0.1", 9999);
nettyServer.publishService(helloService, HelloService.class);
......
package github.javaguide;
import github.javaguide.api.HelloService;
import github.javaguide.remoting.transport.socket.SocketRpcServer;
/**
......
package github.javaguide;
package github.javaguide.api;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import java.io.Serializable;
......
......@@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
public final class CuratorUtils {
private static final int BASE_SLEEP_TIME = 1000;
private static final int MAX_RETRIES = 5;
private static final String CONNECT_STRING = "127.0.0.1:2181";
private static final String CONNECT_STRING = "20.21.1.145:2181";
public static final String ZK_REGISTER_ROOT_PATH = "/my-rpc";
private static Map<String, List<String>> serviceAddressMap = new ConcurrentHashMap<>();
private static Set<String> registeredPathSet = ConcurrentHashMap.newKeySet();
......
......@@ -19,5 +19,6 @@ public class ZkServiceRegistry implements ServiceRegistry {
//根节点下注册子节点:服务
String servicePath = CuratorUtils.ZK_REGISTER_ROOT_PATH + "/" + serviceName + inetSocketAddress.toString();
CuratorUtils.createPersistentNode(servicePath);
}
}
......@@ -2,4 +2,4 @@
基于spring 5.2.6.RELEASE
- 通过一个注解就可以实现远程接口的调用
@RpcServiceScan("github.javaguide.spring.service")
\ No newline at end of file
@RpcServiceScan("github.javaguide.api")
\ No newline at end of file
......@@ -27,5 +27,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>github.javaguide</groupId>
<artifactId>hello-service-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -25,15 +25,7 @@ public class RpcServiceFactoryBean<T> implements FactoryBean<T> {
if (rpcServiceInterface == null) {
throw new IllegalStateException("");
}
return ClientProxy.getServiceProxy(rpcServiceInterface);
// return (T) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class[]{rpcServiceInterface}, new InvocationHandler() {
// @Override
// public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
// if(method.equals()){}
// return null;
// }
// });
}
@Override
......
package github.javaguide.spring;
import github.javaguide.api.Hello;
import github.javaguide.api.HelloService;
import github.javaguide.spring.annotation.RpcServiceScan;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
......@@ -19,12 +22,16 @@ public class ClientTest {
applicationContext.refresh();
applicationContext.start();
HelloService helloService = applicationContext.getBean(HelloService.class);
Hello hello = Hello.builder().message("test message").description("test description").build();
String res = helloService.hello(hello);
String expectedResult = "Hello description is " + hello.getDescription();
Assert.assertEquals(expectedResult, res);
}
@Configuration
@RpcServiceScan("github.javaguide.spring.service")
//@Configuration
@RpcServiceScan("github.javaguide.api")
public static class TestConfig {
}
......
package github.javaguide.spring.service;
public interface Service1 {
}
package github.javaguide.spring.service;
/**
* @description:
* @author:lvxuhong
* @date:2020/6/18
*/
public interface Service2 {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册