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
48f910e6
Commit
48f910e6
authored
Nov 05, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决maven循环依赖
parent
1848ec29
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
40 deletions
+104
-40
AdminRegisterConfig.java
...in/src/main/java/com/byit/config/AdminRegisterConfig.java
+7
-1
pom.xml
byit-myth-rpc/pom.xml
+5
-16
RequestUtil.java
...myth-rpc/src/main/java/com/byit/rpc/util/RequestUtil.java
+24
-23
RpcSpringUtil.java
...th-rpc/src/main/java/com/byit/rpc/util/RpcSpringUtil.java
+68
-0
No files found.
byit-myth-admin/src/main/java/com/byit/config/AdminRegisterConfig.java
View file @
48f910e6
...
@@ -3,6 +3,7 @@ package com.byit.config;
...
@@ -3,6 +3,7 @@ package com.byit.config;
import
com.byit.rpc.registry.impl.RegistryServiceRegistry
;
import
com.byit.rpc.registry.impl.RegistryServiceRegistry
;
import
com.byit.rpc.remoting.invoker.impl.RpcSpringInvokerFactory
;
import
com.byit.rpc.remoting.invoker.impl.RpcSpringInvokerFactory
;
import
com.byit.rpc.remoting.provider.impl.RpcSpringProviderFactory
;
import
com.byit.rpc.remoting.provider.impl.RpcSpringProviderFactory
;
import
com.byit.rpc.util.RpcSpringUtil
;
import
com.byit.util.SpringUtil
;
import
com.byit.util.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -64,8 +65,13 @@ public class AdminRegisterConfig {
...
@@ -64,8 +65,13 @@ public class AdminRegisterConfig {
}
}
@Bean
@Bean
public
SpringUtil
rpcS
pringUtil
(){
public
SpringUtil
s
pringUtil
(){
return
new
SpringUtil
();
return
new
SpringUtil
();
}
}
@Bean
public
RpcSpringUtil
rpcSpringUtil
(){
return
new
RpcSpringUtil
();
}
}
}
byit-myth-rpc/pom.xml
View file @
48f910e6
...
@@ -37,22 +37,6 @@
...
@@ -37,22 +37,6 @@
<dependency>
<dependency>
<groupId>
myth-job
</groupId>
<groupId>
myth-job
</groupId>
<artifactId>
myth-web-core
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<exclusions>
<exclusion>
<groupId>
myth-job
</groupId>
<artifactId>
myth-core-common
</artifactId>
</exclusion>
<exclusion>
<groupId>
myth-job
</groupId>
<artifactId>
myth-web-core
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
myth-job
</groupId>
<artifactId>
myth-dto-core
</artifactId>
<artifactId>
myth-dto-core
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependency>
...
@@ -88,6 +72,11 @@
...
@@ -88,6 +72,11 @@
<scope>
provided
</scope>
<scope>
provided
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
<!-- ********************** serialize (default=hessian) ********************** -->
<!-- ********************** serialize (default=hessian) ********************** -->
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/util/RequestUtil.java
View file @
48f910e6
...
@@ -3,11 +3,9 @@ package com.byit.rpc.util;
...
@@ -3,11 +3,9 @@ package com.byit.rpc.util;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.dto.executor.ScriptDto
;
import
com.byit.dto.executor.ScriptDto
;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.rpc.remoting.invoker.reference.RpcReferenceBean
;
import
com.byit.rpc.remoting.invoker.route.LoadBalance
;
import
com.byit.rpc.remoting.invoker.route.LoadBalance
;
import
com.byit.rpc.remoting.net.Client
;
import
com.byit.rpc.remoting.net.Client
;
import
com.byit.rpc.remoting.net.params.Beat
;
import
com.byit.rpc.remoting.net.params.Beat
;
import
com.byit.util.SpringUtil
;
import
com.byit.utils.KeyUtil
;
import
com.byit.utils.KeyUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -20,29 +18,31 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
...
@@ -20,29 +18,31 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
public
class
RequestUtil
{
public
class
RequestUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RequestUtil
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RequestUtil
.
class
);
/**
/**
* 基于负载均衡方案选择合适的主机进行选取
* 基于负载均衡方案选择合适的主机进行选取
* @param client 客户端链接帮助其
*
* @param client 客户端链接帮助其
* @param loadBalance 负载均衡器
* @param loadBalance 负载均衡器
* @param address 地址
* @param address
地址
* @param serverKey 服务名称
* @param serverKey
服务名称
* @return 健全的服务地址
* @return 健全的服务地址
* @throws InterruptedException 线程异常
* @throws InterruptedException 线程异常
*/
*/
public
static
String
selectRPCServer
(
Client
client
,
LoadBalance
loadBalance
,
TreeSet
<
String
>
address
,
String
serverKey
,
Object
[]
parameters
)
throws
InterruptedException
{
public
static
String
selectRPCServer
(
Client
client
,
LoadBalance
loadBalance
,
TreeSet
<
String
>
address
,
String
serverKey
,
Object
[]
parameters
)
throws
InterruptedException
{
String
runKey
=
null
;
String
runKey
=
null
;
if
(
parameters
!=
null
&&
parameters
.
length
>
1
)
{
if
(
parameters
!=
null
&&
parameters
.
length
>
1
)
{
Object
parameter
=
parameters
[
0
];
Object
parameter
=
parameters
[
0
];
if
(
parameter
instanceof
ScriptDto
)
{
if
(
parameter
instanceof
ScriptDto
)
{
ScriptDto
scriptDto
=
(
ScriptDto
)
parameter
;
ScriptDto
scriptDto
=
(
ScriptDto
)
parameter
;
Integer
logId
=
scriptDto
.
getLogId
();
Integer
logId
=
scriptDto
.
getLogId
();
runKey
=
KeyUtil
.
generateRunKey
(
logId
);
runKey
=
KeyUtil
.
generateRunKey
(
logId
);
}
}
}
}
for
(
String
ignored
:
address
)
{
for
(
String
ignored
:
address
)
{
String
routeHost
=
loadBalance
.
rpcInvokerRouter
.
route
(
serverKey
,
address
);
String
routeHost
=
loadBalance
.
rpcInvokerRouter
.
route
(
serverKey
,
address
);
boolean
retryRpcHost
=
retryRpcHost
(
client
,
routeHost
,
runKey
,
3
,
1
);
boolean
retryRpcHost
=
retryRpcHost
(
client
,
routeHost
,
runKey
,
3
,
1
);
if
(
retryRpcHost
)
{
if
(
retryRpcHost
)
{
return
routeHost
;
return
routeHost
;
}
}
}
}
...
@@ -51,35 +51,36 @@ public class RequestUtil {
...
@@ -51,35 +51,36 @@ public class RequestUtil {
/**
/**
* rpc节点重试
* rpc节点重试
* @param client 客户端
*
* @param host 主机
* @param client 客户端
* @param host 主机
* @param retryTotalCount 重试次数
* @param retryTotalCount 重试次数
* @param thisRetryCount 当前重试次数
* @param thisRetryCount
当前重试次数
* @return 是否成功
* @return 是否成功
*/
*/
public
static
boolean
retryRpcHost
(
Client
client
,
String
host
,
String
runKey
,
int
retryTotalCount
,
int
thisRetryCount
)
throws
InterruptedException
{
public
static
boolean
retryRpcHost
(
Client
client
,
String
host
,
String
runKey
,
int
retryTotalCount
,
int
thisRetryCount
)
throws
InterruptedException
{
log
.
info
(
"------当前rpc的请求的地址为:{}-------"
,
host
);
log
.
info
(
"------当前rpc的请求的地址为:{}-------"
,
host
);
try
{
try
{
client
.
asyncSend
(
host
,
Beat
.
BEAT_PING
);
client
.
asyncSend
(
host
,
Beat
.
BEAT_PING
);
log
.
info
(
"------{}rpc通道建立成功,重试了{}次------"
,
host
,
thisRetryCount
-
1
);
log
.
info
(
"------{}rpc通道建立成功,重试了{}次------"
,
host
,
thisRetryCount
-
1
);
return
true
;
return
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
//当前重试次数 小于等于总共的重试次数时
//当前重试次数 小于等于总共的重试次数时
if
(
thisRetryCount
<=
retryTotalCount
)
{
if
(
thisRetryCount
<=
retryTotalCount
)
{
String
redisFormat
=
String
.
format
(
"rpc通道[%s]建立时出现异常,开始第%s次重试!"
,
host
,
thisRetryCount
);
String
redisFormat
=
String
.
format
(
"rpc通道[%s]建立时出现异常,开始第%s次重试!"
,
host
,
thisRetryCount
);
log
.
error
(
"{},rpc通道建立时出现异常,异常信息为:{},开始第{}次重试!"
,
host
,
RPCLogUtil
.
getMessage
(
e
),
thisRetryCount
);
log
.
error
(
"{},rpc通道建立时出现异常,异常信息为:{},开始第{}次重试!"
,
host
,
RPCLogUtil
.
getMessage
(
e
),
thisRetryCount
);
StringRedisTemplate
stringRedisTemplate
=
SpringUtil
.
getBean
(
StringRedisTemplate
.
class
);
StringRedisTemplate
stringRedisTemplate
=
Rpc
SpringUtil
.
getBean
(
StringRedisTemplate
.
class
);
RunLog
runLog
=
RunLog
.
builder
().
runLog
(
redisFormat
).
isEnd
(
false
).
build
();
RunLog
runLog
=
RunLog
.
builder
().
runLog
(
redisFormat
).
isEnd
(
false
).
build
();
stringRedisTemplate
.
opsForList
().
rightPush
(
runKey
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
stringRedisTemplate
.
opsForList
().
rightPush
(
runKey
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
Thread
.
sleep
(
1000
*
thisRetryCount
);
Thread
.
sleep
(
1000
*
thisRetryCount
);
retryRpcHost
(
client
,
host
,
runKey
,
retryTotalCount
,
++
thisRetryCount
);
retryRpcHost
(
client
,
host
,
runKey
,
retryTotalCount
,
++
thisRetryCount
);
}
}
String
format
=
String
.
format
(
"与主机【%s】建立通道,总共【%s】次,全部失败,开始挑选下一个负载均衡方案重试,请稍后"
,
host
,
retryTotalCount
);
String
format
=
String
.
format
(
"与主机【%s】建立通道,总共【%s】次,全部失败,开始挑选下一个负载均衡方案重试,请稍后"
,
host
,
retryTotalCount
);
StringRedisTemplate
stringRedisTemplate
=
SpringUtil
.
getBean
(
StringRedisTemplate
.
class
);
StringRedisTemplate
stringRedisTemplate
=
Rpc
SpringUtil
.
getBean
(
StringRedisTemplate
.
class
);
RunLog
runLog
=
RunLog
.
builder
().
runLog
(
format
).
isEnd
(
false
).
build
();
RunLog
runLog
=
RunLog
.
builder
().
runLog
(
format
).
isEnd
(
false
).
build
();
stringRedisTemplate
.
opsForList
().
rightPush
(
runKey
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
stringRedisTemplate
.
opsForList
().
rightPush
(
runKey
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
...
...
byit-myth-rpc/src/main/java/com/byit/rpc/util/RpcSpringUtil.java
0 → 100644
View file @
48f910e6
package
com
.
byit
.
rpc
.
util
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
java.util.Map
;
public
class
RpcSpringUtil
implements
ApplicationContextAware
{
private
static
ApplicationContext
applicationContext
=
null
;
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
if
(
RpcSpringUtil
.
applicationContext
==
null
)
{
RpcSpringUtil
.
applicationContext
=
applicationContext
;
}
}
/**
* 获取applicationContext
* @return 返回applicationContext
*/
public
static
ApplicationContext
getApplicationContext
()
{
return
applicationContext
;
}
/**
* 通过name获取 Bean.
* @param name
* @return
*/
public
static
Object
getBean
(
String
name
){
return
getApplicationContext
().
getBean
(
name
);
}
/**
* 通过class获取Bean.
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
T
getBean
(
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
clazz
);
}
/**
* 通过name,以及Clazz返回指定的Bean
* @param name
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
name
,
clazz
);
}
/**
* 获取实现某个接口的类
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
Map
<
String
,
T
>
getBeansOfType
(
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBeansOfType
(
clazz
);
}
}
\ 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