Nacos服务地址配置,默认用host jeecg-boot-nacos

默认注释掉mq测试示例代码,减少入门难度
pull/3525/head
zhangdaiscott 2022-02-25 22:19:41 +08:00
parent 758c347eb0
commit 51c63e8057
9 changed files with 210 additions and 221 deletions

View File

@ -30,11 +30,11 @@
<artifactId>jeecg-boot-module-system</artifactId>
</dependency>
<!--rabbitmq消息队列-->
<!--rabbitmq消息队列
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-boot-starter-rabbitmq</artifactId>
</dependency>
</dependency>-->
<!--xxl-job定时任务-->
<dependency>
<groupId>org.jeecgframework.boot</groupId>

View File

@ -1,27 +1,27 @@
package org.jeecg.modules.cloud.ebus;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.rabbitmq.event.EventObj;
import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.cloud.constant.CloudConstant;
import org.springframework.stereotype.Component;
/**
*
*/
@Slf4j
@Component(CloudConstant.MQ_DEMO_BUS_EVENT)
public class DemoBusEvent implements JeecgBusEventHandler {
@Override
public void onMessage(EventObj obj) {
if (ObjectUtil.isNotEmpty(obj)) {
BaseMap baseMap = obj.getBaseMap();
String orderId = baseMap.get("orderId");
log.info("业务处理----订单ID:" + orderId);
}
}
}
//package org.jeecg.modules.cloud.ebus;
//
//import cn.hutool.core.util.ObjectUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.boot.starter.rabbitmq.event.EventObj;
//import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler;
//import org.jeecg.common.base.BaseMap;
//import org.jeecg.modules.cloud.constant.CloudConstant;
//import org.springframework.stereotype.Component;
//
///**
// * 消息处理器【发布订阅】
// */
//@Slf4j
//@Component(CloudConstant.MQ_DEMO_BUS_EVENT)
//public class DemoBusEvent implements JeecgBusEventHandler {
//
//
// @Override
// public void onMessage(EventObj obj) {
// if (ObjectUtil.isNotEmpty(obj)) {
// BaseMap baseMap = obj.getBaseMap();
// String orderId = baseMap.get("orderId");
// log.info("业务处理----订单ID:" + orderId);
// }
// }
//}

View File

@ -1,12 +1,9 @@
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;
@ -16,8 +13,6 @@ 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 = "【微服务】单元测试")
@ -27,8 +22,8 @@ public class JeecgTestFeignController {
private JeecgFeignService jeecgFeignService;
@Autowired
private JeecgTestClient jeecgTestClient;
@Autowired
private RabbitMqClient rabbitMqClient;
// @Autowired
// private RabbitMqClient rabbitMqClient;
@GetMapping("getMessage")
@ApiOperation(value = "测试feign", notes = "测试feign")
@ -43,19 +38,19 @@ public class JeecgTestFeignController {
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发送消息成功");
}
// @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发送消息成功");
// }
}

View File

@ -1,17 +1,11 @@
package org.jeecg.modules.cloud.lock;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.lock.annotation.JLock;
import org.jeecg.boot.starter.lock.client.RedissonLockClient;
import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.cloud.constant.CloudConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* demo
*/
@ -20,26 +14,26 @@ import java.util.Map;
public class DemoLockTest {
@Autowired
RedissonLockClient redissonLock;
@Autowired
RabbitMqClient rabbitMqClient;
// @Autowired
// RabbitMqClient rabbitMqClient;
/**
*
*/
@Scheduled(cron = "0/5 * * * * ?")
@JLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1)
public void execute() throws InterruptedException {
log.info("执行execute任务开始休眠三秒");
Thread.sleep(3000);
System.out.println("=======================业务逻辑1=============================");
Map map = new BaseMap();
map.put("orderId", "BJ0001");
rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map);
//延迟10秒发送
map.put("orderId", "NJ0002");
rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map, 10000);
log.info("execute任务结束休眠三秒");
}
// /**
// * 测试分布式锁【注解方式】
// */
// @Scheduled(cron = "0/5 * * * * ?")
// @JLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1)
// public void execute() throws InterruptedException {
// log.info("执行execute任务开始休眠三秒");
// Thread.sleep(3000);
// System.out.println("=======================业务逻辑1=============================");
// Map map = new BaseMap();
// map.put("orderId", "BJ0001");
// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map);
// //延迟10秒发送
// map.put("orderId", "NJ0002");
// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map, 10000);
// log.info("execute任务结束休眠三秒");
// }
public DemoLockTest() {
}

