Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
嗝屁小孩纸
guide-rpc-framework
提交
1e936a02
G
guide-rpc-framework
项目概览
嗝屁小孩纸
/
guide-rpc-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
guide-rpc-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1e936a02
编写于
8月 11, 2020
作者:
G
guide
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[docs]update readme
上级
4c4b38fa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
44 deletion
+18
-44
README-EN.md
README-EN.md
+5
-5
README.md
README.md
+9
-11
example-client/src/main/java/github/javaguide/NettyClientMain2.java
...ient/src/main/java/github/javaguide/NettyClientMain2.java
+0
-27
rpc-framework-common/src/main/java/github/javaguide/factory/SingletonFactory.java
.../main/java/github/javaguide/factory/SingletonFactory.java
+4
-1
未找到文件。
README-EN.md
浏览文件 @
1e936a02
...
...
@@ -142,13 +142,13 @@ Publish services (transport using Netty) :
* @author shuang.kou
* @createTime 2020年05月10日 07:25:00
*/
@
ComponentScan
(
"github.javaguide"
)
@
RpcScan
(
basePackage
=
{
"github.javaguide.serviceimpl"
}
)
public
class
NettyServerMain
{
public
static
void
main
(
String
[]
args
)
{
// Register service via annotation
(通过注解注册服务 HelloServiceImpl )
AnnotationConfigApplicationContext
applicationContext
=
new
AnnotationConfigApplicationContext
(
NettyServerMain
.
class
);
NettyServer
nettyServer
=
applicationContext
.
getBean
(
NettyServer
.
class
);
// Register service manually
(手动注册服务 HelloServiceImpl2)
// Register service via annotation
new
AnnotationConfigApplicationContext
(
NettyServerMain
.
class
);
NettyServer
nettyServer
=
new
NettyServer
(
);
// Register service manually
HelloService
helloService2
=
new
HelloServiceImpl2
();
RpcServiceProperties
rpcServiceProperties
=
RpcServiceProperties
.
builder
()
.
group
(
"test2"
).
version
(
"version2"
).
build
();
...
...
README.md
浏览文件 @
1e936a02
...
...
@@ -71,7 +71,7 @@
-
[x]
**处理一个接口有多个类实现的情况**
:对服务分组,发布服务的时候增加一个 group 参数即可。
-
[x]
**集成 Spring 通过注解注册服务**
-
[x]
**增加服务版本号**
:建议使用两位数字版本,如:1.0,通常在接口不兼容时版本号才需要升级。为什么要增加服务版本号?为后续不兼容升级提供可能,比如服务接口增加方法,或服务模型增加字段,可向后兼容,删除方法或删除字段,将不兼容,枚举类型新增字段也不兼容,需通过变更版本号升级。
-
[
]
**对 SPI 机制的运用**
-
[
x
]
**对 SPI 机制的运用**
-
[ ]
**增加可配置比如序列化方式、注册中心的实现方式,避免硬编码**
:通过 API 配置,后续集成 Spring 的话建议使用配置文件的方式进行配置
-
[ ]
**使用注解进行服务消费**
-
[ ]
**客户端与服务端通信协议(数据包结构)重新设计**
,可以将原有的
`RpcRequest`
和
`RpcReuqest`
对象作为消息体,然后增加如下字段(可以参考:《Netty 入门实战小册》和 Dubbo 框架对这块的设计):
...
...
@@ -181,20 +181,18 @@ public class HelloServiceImpl2 implements HelloService {
* @author shuang.kou
* @createTime 2020年05月10日 07:25:00
*/
@
ComponentScan
(
"github.javaguide"
)
@
RpcScan
(
basePackage
=
{
"github.javaguide.serviceimpl"
}
)
public
class
NettyServerMain
{
public
static
void
main
(
String
[]
args
)
{
// Register service via annotation(通过注解注册服务 HelloServiceImpl )
AnnotationConfigApplicationContext
applicationContext
=
new
AnnotationConfigApplicationContext
(
NettyServerMain
.
class
);
NettyServer
nettyServer
=
applicationContext
.
getBean
(
NettyServer
.
class
);
nettyServer
.
start
();
// Register service manually(手动注册服务 HelloServiceImpl2)
// Register service via annotation
new
AnnotationConfigApplicationContext
(
NettyServerMain
.
class
);
NettyServer
nettyServer
=
new
NettyServer
();
// Register service manually
HelloService
helloService2
=
new
HelloServiceImpl2
();
ServiceProvider
serviceProvider
=
new
ServiceProviderImpl
();
RpcServiceProperties
rpcServiceProperties
=
RpcServiceProperties
.
builder
()
.
group
(
"test2"
).
version
(
"
test
2"
).
build
();
serviceProvider
.
publish
Service
(
helloService2
,
rpcServiceProperties
);
.
group
(
"test2"
).
version
(
"
version
2"
).
build
();
nettyServer
.
register
Service
(
helloService2
,
rpcServiceProperties
);
nettyServer
.
start
();
}
}
```
...
...
example-client/src/main/java/github/javaguide/NettyClientMain2.java
已删除
100644 → 0
浏览文件 @
4c4b38fa
package
github.javaguide
;
import
github.javaguide.entity.RpcServiceProperties
;
import
github.javaguide.proxy.RpcClientProxy
;
import
github.javaguide.remoting.transport.ClientTransport
;
import
github.javaguide.remoting.transport.netty.client.NettyClientTransport
;
/**
* @author shuang.kou
* @createTime 2020年05月10日 07:25:00
*/
public
class
NettyClientMain2
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
ClientTransport
rpcClient
=
new
NettyClientTransport
();
RpcServiceProperties
rpcServiceProperties
=
RpcServiceProperties
.
builder
()
.
group
(
"test2"
).
version
(
"version2"
).
build
();
RpcClientProxy
rpcClientProxy
=
new
RpcClientProxy
(
rpcClient
,
rpcServiceProperties
);
HelloService
helloService
=
rpcClientProxy
.
getProxy
(
HelloService
.
class
);
String
hello
=
helloService
.
hello
(
new
Hello
(
"111"
,
"222"
));
//如需使用 assert 断言,需要在 VM options 添加参数:-ea
assert
"Hello description is 222"
.
equals
(
hello
);
Thread
.
sleep
(
12000
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
helloService
.
hello
(
new
Hello
(
"111"
,
"222"
));
}
}
}
rpc-framework-common/src/main/java/github/javaguide/factory/SingletonFactory.java
浏览文件 @
1e936a02
package
github.javaguide.factory
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -21,10 +22,12 @@ public final class SingletonFactory {
synchronized
(
c
)
{
if
(
instance
==
null
)
{
try
{
instance
=
c
.
newInstance
();
instance
=
c
.
getDeclaredConstructor
().
newInstance
();
OBJECT_MAP
.
put
(
key
,
instance
);
}
catch
(
IllegalAccessException
|
InstantiationException
e
)
{
throw
new
RuntimeException
(
e
.
getMessage
(),
e
);
}
catch
(
NoSuchMethodException
|
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录