parent
90758f3b2a
commit
eb1578ada3
@ -1,16 +0,0 @@
|
|||||||
FROM anapsix/alpine-java:8_server-jre_unlimited
|
|
||||||
|
|
||||||
MAINTAINER jeecgos@163.com
|
|
||||||
|
|
||||||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
|
||||||
|
|
||||||
RUN mkdir -p /jeecg-cloud-example
|
|
||||||
|
|
||||||
WORKDIR /jeecg-cloud-example
|
|
||||||
|
|
||||||
EXPOSE 7001
|
|
||||||
|
|
||||||
ADD ./target/jeecg-cloud-example-2.4.2.jar ./
|
|
||||||
|
|
||||||
CMD java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-example-2.4.2.jar
|
|
||||||
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
<?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">
|
|
||||||
<parent>
|
|
||||||
<artifactId>jeecg-cloud-module</artifactId>
|
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
|
||||||
<version>2.4.2</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>jeecg-cloud-example</artifactId>
|
|
||||||
<description>jeecg-cloud-example 微服务测试例子</description>
|
|
||||||
<dependencies>
|
|
||||||
<!-- 引入jeecg-boot-starter-cloud依赖-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
|
||||||
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- 引入定时任务依赖 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
|
||||||
<artifactId>jeecg-boot-starter-job</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 引入分布式锁依赖 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
|
||||||
<artifactId>jeecg-boot-starter-lock</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--rabbitmq消息队列-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
|
||||||
<artifactId>jeecg-boot-starter-rabbitmq</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
package org.jeecg;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
||||||
|
|
||||||
@EnableScheduling
|
|
||||||
@EnableFeignClients(basePackages = {"org.jeecg"})
|
|
||||||
@SpringBootApplication(scanBasePackages = "org.jeecg")
|
|
||||||
public class JeecgCloudExampleApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(JeecgCloudExampleApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package org.jeecg.cloud.demo.test.service.impl;
|
|
||||||
|
|
||||||
import org.jeecg.cloud.demo.test.service.JeecgDemoService;
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class JeecgDemoServiceImpl implements JeecgDemoService {
|
|
||||||
@Override
|
|
||||||
public Result<String> getMessage(String name) {
|
|
||||||
return Result.OK("Hello" + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
server:
|
|
||||||
port: 7003
|
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
name: jeecg-cloud-example
|
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package org.jeecg.modules.cloud.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微服务单元测试常量定义
|
||||||
|
*/
|
||||||
|
public interface CloudConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微服务名【对应模块jeecg-boot-module-demo】
|
||||||
|
*/
|
||||||
|
public final static String SERVER_NAME_JEECGDEMO = "jeecg-demo";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQ测试队列名字
|
||||||
|
*/
|
||||||
|
public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order";
|
||||||
|
public final static String MQ_JEECG_PLACE_ORDER_TIME = "jeecg_place_order_time";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQ测试消息总线
|
||||||
|
*/
|
||||||
|
public final static String MQ_DEMO_BUS_EVENT = "demoBusEvent";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分布式锁lock key
|
||||||
|
*/
|
||||||
|
public final static String REDISSON_DEMO_LOCK_KEY1 = "demoLockKey1";
|
||||||
|
public final static String REDISSON_DEMO_LOCK_KEY2 = "demoLockKey2";
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,17 +1,18 @@
|
|||||||
package org.jeecg.cloud.demo.bus;
|
package org.jeecg.modules.cloud.ebus;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.boot.starter.rabbitmq.event.EventObj;
|
import org.jeecg.boot.starter.rabbitmq.event.EventObj;
|
||||||
import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler;
|
import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler;
|
||||||
import org.jeecg.common.base.BaseMap;
|
import org.jeecg.common.base.BaseMap;
|
||||||
|
import org.jeecg.modules.cloud.constant.CloudConstant;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息处理器【发布订阅】
|
* 消息处理器【发布订阅】
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component("demoBusEvent")
|
@Component(CloudConstant.MQ_DEMO_BUS_EVENT)
|
||||||
public class DemoBusEvent implements JeecgBusEventHandler {
|
public class DemoBusEvent implements JeecgBusEventHandler {
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package org.jeecg.modules.cloud.feign.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.base.BaseMap;
|
||||||
|
import org.jeecg.modules.cloud.constant.CloudConstant;
|
||||||
|
import org.jeecg.modules.cloud.feign.feign.JeecgTestClient;
|
||||||
|
import org.jeecg.modules.cloud.feign.feign.JeecgTestClientDyn;
|
||||||
|
import org.jeecg.starter.cloud.feign.impl.JeecgFeignService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sys/test")
|
||||||
|
@Api(tags = "【微服务】单元测试")
|
||||||
|
public class JeecgTestFeignController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JeecgFeignService jeecgFeignService;
|
||||||
|
@Autowired
|
||||||
|
private JeecgTestClient jeecgTestClient;
|
||||||
|
@Autowired
|
||||||
|
private RabbitMqClient rabbitMqClient;
|
||||||
|
|
||||||
|
@GetMapping("getMessage")
|
||||||
|
@ApiOperation(value = "测试feign", notes = "测试feign")
|
||||||
|
public Result<String> getMessage() {
|
||||||
|
return jeecgTestClient.getMessage("jeecg-boot");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("getMessage2")
|
||||||
|
@ApiOperation(value = "测试动态feign", notes = "测试动态feign")
|
||||||
|
public Result<String> getMessage2() {
|
||||||
|
JeecgTestClientDyn myClientDyn = jeecgFeignService.newInstance(JeecgTestClientDyn.class, CloudConstant.SERVER_NAME_JEECGDEMO);
|
||||||
|
return myClientDyn.getMessage("动态fegin——jeecg-boot2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/rabbitmq")
|
||||||
|
@ApiOperation(value = "测试rabbitmq", notes = "测试rabbitmq")
|
||||||
|
public Result<?> rabbitMqClientTest(HttpServletRequest req) {
|
||||||
|
//rabbitmq消息队列测试
|
||||||
|
BaseMap map = new BaseMap();
|
||||||
|
map.put("orderId", RandomUtil.randomNumbers(10));
|
||||||
|
rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map);
|
||||||
|
rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER_TIME, map,10);
|
||||||
|
|
||||||
|
//rabbitmq消息总线测试
|
||||||
|
BaseMap params = new BaseMap();
|
||||||
|
params.put("orderId", "123456");
|
||||||
|
rabbitMqClient.publishEvent(CloudConstant.MQ_DEMO_BUS_EVENT, params);
|
||||||
|
return Result.OK("MQ发送消息成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,39 +0,0 @@
|
|||||||
package org.jeecg.modules.cloud.feign.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
|
||||||
import org.jeecg.modules.cloud.feign.feign.JeecgTestClient;
|
|
||||||
import org.jeecg.modules.cloud.feign.feign.JeecgTestClient2;
|
|
||||||
import org.jeecg.starter.cloud.feign.impl.JeecgFeignService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/sys/test")
|
|
||||||
@Api(tags = "feign测试")
|
|
||||||
public class JeecgTestFeignTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JeecgFeignService jeecgFeignService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JeecgTestClient jeecgTestClient;
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("getMessage")
|
|
||||||
@ApiOperation(value = "测试feign", notes = "测试feign")
|
|
||||||
public Result<String> getMessage() {
|
|
||||||
return jeecgTestClient.getMessage("jeecg-boot");
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("getMessage2")
|
|
||||||
@ApiOperation(value = "测试动态feign", notes = "测试动态feign")
|
|
||||||
public Result<String> getMessage2() {
|
|
||||||
JeecgTestClient2 jeecgTestClient = jeecgFeignService.newInstance(JeecgTestClient2.class, "jeecg-demo");
|
|
||||||
return jeecgTestClient.getMessage("jeecg-boot2");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +1,14 @@
|
|||||||
package org.jeecg.modules.cloud.feign.feign;
|
package org.jeecg.modules.cloud.feign.feign.fallback;
|
||||||
|
|
||||||
import feign.hystrix.FallbackFactory;
|
import feign.hystrix.FallbackFactory;
|
||||||
|
import org.jeecg.modules.cloud.feign.feign.JeecgTestClient;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author qinfeng
|
* @author qinfeng
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class DemoFallback implements FallbackFactory<JeecgTestClient> {
|
public class JeecgTestClientFallback implements FallbackFactory<JeecgTestClient> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JeecgTestClient create(Throwable throwable) {
|
public JeecgTestClient create(Throwable throwable) {
|
||||||
@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
package org.jeecg.modules.cloud.xxljob;;
|
|
||||||
|
|
||||||
|
|
||||||
import com.xxl.job.core.biz.model.ReturnT;
|
|
||||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
||||||
import com.xxl.job.core.log.XxlJobLogger;
|
|
||||||
import com.xxl.job.core.util.ShardingUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* xxl-job定时任务测试
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class Demo2JobHandler {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简单任务
|
|
||||||
*
|
|
||||||
* @param params
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
|
|
||||||
@XxlJob(value = "demoJob2")
|
|
||||||
public ReturnT<String> demoJobHandler(String params) {
|
|
||||||
log.info("我是定时任务,我执行了...............................");
|
|
||||||
return ReturnT.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2、分片广播任务
|
|
||||||
*/
|
|
||||||
|
|
||||||
@XxlJob("shardingJobHandler3")
|
|
||||||
public ReturnT<String> shardingJobHandler(String param) throws Exception {
|
|
||||||
|
|
||||||
// 分片参数
|
|
||||||
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
|
|
||||||
XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal());
|
|
||||||
|
|
||||||
// 业务逻辑
|
|
||||||
for (int i = 0; i < shardingVO.getTotal(); i++) {
|
|
||||||
if (i == shardingVO.getIndex()) {
|
|
||||||
XxlJobLogger.log("第 {} 片, 命中分片开始处理", i);
|
|
||||||
} else {
|
|
||||||
XxlJobLogger.log("第 {} 片, 忽略", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ReturnT.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
Reference in new issue