View File

@ -1,36 +1,36 @@
package org.jeecg.modules.cloud.rabbitmq;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
import org.jeecg.common.annotation.RabbitComponent;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.cloud.constant.CloudConstant;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
/**
* RabbitMq1
* @RabbitListener
*/
@Slf4j
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)
@RabbitComponent(value = "helloReceiver1")
public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> {
@RabbitHandler
public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
@Override
public void handler(BaseMap map, Channel channel) {
//业务处理
String orderId = map.get("orderId").toString();
log.info("MQ Receiver1orderId : " + orderId);
}
});
}
}
//package org.jeecg.modules.cloud.rabbitmq;
//
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
//import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
//import org.jeecg.common.annotation.RabbitComponent;
//import org.jeecg.common.base.BaseMap;
//import org.jeecg.modules.cloud.constant.CloudConstant;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//
///**
// * RabbitMq接受者1
// * @RabbitListener声明类上一个类只能监听一个队列
// */
//@Slf4j
//@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)
//@RabbitComponent(value = "helloReceiver1")
//public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> {
//
// @RabbitHandler
// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
// @Override
// public void handler(BaseMap map, Channel channel) {
// //业务处理
// String orderId = map.get("orderId").toString();
// log.info("MQ Receiver1orderId : " + orderId);
// }
// });
// }
//
//}

View File

@ -1,36 +1,36 @@
package org.jeecg.modules.cloud.rabbitmq;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
import org.jeecg.common.annotation.RabbitComponent;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.cloud.constant.CloudConstant;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
/**
* RabbitMq2
* @RabbitListener
*/
@Slf4j
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)
@RabbitComponent(value = "helloReceiver2")
public class HelloReceiver2 extends BaseRabbiMqHandler<BaseMap> {
@RabbitHandler
public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
@Override
public void handler(BaseMap map, Channel channel) {
//业务处理
String orderId = map.get("orderId").toString();
log.info("MQ Receiver2orderId : " + orderId);
}
});
}
}
//package org.jeecg.modules.cloud.rabbitmq;
//
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
//import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
//import org.jeecg.common.annotation.RabbitComponent;
//import org.jeecg.common.base.BaseMap;
//import org.jeecg.modules.cloud.constant.CloudConstant;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//
///**
// * RabbitMq接受者2
// * @RabbitListener声明类上一个类只能监听一个队列
// */
//@Slf4j
//@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)
//@RabbitComponent(value = "helloReceiver2")
//public class HelloReceiver2 extends BaseRabbiMqHandler<BaseMap> {
//
// @RabbitHandler
// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
// @Override
// public void handler(BaseMap map, Channel channel) {
// //业务处理
// String orderId = map.get("orderId").toString();
// log.info("MQ Receiver2orderId : " + orderId);
// }
// });
// }
//
//}

View File

@ -1,35 +1,35 @@
package org.jeecg.modules.cloud.rabbitmq;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
import org.jeecg.common.annotation.RabbitComponent;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.cloud.constant.CloudConstant;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
/**
* RabbitMq3
* @RabbitListener
*/
@Slf4j
@RabbitComponent(value = "helloReceiver3")
public class HelloReceiver3 extends BaseRabbiMqHandler<BaseMap> {
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)
public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
@Override
public void handler(BaseMap map, Channel channel) {
//业务处理
String orderId = map.get("orderId").toString();
log.info("MQ Receiver3orderId : " + orderId);
}
});
}
}
//package org.jeecg.modules.cloud.rabbitmq;
//
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
//import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
//import org.jeecg.common.annotation.RabbitComponent;
//import org.jeecg.common.base.BaseMap;
//import org.jeecg.modules.cloud.constant.CloudConstant;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//
///**
// * RabbitMq接受者3
// * @RabbitListener声明类方法上一个类可以多监听多个队列
// */
//@Slf4j
//@RabbitComponent(value = "helloReceiver3")
//public class HelloReceiver3 extends BaseRabbiMqHandler<BaseMap> {
//
// @RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)
// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
// @Override
// public void handler(BaseMap map, Channel channel) {
// //业务处理
// String orderId = map.get("orderId").toString();
// log.info("MQ Receiver3orderId : " + orderId);
// }
// });
// }
//
//}

