|
|
@ -1,14 +1,20 @@
|
|
|
|
package cn.estsh.i3plus.core.apiservice.controller;
|
|
|
|
package cn.estsh.i3plus.core.apiservice.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysRoleService;
|
|
|
|
import cn.estsh.i3plus.core.apiservice.mq.I3CoreQueueConfig;
|
|
|
|
import cn.estsh.i3plus.core.apiservice.mq.I3CoreQueueConfig;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.thread.CoreDemoThread;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.QueueConstWords;
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysRole;
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.thread.ImppThreadPool;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
@ -18,7 +24,9 @@ import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
@ -27,7 +35,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -39,7 +49,7 @@ import java.util.concurrent.TimeoutException;
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Api(description="复杂对象服务demo")
|
|
|
|
@Api(description="复杂对象服务demo")
|
|
|
|
@RequestMapping(PlatformConstWords.BASE_URL + "/demo")
|
|
|
|
@RequestMapping("/demo-redis-mq")
|
|
|
|
public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DemoRedisMqController.class);
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DemoRedisMqController.class);
|
|
|
|
|
|
|
|
|
|
|
@ -57,12 +67,36 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ISysRoleService sysRoleService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RabbitListenerEndpointRegistry rabbitRegistry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ConnectionFactory connectionFactory;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* mq工厂,用于生产ack消息
|
|
|
|
* mq工厂,用于生产ack消息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private CachingConnectionFactory mqFactory;
|
|
|
|
private CachingConnectionFactory mqFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/get-mq-info")
|
|
|
|
|
|
|
|
@ApiOperation(value="获取队列信息")
|
|
|
|
|
|
|
|
public ResultBean getMqInfo(){
|
|
|
|
|
|
|
|
System.out.println(rabbitRegistry.isAutoStartup() + " " + rabbitRegistry.isRunning());
|
|
|
|
|
|
|
|
System.out.println(mqFactory.isPublisherConfirms() + " " + mqFactory.isPublisherReturns());
|
|
|
|
|
|
|
|
System.out.println(connectionFactory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<String> ids = rabbitRegistry.getListenerContainerIds();
|
|
|
|
|
|
|
|
for(String id : ids){
|
|
|
|
|
|
|
|
System.out.println("id = "+id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/put-cache")
|
|
|
|
@GetMapping(value="/put-cache")
|
|
|
|
@ApiOperation(value="缓存",notes="放入数据")
|
|
|
|
@ApiOperation(value="缓存",notes="放入数据")
|
|
|
|
public ResultBean putCache(){
|
|
|
|
public ResultBean putCache(){
|
|
|
@ -76,13 +110,82 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
@GetMapping(value="/get-cache")
|
|
|
|
@GetMapping(value="/get-cache")
|
|
|
|
@ApiOperation(value="缓存",notes="获取数据")
|
|
|
|
@ApiOperation(value="缓存",notes="获取数据")
|
|
|
|
public ResultBean getCache(){
|
|
|
|
public ResultBean getCache(){
|
|
|
|
//MachineFactory mf = (MachineFactory) redisCore.getObject("machineFactory");
|
|
|
|
|
|
|
|
//System.out.println("1===== " + mf);
|
|
|
|
|
|
|
|
System.out.println("2===== " + redisCore.getObject("wms"));
|
|
|
|
System.out.println("2===== " + redisCore.getObject("wms"));
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true);
|
|
|
|
return new ResultBean(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/exception-demo")
|
|
|
|
|
|
|
|
@ApiOperation(value="异常demo",notes="异常demo")
|
|
|
|
|
|
|
|
public ResultBean exceptionDemp() throws IOException, TimeoutException {
|
|
|
|
|
|
|
|
String data = "true";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if("true".equals(data)) {
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.WMS.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
|
|
|
|
|
|
|
|
.setErrorDetail("aaa操作数据出错")
|
|
|
|
|
|
|
|
.setErrorSolution("检查数据完整性")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/international")
|
|
|
|
|
|
|
|
@ApiOperation(value="国际化处理",notes="资源配置文件及国际化")
|
|
|
|
|
|
|
|
public ResultBean international() {
|
|
|
|
|
|
|
|
Locale locale = LocaleContextHolder.getLocale();
|
|
|
|
|
|
|
|
System.out.println(locale.getLanguage() + " " + locale.getCountry());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功 : " + locale.getLanguage() + " " + locale.getCountry());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource(name="redisSession")
|
|
|
|
|
|
|
|
private ImppRedis redisSession;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/set-redis")
|
|
|
|
|
|
|
|
@ApiOperation(value="setredis")
|
|
|
|
|
|
|
|
public ResultBean setRedis(String key,String value) {
|
|
|
|
|
|
|
|
//redisSession.putObject(key,value);
|
|
|
|
|
|
|
|
//redisCore.putObject(key,value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResultBean rs = new ResultBean(true,"yes");
|
|
|
|
|
|
|
|
rs.setPager(new Pager(100));
|
|
|
|
|
|
|
|
redisSession.putObject("rs",rs);
|
|
|
|
|
|
|
|
redisCore.putObject("rs",rs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功 : " + key + " : " + value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/get-redis")
|
|
|
|
|
|
|
|
@ApiOperation(value="getredis")
|
|
|
|
|
|
|
|
public ResultBean getRedis(String key) {
|
|
|
|
|
|
|
|
Object d1 = redisSession.getObject(key);
|
|
|
|
|
|
|
|
System.out.println("redisSession-d1==" + d1);
|
|
|
|
|
|
|
|
Object d2 = redisCore.getObject(key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(d1 != null) {
|
|
|
|
|
|
|
|
SessionUser sessionUser = AuthUtil.getSessionUser();
|
|
|
|
|
|
|
|
System.out.println(sessionUser.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("redisCore-d2==" + d2);
|
|
|
|
|
|
|
|
System.out.println(d1 == null?"null":d1.toString());
|
|
|
|
|
|
|
|
System.out.println(d2 == null?"null":d2.toString());
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功 : " + d1 + " : " + d2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/test-thread")
|
|
|
|
|
|
|
|
@ApiOperation(value="testThread")
|
|
|
|
|
|
|
|
public ResultBean testThread(String param) {
|
|
|
|
|
|
|
|
ImppThreadPool.getThreadExcutorService().execute(new CoreDemoThread(param));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/send-mq")
|
|
|
|
@GetMapping(value="/send-mq")
|
|
|
|
@ApiOperation(value="队列",notes="发送")
|
|
|
|
@ApiOperation(value="队列",notes="发送")
|
|
|
|
public ResultBean sendMQ(String data){
|
|
|
|
public ResultBean sendMQ(String data){
|
|
|
@ -156,7 +259,6 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 如果需要进行ack操作,需要添加RabbitListener方法
|
|
|
|
* 如果需要进行ack操作,需要添加RabbitListener方法
|
|
|
|
* @param data
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
* @throws IOException
|
|
|
|
* @throws IOException
|
|
|
|
* @throws TimeoutException
|
|
|
|
* @throws TimeoutException
|
|
|
@ -174,12 +276,12 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
@ApiOperation(value="getack队列",notes="接收")
|
|
|
|
@ApiOperation(value="getack队列",notes="接收")
|
|
|
|
public ResultBean getAckMQ() throws IOException, TimeoutException {
|
|
|
|
public ResultBean getAckMQ() throws IOException, TimeoutException {
|
|
|
|
Channel channel = this.rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
|
|
|
|
Channel channel = this.rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
|
|
|
|
System.out.println("1====" + channel);
|
|
|
|
LOGGER.info("channel = {}",channel);
|
|
|
|
String str = (String) rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
String str = (String) rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
System.out.println("2=============="+str);
|
|
|
|
LOGGER.info("str = {}",str);
|
|
|
|
|
|
|
|
|
|
|
|
Message message = rabbitTemplate.receive(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
Message message = rabbitTemplate.receive(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
System.out.println("3=============="+message);
|
|
|
|
LOGGER.info("message = {}",message);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
/*String data = (String) this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
/*String data = (String) this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
System.out.println("【client】数据接收成功:" + data);
|
|
|
|
System.out.println("【client】数据接收成功:" + data);
|
|
|
@ -213,64 +315,42 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/exception-demo")
|
|
|
|
/**
|
|
|
|
@ApiOperation(value="异常demo",notes="异常demo")
|
|
|
|
* 发送角色至mq交换机
|
|
|
|
public ResultBean exceptionDemp() throws IOException, TimeoutException {
|
|
|
|
* @return
|
|
|
|
String data = "true";
|
|
|
|
* @throws IOException
|
|
|
|
|
|
|
|
* @throws TimeoutException
|
|
|
|
if("true".equals(data)) {
|
|
|
|
*/
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
@GetMapping(value="/send-mq-role")
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.WMS.getCode())
|
|
|
|
@ApiOperation(value="发送角色信息队列",notes="发送")
|
|
|
|
.setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
|
|
|
|
public ResultBean sendRoleMQ(int sendCount) throws IOException, TimeoutException {
|
|
|
|
.setErrorDetail("aaa操作数据出错")
|
|
|
|
List<SysRole> roleList = sysRoleService.findSysRoleAll();
|
|
|
|
.setErrorSolution("检查数据完整性")
|
|
|
|
LOGGER.info("共有角色数:{}",roleList.size());
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
//发送信息至通用交换机-》扇形交换
|
|
|
|
|
|
|
|
SysRole sysRole;
|
|
|
|
|
|
|
|
for(int i=0;i<sendCount;i++) {
|
|
|
|
|
|
|
|
sysRole = roleList.get(i);
|
|
|
|
|
|
|
|
LOGGER.info("{}次发送角色:{}",i,sysRole);
|
|
|
|
|
|
|
|
this.rabbitTemplate.convertAndSend(QueueConstWords.QUEUE_EXCHANGE_COMMON,"", sysRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/international")
|
|
|
|
|
|
|
|
@ApiOperation(value="国际化处理",notes="资源配置文件及国际化")
|
|
|
|
|
|
|
|
public ResultBean international() {
|
|
|
|
|
|
|
|
Locale locale = LocaleContextHolder.getLocale();
|
|
|
|
|
|
|
|
System.out.println(locale.getLanguage() + " " + locale.getCountry());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功 : " + locale.getLanguage() + " " + locale.getCountry());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource(name="redisSession")
|
|
|
|
|
|
|
|
private ImppRedis redisSession;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/set-redis")
|
|
|
|
|
|
|
|
@ApiOperation(value="setredis")
|
|
|
|
|
|
|
|
public ResultBean setRedis(String key,String value) {
|
|
|
|
|
|
|
|
//redisSession.putObject(key,value);
|
|
|
|
|
|
|
|
//redisCore.putObject(key,value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResultBean rs = new ResultBean(true,"yes");
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
rs.setPager(new Pager(100));
|
|
|
|
|
|
|
|
redisSession.putObject("rs",rs);
|
|
|
|
|
|
|
|
redisCore.putObject("rs",rs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功 : " + key + " : " + value);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/get-redis")
|
|
|
|
|
|
|
|
@ApiOperation(value="getredis")
|
|
|
|
|
|
|
|
public ResultBean getRedis(String key) {
|
|
|
|
|
|
|
|
Object d1 = redisSession.getObject(key);
|
|
|
|
|
|
|
|
System.out.println("redisSession-d1==" + d1);
|
|
|
|
|
|
|
|
Object d2 = redisCore.getObject(key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(d1 != null) {
|
|
|
|
/**
|
|
|
|
SessionUser sessionUser = AuthUtil.getSessionUser();
|
|
|
|
* 发送角色至mq交换机(直达)
|
|
|
|
System.out.println(sessionUser.toString());
|
|
|
|
* @return
|
|
|
|
}
|
|
|
|
* @throws IOException
|
|
|
|
|
|
|
|
* @throws TimeoutException
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@GetMapping(value="/send-mq-role-direct")
|
|
|
|
|
|
|
|
@ApiOperation(value="发送角色信息队列",notes="发送")
|
|
|
|
|
|
|
|
public ResultBean sendRoleMQDirect(String routeKey) throws IOException, TimeoutException {
|
|
|
|
|
|
|
|
//通过routekey来控制接收的队列
|
|
|
|
|
|
|
|
this.rabbitTemplate.convertAndSend(QueueConstWords.QUEUE_EXCHANGE_DIRECT,routeKey, "发送信息=key:" + routeKey);
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("redisCore-d2==" + d2);
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
System.out.println(d1 == null?"null":d1.toString());
|
|
|
|
|
|
|
|
System.out.println(d2 == null?"null":d2.toString());
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功 : " + d1 + " : " + d2);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|