commit
25acd82fbb
@ -0,0 +1,21 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Example user template template
|
||||
### Example user template
|
||||
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
*.iml
|
||||
out
|
||||
gen
|
||||
### Maven template
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.12.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<groupId>com.mashibing</groupId>
|
||||
<artifactId>hippo4j-client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hippo4j</groupId>
|
||||
<artifactId>hippo4j-spring-boot-starter</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hippo4j</groupId>
|
||||
<artifactId>hippo4j-spring-boot-starter-adapter-rabbitmq</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,19 @@
|
||||
package com.mashibing;
|
||||
|
||||
import cn.hippo4j.core.enable.EnableDynamicThreadPool;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDynamicThreadPool
|
||||
public class Hippo4jClientStarterApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Hippo4jClientStarterApp.class,args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.mashibing.config;
|
||||
|
||||
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
|
||||
import cn.hippo4j.core.executor.DynamicThreadPool;
|
||||
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 交给Hippo4j-Server管理的线程池
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Configuration
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
@Bean
|
||||
@DynamicThreadPool
|
||||
public ThreadPoolExecutor testThreadPool(){
|
||||
//1、 采用线程池Builder去构建
|
||||
ThreadPoolExecutor testThreadPool = ThreadPoolBuilder.builder()
|
||||
.corePoolSize(10)
|
||||
.maximumPoolSize(10)
|
||||
.keepAliveTime(10)
|
||||
.timeUnit(TimeUnit.SECONDS)
|
||||
.workQueue(BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE)
|
||||
.threadFactory("test")
|
||||
.rejected(new ThreadPoolExecutor.AbortPolicy())
|
||||
.threadPoolId("test")
|
||||
.dynamicPool()
|
||||
.build();
|
||||
return testThreadPool;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.mashibing.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@RestController
|
||||
public class TestController {
|
||||
|
||||
@Resource
|
||||
private ThreadPoolExecutor testThreadPool;
|
||||
|
||||
@GetMapping("/test")
|
||||
public String test(){
|
||||
testThreadPool.execute(() -> System.out.println(Thread.currentThread().getName()));
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@GetMapping("/web")
|
||||
public String web(){
|
||||
System.out.println(Thread.currentThread().getName());
|
||||
return "ok";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.mashibing.mq;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Component
|
||||
public class TestListener {
|
||||
|
||||
@RabbitListener(queues = "hippo4j",containerFactory = "defaultContainerFactory")
|
||||
public void consume(String message){
|
||||
System.out.println(Thread.currentThread().getName() + ":消费消息 --> " + message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
spring:
|
||||
profiles:
|
||||
active:
|
||||
application:
|
||||
name: hippo4j-client
|
||||
dynamic:
|
||||
thread-pool:
|
||||
server-addr: 192.168.11.88:6691
|
||||
username: admin
|
||||
password: 123456
|
||||
namespace: mashibing # 租户名称
|
||||
item-id: ${spring.application.name} # 项目名称,需要与与服务名称保持一致。
|
||||
rabbitmq:
|
||||
host: 192.168.11.88
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
virtual-host: /
|
Loading…
Reference in new issue