View File

@ -1,32 +1,32 @@
package org.jeecg.modules.cloud.rabbitmq;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
import org.jeecg.common.annotation.RabbitComponent;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.cloud.constant.CloudConstant;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
@Slf4j
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER_TIME)
@RabbitComponent(value = "helloTimeReceiver")
public class HelloTimeReceiver extends BaseRabbiMqHandler<BaseMap> {
@RabbitHandler
public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
@Override
public void handler(BaseMap map, Channel channel) {
//业务处理
String orderId = map.get("orderId").toString();
log.info("Time Receiver1orderId : " + orderId);
}
});
}
}
//package org.jeecg.modules.cloud.rabbitmq;
//
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
//import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
//import org.jeecg.common.annotation.RabbitComponent;
//import org.jeecg.common.base.BaseMap;
//import org.jeecg.modules.cloud.constant.CloudConstant;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//
//@Slf4j
//@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER_TIME)
//@RabbitComponent(value = "helloTimeReceiver")
//public class HelloTimeReceiver extends BaseRabbiMqHandler<BaseMap> {
//
// @RabbitHandler
// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
// @Override
// public void handler(BaseMap map, Channel channel) {
// //业务处理
// String orderId = map.get("orderId").toString();
// log.info("Time Receiver1orderId : " + orderId);
// }
// });
// }
//
//}

View File

@ -363,7 +363,7 @@
<!--配置文件前缀-->
<prefix.name>jeecg</prefix.name>
<!--Nacos配置中心地址-->
<config.server-addr>127.0.0.1:8848</config.server-addr>
<config.server-addr>jeecg-boot-nacos:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID不能使用名称,默认为空-->
<config.namespace></config.namespace>
<!--Nacos用户名-->
@ -373,7 +373,7 @@
<!--Nacos配置分组名称-->
<config.group>DEFAULT_GROUP</config.group>
<!--Nacos服务发现地址-->
<discovery.server-addr>127.0.0.1:8848</discovery.server-addr>
<discovery.server-addr>jeecg-boot-nacos:8848</discovery.server-addr>
</properties>
</profile>
<!-- 测试 -->
@ -385,7 +385,7 @@
<!--配置文件前缀-->
<prefix.name>jeecg</prefix.name>
<!--Nacos配置中心地址-->
<config.server-addr>127.0.0.1:8848</config.server-addr>
<config.server-addr>jeecg-boot-nacos:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID不能使用名称,默认为空-->
<config.namespace></config.namespace>
<!--Nacos用户名-->
@ -395,7 +395,7 @@
<!--Nacos配置分组名称-->
<config.group>DEFAULT_GROUP</config.group>
<!--Nacos服务发现地址-->
<discovery.server-addr>127.0.0.1:8848</discovery.server-addr>
<discovery.server-addr>jeecg-boot-nacos:8848</discovery.server-addr>
</properties>
</profile>
<!-- 生产 -->
@ -407,7 +407,7 @@
<!--配置文件前缀-->
<prefix.name>jeecg</prefix.name>
<!--Nacos配置中心地址-->
<config.server-addr>127.0.0.1:8848</config.server-addr>
<config.server-addr>jeecg-boot-nacos:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID不能使用名称,默认为空-->
<config.namespace></config.namespace>
<!--Nacos用户名-->
@ -417,7 +417,7 @@
<!--Nacos配置分组名称-->
<config.group>DEFAULT_GROUP</config.group>
<!--Nacos服务发现地址-->
<discovery.server-addr>127.0.0.1:8848</discovery.server-addr>
<discovery.server-addr>jeecg-boot-nacos:8848</discovery.server-addr>
</properties>
</profile>
</profiles>