Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
88b253ce
Commit
88b253ce
authored
Aug 06, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
629ae0f5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
41 deletions
+85
-41
MqConfig.java
yzg-util-mq/src/main/java/com/yanzuoguang/mq/MqConfig.java
+62
-0
MqConsumeDynamic.java
...c/main/java/com/yanzuoguang/mq/base/MqConsumeDynamic.java
+7
-13
MqMessageInitPlan.java
.../main/java/com/yanzuoguang/mq/plan/MqMessageInitPlan.java
+10
-14
YzgMqProcedure.java
...src/main/java/com/yanzuoguang/mq/plan/YzgMqProcedure.java
+6
-14
No files found.
yzg-util-mq/src/main/java/com/yanzuoguang/mq/MqConfig.java
0 → 100644
View file @
88b253ce
package
com
.
yanzuoguang
.
mq
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* MQ配置
*
* @author 颜佐光
*/
@Component
public
class
MqConfig
{
@Value
(
"${spring.rabbitmq.listener.simple.concurrency:1}"
)
private
int
concurrency
;
@Value
(
"${spring.rabbitmq.listener.simple.max-concurrency:10}"
)
private
int
maxConcurrency
;
@Value
(
"${spring.rabbitmq.listener.simple.prefetch:100}"
)
private
int
prefetch
;
@Value
(
"${spring.rabbitmq.listener.simple.transaction-size:100}"
)
private
int
txSize
;
@Value
(
"${yzg.mq.retry.size:100}"
)
private
int
retrySize
=
100
;
@Value
(
"${yzg.mq.retry.time:60000}"
)
private
int
retryTime
=
1000
;
@Value
(
"${yzg.mq.unit.min:1000}"
)
private
long
unitMin
;
public
int
getConcurrency
()
{
return
concurrency
;
}
public
int
getMaxConcurrency
()
{
return
maxConcurrency
;
}
public
int
getPrefetch
()
{
return
prefetch
;
}
public
int
getTxSize
()
{
return
txSize
;
}
public
int
getRetrySize
()
{
return
retrySize
;
}
public
int
getRetryTime
()
{
return
retryTime
;
}
public
long
getUnitMin
()
{
return
unitMin
;
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/base/MqConsumeDynamic.java
View file @
88b253ce
package
com
.
yanzuoguang
.
mq
.
base
;
import
com.yanzuoguang.mq.MqConfig
;
import
com.yanzuoguang.mq.base.consumer.ConsumerSimpleMessageListenerContainer
;
import
org.springframework.amqp.core.AcknowledgeMode
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
...
...
@@ -10,7 +11,6 @@ import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanInitializationException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.*
;
import
org.springframework.stereotype.Component
;
...
...
@@ -26,14 +26,7 @@ public class MqConsumeDynamic implements ApplicationContextAware {
private
RabbitAdmin
rabbitAdmin
;
@Value
(
"${spring.rabbitmq.listener.simple.concurrency:1}"
)
private
int
concurrency
;
@Value
(
"${spring.rabbitmq.listener.simple.max-concurrency:10}"
)
private
int
maxConcurrency
;
@Value
(
"${spring.rabbitmq.listener.simple.prefetch:100}"
)
private
int
prefetch
;
@Value
(
"${spring.rabbitmq.listener.simple.transaction-size:100}"
)
private
int
txSize
;
private
MqConfig
mqConfig
;
/**
* Set the ApplicationContext that this object runs in.
...
...
@@ -53,6 +46,7 @@ public class MqConsumeDynamic implements ApplicationContextAware {
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
connectionFactory
=
applicationContext
.
getBean
(
ConnectionFactory
.
class
);
rabbitAdmin
=
applicationContext
.
getBean
(
RabbitAdmin
.
class
);
mqConfig
=
applicationContext
.
getBean
(
MqConfig
.
class
);
}
public
SimpleMessageListenerContainer
init
(
String
queueName
,
ChannelAwareMessageListener
messageListener
)
{
...
...
@@ -67,11 +61,11 @@ public class MqConsumeDynamic implements ApplicationContextAware {
if
(
concurrency
>
0
)
{
container
.
setConcurrentConsumers
(
concurrency
);
}
else
{
container
.
setConcurrentConsumers
(
this
.
concurrency
);
container
.
setConcurrentConsumers
(
this
.
mqConfig
.
getConcurrency
()
);
}
container
.
setMaxConcurrentConsumers
(
maxConcurrency
);
container
.
setPrefetchCount
(
prefetch
);
container
.
setTxSize
(
t
xSize
);
container
.
setMaxConcurrentConsumers
(
this
.
mqConfig
.
getMaxConcurrency
()
);
container
.
setPrefetchCount
(
this
.
mqConfig
.
getPrefetch
()
);
container
.
setTxSize
(
t
his
.
mqConfig
.
getTxSize
()
);
container
.
setMessageListener
(
new
MessageListenerAdapter
(
messageListener
));
container
.
start
();
return
container
;
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/plan/MqMessageInitPlan.java
View file @
88b253ce
package
com
.
yanzuoguang
.
mq
.
plan
;
import
com.yanzuoguang.mq.MqConfig
;
import
com.yanzuoguang.mq.service.MessageService
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
@@ -9,7 +10,6 @@ import com.yanzuoguang.util.thread.ThreadNext;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanInitializationException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.*
;
import
org.springframework.stereotype.Component
;
...
...
@@ -24,12 +24,12 @@ import java.util.List;
public
class
MqMessageInitPlan
implements
ThreadNext
.
Next
,
Runnable
,
ApplicationContextAware
{
private
MessageService
messageService
;
private
MqConfig
mqConfig
;
@Value
(
"${yzg.mq.retry.size:100}"
)
private
int
retrySize
=
100
;
@Value
(
"${yzg.mq.retry.time:60000}"
)
private
int
retryTime
=
1000
;
/**
* 是否为空
*/
private
boolean
empty
=
true
;
/**
* Set the ApplicationContext that this object runs in.
...
...
@@ -48,13 +48,9 @@ public class MqMessageInitPlan implements ThreadNext.Next, Runnable, Application
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
messageService
=
applicationContext
.
getBean
(
MessageService
.
class
);
mqConfig
=
applicationContext
.
getBean
(
MqConfig
.
class
);
}
/**
* 是否为空
*/
private
boolean
empty
=
true
;
public
MqMessageInitPlan
()
{
ThreadNext
.
start
(
this
,
"message init error"
);
}
...
...
@@ -74,7 +70,7 @@ public class MqMessageInitPlan implements ThreadNext.Next, Runnable, Application
if
(!
empty
)
{
return
0
;
}
return
retryTime
;
return
mqConfig
.
getRetryTime
()
;
}
/**
...
...
@@ -90,7 +86,7 @@ public class MqMessageInitPlan implements ThreadNext.Next, Runnable, Application
*/
@Override
public
void
run
()
{
List
<
MessageVo
>
messages
=
messageService
.
updateBatch
(
StringHelper
.
getNewID
(),
retrySize
);
List
<
MessageVo
>
messages
=
messageService
.
updateBatch
(
StringHelper
.
getNewID
(),
mqConfig
.
getRetrySize
()
);
for
(
MessageVo
message
:
messages
)
{
try
{
messageService
.
nextSend
(
message
);
...
...
@@ -99,6 +95,6 @@ public class MqMessageInitPlan implements ThreadNext.Next, Runnable, Application
}
}
empty
=
messages
.
size
()
<
retrySize
;
empty
=
messages
.
size
()
<
mqConfig
.
getRetrySize
()
;
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/plan/YzgMqProcedure.java
View file @
88b253ce
package
com
.
yanzuoguang
.
mq
.
plan
;
import
com.yanzuoguang.mq.MqConfig
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.vo.MessagePlan
;
import
com.yanzuoguang.mq.vo.MessageVo
;
...
...
@@ -12,7 +13,6 @@ import com.yanzuoguang.util.helper.StringHelper;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanInitializationException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.*
;
import
org.springframework.stereotype.Component
;
...
...
@@ -31,13 +31,7 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
* 执行的消息队列
*/
public
static
final
String
YZG_CLEAR_LOG
=
"YZG_CLEAR_LOG"
;
/**
* 执行的消息队列
*/
public
static
final
String
YZG_MQ_SYSTEM_QUEUE
=
"YZG_MQ_SYSTEM_QUEUE"
;
/**
* 延迟队列
*/
public
static
final
String
YZG_MQ_SYSTEM_QUEUE_PLAN
=
"YZG_MQ_SYSTEM_QUEUE_PLAN"
;
/**
* 默认100天延迟
...
...
@@ -56,9 +50,7 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
* MQ服务
*/
private
MqService
mqService
;
@Value
(
"${yzg.mq.unit.min:1000}"
)
private
long
min
;
private
MqConfig
mqConfig
;
/**
* Set the ApplicationContext that this object runs in.
...
...
@@ -77,6 +69,7 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
mqService
=
applicationContext
.
getBean
(
MqService
.
class
);
mqConfig
=
applicationContext
.
getBean
(
MqConfig
.
class
);
}
/**
...
...
@@ -91,7 +84,6 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
*/
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
System
.
out
.
println
(
"init"
);
mqService
.
createQueue
(
new
QueueVo
(
YZG_CLEAR_LOG
));
mqService
.
createQueue
(
new
QueueVo
(
YZG_MQ_SYSTEM_QUEUE
));
mqService
.
createQueue
(
new
QueueVo
(
YZG_MQ_SYSTEM_QUEUE_PLAN
));
...
...
@@ -111,7 +103,7 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
}
for
(
TimeUnit
item
:
YZG_MQ_SYSTEM_QUEUE_PLAN_TIME
)
{
// 在时间范围内,则返回大于等待时间的队列
if
(
item
.
unit
<
m
in
&&
item
!=
YZG_MQ_SYSTEM_QUEUE_PLAN_MIN
)
{
if
(
item
.
unit
<
m
qConfig
.
getUnitMin
()
&&
item
!=
YZG_MQ_SYSTEM_QUEUE_PLAN_MIN
)
{
continue
;
}
mqService
.
createQueue
(
new
QueueVo
(
getQueueName
(
item
),
item
.
unit
,
YZG_MQ_SYSTEM_QUEUE_PLAN
));
...
...
@@ -139,7 +131,7 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
TimeUnit
prevUnit
=
null
;
for
(
TimeUnit
timeUnit
:
YZG_MQ_SYSTEM_QUEUE_PLAN_TIME
)
{
// 判断时间
if
(
timeUnit
.
unit
<
m
in
)
{
if
(
timeUnit
.
unit
<
m
qConfig
.
getUnitMin
()
)
{
continue
;
}
// 在时间范围内,则返回大于等待时间的队列
...
...
@@ -151,7 +143,7 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
}
if
(
prevUnit
==
null
)
{
prevUnit
=
YZG_MQ_SYSTEM_QUEUE_PLAN_MIN
;
}
else
if
(
prevUnit
.
unit
<
m
in
)
{
}
else
if
(
prevUnit
.
unit
<
m
qConfig
.
getUnitMin
()
)
{
throw
new
CodeException
(
"算法错误"
);
}
// 返回最大时间的队列
...
...
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