1.延迟接收消息,防止出现线程吃满
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -146,4 +146,4 @@ fabric.properties
|
|||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
!/.xcodemap/
|
!/.xcodemap/
|
||||||
!/tk-data-save.log
|
/tk-data-save.log
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.yupi.springbootinit.common;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class DelayedRabbitMQStarter implements ApplicationRunner {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RabbitListenerEndpointRegistry registry; // Spring 提供的监听器注册表
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
// 延迟 5 秒后启动监听器
|
||||||
|
log.info("延迟5秒启动 rabbitMQ 监听");
|
||||||
|
Thread.sleep(5000);
|
||||||
|
registry.getListenerContainer("hosts").start();
|
||||||
|
registry.getListenerContainer("bigbrother").start();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,8 @@ package com.yupi.springbootinit.controller;
|
|||||||
|
|
||||||
import com.yupi.springbootinit.common.BaseResponse;
|
import com.yupi.springbootinit.common.BaseResponse;
|
||||||
import com.yupi.springbootinit.common.ResultUtils;
|
import com.yupi.springbootinit.common.ResultUtils;
|
||||||
import com.yupi.springbootinit.model.entity.NewHosts;
|
|
||||||
import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
||||||
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
||||||
import com.yupi.springbootinit.service.HostInfoService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.yupi.springbootinit.service.ServerBigBrotherService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public class MQReceiver {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@RabbitListener(queues = "HOST_INFO_QUEUE")
|
@RabbitListener(queues = "HOST_INFO_QUEUE",id = "hosts", autoStartup = "false")
|
||||||
@Async("taskExecutor")
|
@Async("taskExecutor")
|
||||||
public void receive(List<NewHosts> hosts, Channel channel, Message message) throws IOException {
|
public void receive(List<NewHosts> hosts, Channel channel, Message message) throws IOException {
|
||||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||||
@@ -61,7 +62,7 @@ public class MQReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RabbitListener(queues = "BIG_BROTHER_QUEUE")
|
@RabbitListener(queues = "BIG_BROTHER_QUEUE",id = "bigbrother", autoStartup = "false")
|
||||||
@Async("taskExecutor")
|
@Async("taskExecutor")
|
||||||
public void bigBrotherReceive(ServerBigBrother bigBrotherList, Channel channel, Message message) throws IOException {
|
public void bigBrotherReceive(ServerBigBrother bigBrotherList, Channel channel, Message message) throws IOException {
|
||||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||||
|
|||||||
@@ -26,4 +26,7 @@ spring:
|
|||||||
listener:
|
listener:
|
||||||
simple:
|
simple:
|
||||||
acknowledge-mode: manual
|
acknowledge-mode: manual
|
||||||
|
concurrency: 10
|
||||||
|
max-concurrency: 20
|
||||||
|
prefetch: 5
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ spring:
|
|||||||
listener:
|
listener:
|
||||||
simple:
|
simple:
|
||||||
acknowledge-mode: manual
|
acknowledge-mode: manual
|
||||||
mybatis-plus:
|
concurrency: 10
|
||||||
configuration:
|
max-concurrency: 20
|
||||||
# 生产环境关闭日志
|
prefetch: 5
|
||||||
log-impl: ''
|
|
||||||
# 接口文档配置
|
# 接口文档配置
|
||||||
knife4j:
|
knife4j:
|
||||||
basic:
|
basic:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ spring:
|
|||||||
name: springboot-init
|
name: springboot-init
|
||||||
# 默认 dev 环境
|
# 默认 dev 环境
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: prod
|
||||||
# 支持 swagger3
|
# 支持 swagger3
|
||||||
mvc:
|
mvc:
|
||||||
pathmatch:
|
pathmatch:
|
||||||
@@ -60,7 +60,7 @@ server:
|
|||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: false
|
map-underscore-to-camel-case: false
|
||||||
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||||
default-executor-type: batch
|
default-executor-type: batch
|
||||||
global-config:
|
global-config:
|
||||||
banner: false
|
banner: false
|
||||||
|
|||||||
@@ -34,10 +34,11 @@
|
|||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</logger>
|
</logger>
|
||||||
<logger name="com.baomidou.mybatisplus" level="INFO">
|
<logger name="com.baomidou.mybatisplus" level="INFO">
|
||||||
<appender-ref ref="STDOUT"/>
|
|
||||||
<appender-ref ref="FILE"/>
|
<appender-ref ref="FILE"/>
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</logger>
|
||||||
|
<logger name="org.springframework" level="INFO">
|
||||||
</logger>
|
</logger>
|
||||||
<logger name="org.springframework" level="INFO"/>
|
|
||||||
<logger name="org.redisson" level="INFO"/>
|
<logger name="org.redisson" level="INFO"/>
|
||||||
</springProfile>
|
</springProfile>
|
||||||
|
|
||||||
@@ -47,11 +48,12 @@
|
|||||||
<appender-ref ref="FILE"/>
|
<appender-ref ref="FILE"/>
|
||||||
</root>
|
</root>
|
||||||
<logger name="com.yupi.springbootinit" level="INFO" additivity="false">
|
<logger name="com.yupi.springbootinit" level="INFO" additivity="false">
|
||||||
<appender-ref ref="STDOUT"/>
|
|
||||||
<appender-ref ref="FILE"/>
|
<appender-ref ref="FILE"/>
|
||||||
</logger>
|
</logger>
|
||||||
<logger name="org.springframework" level="INFO"/>
|
<logger name="org.springframework" level="INFO">
|
||||||
<logger name="com.baomidou.mybatisplus" level="INFO"/>
|
</logger>
|
||||||
|
<logger name="com.baomidou.mybatisplus" level="INFO">
|
||||||
|
</logger>
|
||||||
<logger name="org.redisson" level="INFO"/>
|
<logger name="org.redisson" level="INFO"/>
|
||||||
</springProfile>
|
</springProfile>
|
||||||
</configuration>
|
</configuration>
|
||||||
Reference in New Issue
Block a user