线程池管理工具-Hippo4j |
AI工具、AI绘图、AI专栏
如果你想学到最前沿、最火爆的技术,赶快加入吧✨
作者简介:硕风和炜,CSDN-Java领域优质创作者,保研|国家奖学金|JAVA开发技术栈|面试刷题|面经八股文|经验分享|好用的网站工具分享
恭喜你发现一枚宝藏博主,赶快收入囊中吧
人生如棋,我愿为卒,行动虽慢,可谁曾见我后退一步?
线程池管理工具-Hippo4j |
Hippo4j支持多种框架的线程池监控功能,其中包括,Dubbo、Hystrix、RabbitMQ、RocketMQ同时还支持SpringCloud中的Stream组件。
以RabbitMQ为测试的效果,来进行监控和修改。
注意: RabbitMQ监控的是消费者消费消息时的线程池信息。
Docker安装Rabbitmq超详细教程
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-amqpartifactId>
dependency>
spring:
rabbitmq:
host: 192.168.10.131 # 你服务的ip地址
port: 5672
username: guest
password: guest
virtual-host: /
@Configuration
public class RabbitMQThreadPoolConfig {
/**
* 构建消费者用到的线程
* @return
*/
@Bean
public ThreadPoolTaskExecutor rabbitThreadPool(){
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setMaxPoolSize(5);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("rabbit-");
return executor;
}
/**
* 构建容器工厂,将线程池设置进入
* @param connectionFactory
* @return
*/
@Bean
public AbstractRabbitListenerContainerFactory<?> defaultContainerFactory(ThreadPoolTaskExecutor rabbitThreadPool,AbstractConnectionFactory connectionFactory){
DirectRabbitListenerContainerFactory factory = new DirectRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
connectionFactory.setExecutor(rabbitThreadPool);
return factory;
}
}
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
public class TestListener {
@RabbitListener(queues = "consume-queue",containerFactory = "defaultContainerFactory")
public void consume(String message){
System.out.println(Thread.currentThread().getName() + ":消费消息 --> " + message);
}
}
根据官方文档中的提示,可以单独引入具体的三方框架依赖的支持,也可以直接全部引入。
单独引入方式
<dependency>
<groupId>cn.hippo4jgroupId>
<artifactId>hippo4j-spring-boot-starter-adapter-dubboartifactId>
<artifactId>hippo4j-spring-boot-starter-adapter-alibaba-dubboartifactId>
<artifactId>hippo4j-spring-boot-starter-adapter-hystrixartifactId>
<artifactId>hippo4j-spring-boot-starter-adapter-rabbitmqartifactId>
<artifactId>hippo4j-spring-boot-starter-adapter-rocketmqartifactId>
<artifactId>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmqartifactId>
<artifactId>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rabbitmqartifactId>
<version>1.5.0version>
dependency>
全部引入
<dependency>
<groupId>cn.hippo4jgroupId>
<artifactId>hippo4j-spring-boot-starter-adapter-allartifactId>
<version>1.5.0version>
dependency>
最后,我想和大家分享一句一直激励我的座右铭,希望可以与大家共勉! |