Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
5e13875d
Commit
5e13875d
authored
Nov 15, 2019
by
liyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
74f3a090
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
115 additions
and
60 deletions
+115
-60
RegistryBaseClient.java
...ain/java/com/byit/registry/client/RegistryBaseClient.java
+1
-1
RegistryServiceImpl.java
...byit/registry/admin/service/impl/RegistryServiceImpl.java
+3
-3
application.properties
...register-server/src/main/resources/application.properties
+1
-0
echarts.common.min.js
...in/resources/static/plugins/echarts/echarts.common.min.js
+0
-0
ServiceRegistry.java
.../src/main/java/com/byit/rpc/registry/ServiceRegistry.java
+4
-4
LocalServiceRegistry.java
...java/com/byit/rpc/registry/impl/LocalServiceRegistry.java
+12
-11
RegistryServiceRegistry.java
...a/com/byit/rpc/registry/impl/RegistryServiceRegistry.java
+6
-4
ZkServiceRegistry.java
...in/java/com/byit/rpc/registry/impl/ZkServiceRegistry.java
+22
-8
RpcReferenceBean.java
...byit/rpc/remoting/invoker/reference/RpcReferenceBean.java
+3
-3
LoadBalance.java
...java/com/byit/rpc/remoting/invoker/route/LoadBalance.java
+3
-6
MinaClientHandler.java
.../rpc/remoting/net/impl/mina/client/MinaClientHandler.java
+1
-1
MinaServerHandler.java
.../rpc/remoting/net/impl/mina/server/MinaServerHandler.java
+1
-1
NettyServerHandler.java
...pc/remoting/net/impl/netty/server/NettyServerHandler.java
+1
-1
NettyHttpServerHandler.java
...ng/net/impl/netty_http/server/NettyHttpServerHandler.java
+1
-1
RpcProviderFactory.java
...va/com/byit/rpc/remoting/provider/RpcProviderFactory.java
+0
-0
RpcService.java
...com/byit/rpc/remoting/provider/annotation/RpcService.java
+7
-2
RpcSpringProviderFactory.java
.../rpc/remoting/provider/impl/RpcSpringProviderFactory.java
+28
-14
application-dev.properties
...emo-service/src/main/resources/application-dev.properties
+7
-0
application-pre.properties
...emo-service/src/main/resources/application-pre.properties
+7
-0
application-test.properties
...mo-service/src/main/resources/application-test.properties
+7
-0
No files found.
byit-myth-register/myth-register-client/src/main/java/com/byit/registry/client/RegistryBaseClient.java
View file @
5e13875d
...
@@ -181,7 +181,7 @@ public class RegistryBaseClient {
...
@@ -181,7 +181,7 @@ public class RegistryBaseClient {
registryParamVO
.
setAccessToken
(
this
.
accessToken
);
registryParamVO
.
setAccessToken
(
this
.
accessToken
);
registryParamVO
.
setBiz
(
this
.
biz
);
registryParamVO
.
setBiz
(
this
.
biz
);
registryParamVO
.
setEnv
(
this
.
env
);
registryParamVO
.
setEnv
(
this
.
env
);
registryParamVO
.
setKeys
(
new
ArrayList
<
String
>(
keys
));
registryParamVO
.
setKeys
(
new
ArrayList
<>(
keys
));
String
paramsJson
=
BasicJson
.
toJson
(
registryParamVO
);
String
paramsJson
=
BasicJson
.
toJson
(
registryParamVO
);
...
...
byit-myth-register/myth-register-server/src/main/java/com/byit/registry/admin/service/impl/RegistryServiceImpl.java
View file @
5e13875d
...
@@ -259,14 +259,14 @@ public class RegistryServiceImpl implements IRegistryService, InitializingBean,
...
@@ -259,14 +259,14 @@ public class RegistryServiceImpl implements IRegistryService, InitializingBean,
}
}
}
}
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
<
String
,
List
<
String
>>(
);
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
<
>(
16
);
for
(
String
key:
keys
)
{
for
(
String
key:
keys
)
{
RegistryData
registryData
=
new
RegistryData
();
RegistryData
registryData
=
new
RegistryData
();
registryData
.
setBiz
(
biz
);
registryData
.
setBiz
(
biz
);
registryData
.
setEnv
(
env
);
registryData
.
setEnv
(
env
);
registryData
.
setKey
(
key
);
registryData
.
setKey
(
key
);
List
<
String
>
dataList
=
new
ArrayList
<
String
>();
List
<
String
>
dataList
=
new
ArrayList
<>();
Registry
fileRegistry
=
getFileRegistryData
(
registryData
);
Registry
fileRegistry
=
getFileRegistryData
(
registryData
);
if
(
fileRegistry
!=
null
)
{
if
(
fileRegistry
!=
null
)
{
dataList
=
fileRegistry
.
getDataList
();
dataList
=
fileRegistry
.
getDataList
();
...
@@ -482,7 +482,7 @@ public class RegistryServiceImpl implements IRegistryService, InitializingBean,
...
@@ -482,7 +482,7 @@ public class RegistryServiceImpl implements IRegistryService, InitializingBean,
public
void
run
()
{
public
void
run
()
{
while
(!
executorStoped
)
{
while
(!
executorStoped
)
{
try
{
try
{
// new message, filter readed
// new message, filter
s
readed
List
<
RegistryMessage
>
messageList
=
registryMessageDao
.
findMessage
(
readedMessageIds
);
List
<
RegistryMessage
>
messageList
=
registryMessageDao
.
findMessage
(
readedMessageIds
);
if
(
messageList
!=
null
&&
messageList
.
size
()>
0
)
{
if
(
messageList
!=
null
&&
messageList
.
size
()>
0
)
{
for
(
RegistryMessage
message:
messageList
)
{
for
(
RegistryMessage
message:
messageList
)
{
...
...
byit-myth-register/myth-register-server/src/main/resources/application.properties
View file @
5e13875d
### web
### web
server.port
=
8080
server.port
=
8080
server.context-path
=
/myth-register
server.context-path
=
/myth-register
logging.config
=
classpath:logback.xml
### resources
### resources
spring.mvc.static-path-pattern
=
/static/**
spring.mvc.static-path-pattern
=
/static/**
...
...
byit-myth-register/myth-register-server/src/main/resources/static/plugins/echarts/echarts.common.min.js
View file @
5e13875d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
byit-myth-rpc/src/main/java/com/byit/rpc/registry/ServiceRegistry.java
View file @
5e13875d
...
@@ -30,11 +30,11 @@ public abstract class ServiceRegistry {
...
@@ -30,11 +30,11 @@ public abstract class ServiceRegistry {
/**
/**
* registry service, for mult
* registry service, for mult
*
*
* @param keys service key
* @param keyServerAddress Map's key is service key Map'svalue is service value/ip:port
* @param value service value/ip:port
* @return
*/
*/
public
abstract
boolean
registry
(
Set
<
String
>
keys
,
String
value
);
public
abstract
boolean
registry
(
Map
<
String
,
String
>
keyServerAddress
);
/**
/**
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/registry/impl/LocalServiceRegistry.java
View file @
5e13875d
package
com
.
byit
.
rpc
.
registry
.
impl
;
package
com
.
byit
.
rpc
.
registry
.
impl
;
import
com.byit.registry.client.model.RegistryDataParamVO
;
import
com.byit.rpc.registry.ServiceRegistry
;
import
com.byit.rpc.registry.ServiceRegistry
;
import
org.springframework.util.CollectionUtils
;
import
java.util.HashMap
;
import
java.util.*
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeSet
;
/**
/**
* service registry for "local"
* service registry for "local"
...
@@ -33,20 +32,22 @@ public class LocalServiceRegistry extends ServiceRegistry {
...
@@ -33,20 +32,22 @@ public class LocalServiceRegistry extends ServiceRegistry {
registryData
.
clear
();
registryData
.
clear
();
}
}
@Override
@Override
public
boolean
registry
(
Set
<
String
>
keys
,
String
value
)
{
public
boolean
registry
(
Map
<
String
,
String
>
keyServerAddress
)
{
if
(
keys
==
null
||
keys
.
size
()==
0
||
value
==
null
||
value
.
trim
().
length
()==
0
)
{
if
(
CollectionUtils
.
isEmpty
(
keyServerAddress
)
)
{
return
false
;
return
false
;
}
}
for
(
String
key
:
keys
)
{
TreeSet
<
String
>
values
=
registryData
.
get
(
key
);
// init
for
(
Map
.
Entry
<
String
,
String
>
entry
:
keyServerAddress
.
entrySet
())
{
TreeSet
<
String
>
values
=
registryData
.
get
(
entry
.
getKey
());
if
(
values
==
null
)
{
if
(
values
==
null
)
{
values
=
new
TreeSet
<>();
values
=
new
TreeSet
<>();
registryData
.
put
(
key
,
values
);
registryData
.
put
(
entry
.
getKey
()
,
values
);
}
}
values
.
add
(
value
);
values
.
add
(
entry
.
getValue
()
);
}
}
return
true
;
return
true
;
}
}
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/registry/impl/RegistryServiceRegistry.java
View file @
5e13875d
...
@@ -3,6 +3,7 @@ package com.byit.rpc.registry.impl;
...
@@ -3,6 +3,7 @@ package com.byit.rpc.registry.impl;
import
com.byit.registry.client.RegistryClient
;
import
com.byit.registry.client.RegistryClient
;
import
com.byit.registry.client.model.RegistryDataParamVO
;
import
com.byit.registry.client.model.RegistryDataParamVO
;
import
com.byit.rpc.registry.ServiceRegistry
;
import
com.byit.rpc.registry.ServiceRegistry
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
import
java.util.*
;
...
@@ -43,16 +44,17 @@ public class RegistryServiceRegistry extends ServiceRegistry {
...
@@ -43,16 +44,17 @@ public class RegistryServiceRegistry extends ServiceRegistry {
}
}
}
}
@Override
@Override
public
boolean
registry
(
Set
<
String
>
keys
,
String
value
)
{
public
boolean
registry
(
Map
<
String
,
String
>
keyServerAddress
)
{
if
(
keys
==
null
||
keys
.
size
()
==
0
||
value
==
null
)
{
if
(
CollectionUtils
.
isEmpty
(
keyServerAddress
)
)
{
return
false
;
return
false
;
}
}
// init
// init
List
<
RegistryDataParamVO
>
registryDataList
=
new
ArrayList
<>();
List
<
RegistryDataParamVO
>
registryDataList
=
new
ArrayList
<>();
for
(
String
key:
keys
)
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
keyServerAddress
.
entrySet
()
)
{
registryDataList
.
add
(
new
RegistryDataParamVO
(
key
,
value
));
registryDataList
.
add
(
new
RegistryDataParamVO
(
entry
.
getKey
(),
entry
.
getValue
()
));
}
}
return
registryClient
.
registry
(
registryDataList
);
return
registryClient
.
registry
(
registryDataList
);
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/registry/impl/ZkServiceRegistry.java
View file @
5e13875d
package
com
.
byit
.
rpc
.
registry
.
impl
;
package
com
.
byit
.
rpc
.
registry
.
impl
;
import
com.byit.registry.client.model.RegistryDataParamVO
;
import
com.byit.rpc.registry.ServiceRegistry
;
import
com.byit.rpc.registry.ServiceRegistry
;
import
com.byit.rpc.util.RpcException
;
import
com.byit.rpc.util.RpcException
;
import
com.byit.rpc.util.ZkClient
;
import
com.byit.rpc.util.ZkClient
;
...
@@ -7,6 +8,7 @@ import org.apache.zookeeper.WatchedEvent;
...
@@ -7,6 +8,7 @@ import org.apache.zookeeper.WatchedEvent;
import
org.apache.zookeeper.Watcher
;
import
org.apache.zookeeper.Watcher
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -232,25 +234,37 @@ public class ZkServiceRegistry extends ServiceRegistry {
...
@@ -232,25 +234,37 @@ public class ZkServiceRegistry extends ServiceRegistry {
}
}
}
}
@Override
@Override
public
boolean
registry
(
Set
<
String
>
keys
,
String
value
)
{
public
boolean
registry
(
Map
<
String
,
String
>
keyServerAddress
){
for
(
String
key
:
keys
)
{
if
(
CollectionUtils
.
isEmpty
(
keyServerAddress
))
{
return
false
;
}
StringBuilder
keys
=
new
StringBuilder
();
StringBuilder
addressValues
=
new
StringBuilder
();
// init
for
(
Map
.
Entry
<
String
,
String
>
entry
:
keyServerAddress
.
entrySet
())
{
// local cache
// local cache
TreeSet
<
String
>
values
=
registryData
.
get
(
key
);
TreeSet
<
String
>
values
=
registryData
.
get
(
entry
.
getKey
()
);
if
(
values
==
null
)
{
if
(
values
==
null
)
{
values
=
new
TreeSet
<>();
values
=
new
TreeSet
<>();
registryData
.
put
(
key
,
values
);
registryData
.
put
(
entry
.
getKey
()
,
values
);
}
}
values
.
add
(
value
);
values
.
add
(
entry
.
getValue
()
);
// make path, child path
// make path, child path
String
path
=
keyToPath
(
key
);
String
path
=
keyToPath
(
entry
.
getKey
());
zkClient
.
setChildPathData
(
path
,
value
,
""
);
keys
.
append
(
entry
.
getKey
()
+
","
);
addressValues
.
append
(
entry
.
getValue
()
+
","
);
zkClient
.
setChildPathData
(
path
,
entry
.
getValue
(),
""
);
}
}
logger
.
info
(
">>>>>>>>>>> myth-rpc, registry success, keys = {}, value = {}"
,
keys
,
value
);
logger
.
info
(
">>>>>>>>>>> myth-rpc, registry success, keys = {}, value = {}"
,
keys
,
addressValues
);
return
true
;
return
true
;
}
}
@Override
@Override
public
boolean
remove
(
Set
<
String
>
keys
,
String
value
)
{
public
boolean
remove
(
Set
<
String
>
keys
,
String
value
)
{
for
(
String
key
:
keys
)
{
for
(
String
key
:
keys
)
{
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/invoker/reference/RpcReferenceBean.java
View file @
5e13875d
...
@@ -147,7 +147,7 @@ public class RpcReferenceBean {
...
@@ -147,7 +147,7 @@ public class RpcReferenceBean {
Class
<?>[]
parameterTypes
=
method
.
getParameterTypes
();
Class
<?>[]
parameterTypes
=
method
.
getParameterTypes
();
Object
[]
parameters
=
args
;
Object
[]
parameters
=
args
;
// filter for generic
// filter
s
for generic
if
(
className
.
equals
(
RpcGenericService
.
class
.
getName
())
&&
methodName
.
equals
(
"invoke"
))
{
if
(
className
.
equals
(
RpcGenericService
.
class
.
getName
())
&&
methodName
.
equals
(
"invoke"
))
{
Class
<?>[]
paramTypes
=
null
;
Class
<?>[]
paramTypes
=
null
;
...
@@ -168,7 +168,7 @@ public class RpcReferenceBean {
...
@@ -168,7 +168,7 @@ public class RpcReferenceBean {
parameters
=
(
Object
[])
args
[
4
];
parameters
=
(
Object
[])
args
[
4
];
}
}
// filter method like "Object.toString()"
// filter
s
method like "Object.toString()"
if
(
className
.
equals
(
Object
.
class
.
getName
()))
{
if
(
className
.
equals
(
Object
.
class
.
getName
()))
{
logger
.
info
(
">>>>>>>>>>> myth-rpc proxy class-method not support [{}#{}]"
,
className
,
methodName
);
logger
.
info
(
">>>>>>>>>>> myth-rpc proxy class-method not support [{}#{}]"
,
className
,
methodName
);
throw
new
RpcException
(
"myth-rpc proxy class-method not support"
);
throw
new
RpcException
(
"myth-rpc proxy class-method not support"
);
...
@@ -187,7 +187,7 @@ public class RpcReferenceBean {
...
@@ -187,7 +187,7 @@ public class RpcReferenceBean {
}
else
if
(
addressSet
.
size
()==
1
)
{
}
else
if
(
addressSet
.
size
()==
1
)
{
finalAddress
=
addressSet
.
first
();
finalAddress
=
addressSet
.
first
();
}
else
{
}
else
{
finalAddress
=
loadBalance
.
xxlR
pcInvokerRouter
.
route
(
serviceKey
,
addressSet
);
finalAddress
=
loadBalance
.
r
pcInvokerRouter
.
route
(
serviceKey
,
addressSet
);
}
}
}
}
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/invoker/route/LoadBalance.java
View file @
5e13875d
...
@@ -11,10 +11,10 @@ public enum LoadBalance {
...
@@ -11,10 +11,10 @@ public enum LoadBalance {
CONSISTENT_HASH
(
new
RpcLoadBalanceConsistentHashStrategy
());
CONSISTENT_HASH
(
new
RpcLoadBalanceConsistentHashStrategy
());
public
final
RpcLoadBalance
xxlR
pcInvokerRouter
;
public
final
RpcLoadBalance
r
pcInvokerRouter
;
private
LoadBalance
(
RpcLoadBalance
xxlR
pcInvokerRouter
)
{
private
LoadBalance
(
RpcLoadBalance
r
pcInvokerRouter
)
{
this
.
xxlRpcInvokerRouter
=
xxlR
pcInvokerRouter
;
this
.
rpcInvokerRouter
=
r
pcInvokerRouter
;
}
}
...
@@ -26,6 +26,4 @@ public enum LoadBalance {
...
@@ -26,6 +26,4 @@ public enum LoadBalance {
}
}
return
defaultRouter
;
return
defaultRouter
;
}
}
}
}
\ No newline at end of file
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/net/impl/mina/client/MinaClientHandler.java
View file @
5e13875d
...
@@ -26,7 +26,7 @@ public class MinaClientHandler extends IoHandlerAdapter {
...
@@ -26,7 +26,7 @@ public class MinaClientHandler extends IoHandlerAdapter {
public
void
messageReceived
(
IoSession
session
,
Object
message
)
throws
Exception
{
public
void
messageReceived
(
IoSession
session
,
Object
message
)
throws
Exception
{
RpcResponse
xxlRpcResponse
=
(
RpcResponse
)
message
;
RpcResponse
xxlRpcResponse
=
(
RpcResponse
)
message
;
// filter beat
// filter
s
beat
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
xxlRpcResponse
.
getRequestId
())){
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
xxlRpcResponse
.
getRequestId
())){
return
;
return
;
}
}
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/net/impl/mina/server/MinaServerHandler.java
View file @
5e13875d
...
@@ -37,7 +37,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
...
@@ -37,7 +37,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
// request
// request
final
RpcRequest
rpcRequest
=
(
RpcRequest
)
message
;
final
RpcRequest
rpcRequest
=
(
RpcRequest
)
message
;
// filter beat
// filter
s
beat
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
rpcRequest
.
getRequestId
())){
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
rpcRequest
.
getRequestId
())){
return
;
return
;
}
}
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/net/impl/netty/server/NettyServerHandler.java
View file @
5e13875d
...
@@ -33,7 +33,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<RpcRequest>
...
@@ -33,7 +33,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<RpcRequest>
@Override
@Override
public
void
channelRead0
(
final
ChannelHandlerContext
ctx
,
final
RpcRequest
rpcRequest
)
throws
Exception
{
public
void
channelRead0
(
final
ChannelHandlerContext
ctx
,
final
RpcRequest
rpcRequest
)
throws
Exception
{
// filter beat
// filter
s
beat
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
rpcRequest
.
getRequestId
())){
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
rpcRequest
.
getRequestId
())){
logger
.
debug
(
">>>>>>>>>>> myth-rpc provider netty server read beat-ping."
);
logger
.
debug
(
">>>>>>>>>>> myth-rpc provider netty server read beat-ping."
);
return
;
return
;
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/net/impl/netty_http/server/NettyHttpServerHandler.java
View file @
5e13875d
...
@@ -80,7 +80,7 @@ public class NettyHttpServerHandler extends SimpleChannelInboundHandler<FullHttp
...
@@ -80,7 +80,7 @@ public class NettyHttpServerHandler extends SimpleChannelInboundHandler<FullHttp
RpcRequest
rpcRequest
=
(
RpcRequest
)
rpcProviderFactory
.
getSerializer
().
deserialize
(
requestBytes
,
RpcRequest
.
class
);
RpcRequest
rpcRequest
=
(
RpcRequest
)
rpcProviderFactory
.
getSerializer
().
deserialize
(
requestBytes
,
RpcRequest
.
class
);
requestId
=
rpcRequest
.
getRequestId
();
requestId
=
rpcRequest
.
getRequestId
();
// filter beat
// filter
s
beat
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
rpcRequest
.
getRequestId
())){
if
(
Beat
.
BEAT_ID
.
equalsIgnoreCase
(
rpcRequest
.
getRequestId
())){
logger
.
debug
(
">>>>>>>>>>> myth-rpc provider netty_http server read beat-ping."
);
logger
.
debug
(
">>>>>>>>>>> myth-rpc provider netty_http server read beat-ping."
);
return
;
return
;
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/provider/RpcProviderFactory.java
View file @
5e13875d
This diff is collapsed.
Click to expand it.
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/provider/annotation/RpcService.java
View file @
5e13875d
...
@@ -11,9 +11,14 @@ import java.lang.annotation.*;
...
@@ -11,9 +11,14 @@ import java.lang.annotation.*;
@Inherited
@Inherited
public
@interface
RpcService
{
public
@interface
RpcService
{
String
version
()
default
""
;
/**
/**
* @return
* 提供http服务
* 向注册中心注册 服务的id 同一个业务中必须唯一
* 端口号从配置文件中获取springboot的端口号
*/
*/
String
version
()
default
""
;
boolean
http_type
()
default
false
;
}
}
byit-myth-rpc/src/main/java/com/byit/rpc/remoting/provider/impl/RpcSpringProviderFactory.java
View file @
5e13875d
...
@@ -9,6 +9,7 @@ import com.byit.rpc.util.RpcException;
...
@@ -9,6 +9,7 @@ import com.byit.rpc.util.RpcException;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationContextAware
;
...
@@ -16,9 +17,8 @@ import java.util.Map;
...
@@ -16,9 +17,8 @@ import java.util.Map;
/**
/**
* myth-rpc provider (for spring)
* myth-rpc provider (for spring)
*
*/
*/
public
class
RpcSpringProviderFactory
extends
RpcProviderFactory
implements
ApplicationContextAware
,
InitializingBean
,
DisposableBean
{
public
class
RpcSpringProviderFactory
extends
RpcProviderFactory
implements
ApplicationContextAware
,
InitializingBean
,
DisposableBean
{
// ---------------------- config ----------------------
// ---------------------- config ----------------------
...
@@ -28,13 +28,22 @@ public class RpcSpringProviderFactory extends RpcProviderFactory implements Appl
...
@@ -28,13 +28,22 @@ public class RpcSpringProviderFactory extends RpcProviderFactory implements Appl
private
int
corePoolSize
;
private
int
corePoolSize
;
private
int
maxPoolSize
;
private
int
maxPoolSize
;
private
String
ip
;
// for registry
private
String
ip
;
// for registry
private
int
port
;
// default port
private
int
port
;
// default port
private
String
accessToken
;
private
String
accessToken
;
private
Class
<?
extends
ServiceRegistry
>
serviceRegistryClass
;
// class.forname
private
Class
<?
extends
ServiceRegistry
>
serviceRegistryClass
;
// class.forname
private
Map
<
String
,
String
>
serviceRegistryParam
;
private
Map
<
String
,
String
>
serviceRegistryParam
;
@Value
(
"${server.port}"
)
private
int
serverPort
;
@Value
(
"${spring.application.name}"
)
private
String
serverName
;
/**
* 该服务是否提供http服务
*/
private
Boolean
isHttp
=
false
;
// set
// set
public
void
setNetType
(
String
netType
)
{
public
void
setNetType
(
String
netType
)
{
...
@@ -85,15 +94,16 @@ public class RpcSpringProviderFactory extends RpcProviderFactory implements Appl
...
@@ -85,15 +94,16 @@ public class RpcSpringProviderFactory extends RpcProviderFactory implements Appl
// util
// util
private
void
prepareConfig
(){
private
void
prepareConfig
()
{
// prepare config
// prepare config
NetEnum
netTypeEnum
=
NetEnum
.
autoMatch
(
netType
,
null
);
NetEnum
netTypeEnum
=
NetEnum
.
autoMatch
(
netType
,
null
);
Serializer
.
SerializeEnum
serializeEnum
=
Serializer
.
SerializeEnum
.
match
(
serialize
,
null
);
Serializer
.
SerializeEnum
serializeEnum
=
Serializer
.
SerializeEnum
.
match
(
serialize
,
null
);
Serializer
serializer
=
serializeEnum
!=
null
?
serializeEnum
.
getSerializer
():
null
;
Serializer
serializer
=
serializeEnum
!=
null
?
serializeEnum
.
getSerializer
()
:
null
;
// init config
// init config
super
.
initConfig
(
netTypeEnum
,
serializer
,
corePoolSize
,
maxPoolSize
,
ip
,
port
,
accessToken
,
serviceRegistryClass
,
serviceRegistryParam
);
super
.
initConfig
(
netTypeEnum
,
serializer
,
corePoolSize
,
maxPoolSize
,
ip
,
port
,
isHttp
,
serverPort
,
serverName
,
accessToken
,
serviceRegistryClass
,
serviceRegistryParam
);
}
}
...
@@ -103,24 +113,28 @@ public class RpcSpringProviderFactory extends RpcProviderFactory implements Appl
...
@@ -103,24 +113,28 @@ public class RpcSpringProviderFactory extends RpcProviderFactory implements Appl
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
Map
<
String
,
Object
>
serviceBeanMap
=
applicationContext
.
getBeansWithAnnotation
(
RpcService
.
class
);
Map
<
String
,
Object
>
serviceBeanMap
=
applicationContext
.
getBeansWithAnnotation
(
RpcService
.
class
);
if
(
serviceBeanMap
!=
null
&&
serviceBeanMap
.
size
()>
0
)
{
if
(
serviceBeanMap
!=
null
&&
serviceBeanMap
.
size
()
>
0
)
{
for
(
Object
serviceBean
:
serviceBeanMap
.
values
())
{
for
(
Object
serviceBean
:
serviceBeanMap
.
values
())
{
// valid
// valid
if
(
serviceBean
.
getClass
().
getInterfaces
().
length
==
0
)
{
if
(
serviceBean
.
getClass
().
getInterfaces
().
length
==
0
)
{
throw
new
RpcException
(
"myth-rpc, service(RpcService) must inherit interface."
);
throw
new
RpcException
(
"myth-rpc, service(RpcService) must inherit interface."
);
}
}
// add service
// add service
RpcService
xxlR
pcService
=
serviceBean
.
getClass
().
getAnnotation
(
RpcService
.
class
);
RpcService
r
pcService
=
serviceBean
.
getClass
().
getAnnotation
(
RpcService
.
class
);
String
iface
=
serviceBean
.
getClass
().
getInterfaces
()[
0
].
getName
();
String
iface
=
serviceBean
.
getClass
().
getInterfaces
()[
0
].
getName
();
String
version
=
xxlRpcService
.
version
();
String
version
=
rpcService
.
version
();
//如果提供的是htp服务
if
(
rpcService
.
http_type
())
{
this
.
isHttp
=
true
;
super
.
addService
(
serverName
,
version
,
serviceBean
);
}
else
{
super
.
addService
(
iface
,
version
,
serviceBean
);
}
super
.
addService
(
iface
,
version
,
serviceBean
);
}
}
}
}
// TODO,addServices by api + prop
}
}
@Override
@Override
...
...
demo-client/byit-demo-service/src/main/resources/application-dev.properties
0 → 100644
View file @
5e13875d
# myth-rpc
myth-rpc.remoting.port
=
9998
myth-rpc.registry.address
=
http://localhost:8080/myth-register
myth-rpc.registry.env
=
liyuan
myth-rpc.registry.biz
=
byit-myth-job
logging.config
=
classpath:logback.xml
\ No newline at end of file
demo-client/byit-demo-service/src/main/resources/application-pre.properties
0 → 100644
View file @
5e13875d
# myth-rpc
myth-rpc.remoting.port
=
9998
myth-rpc.registry.address
=
http://localhost:8080/myth-register
myth-rpc.registry.env
=
pre
myth-rpc.registry.biz
=
byit-myth-job
logging.config
=
classpath:logback.xml
\ No newline at end of file
demo-client/byit-demo-service/src/main/resources/application-test.properties
0 → 100644
View file @
5e13875d
# myth-rpc
myth-rpc.remoting.port
=
9998
myth-rpc.registry.address
=
http://localhost:8080/myth-register
myth-rpc.registry.env
=
test
myth-rpc.registry.biz
=
byit-myth-job
logging.config
=
classpath:logback.xml
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment