主键生成策略调整,日志部分调整

yun-zuoyi
alwaysfrin 6 years ago
parent 73629bfd1f
commit 588e2050b3

@ -16,9 +16,10 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
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;
@ -28,6 +29,7 @@ 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.Locale; import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
/** /**
@ -39,7 +41,7 @@ import java.util.concurrent.TimeoutException;
**/ **/
@RestController @RestController
@Api(description="复杂对象服务demo") @Api(description="复杂对象服务demo")
@RequestMapping(PlatformConstWords.BASE_URL + "/demo") @RequestMapping(PlatformConstWords.BASE_URL + "/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 +59,33 @@ public class DemoRedisMqController extends CoreBaseController{
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@Autowired
private RabbitListenerEndpointRegistry rabbitRegistry;
@Autowired
private ConnectionFactory connectionFactory;
/** /**
* mqack * mqack
*/ */
@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(){
@ -83,7 +106,7 @@ public class DemoRedisMqController extends CoreBaseController{
return new ResultBean(true); 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){
String context = "hello : " + data; String context = "hello : " + data;
@ -98,9 +121,9 @@ public class DemoRedisMqController extends CoreBaseController{
//this.rabbitTemplate.convertAndSend(I3CoreQueueConfig.DEMO_OBJ_QUEUE, new MachineFactory("111mq","rabbit")); //this.rabbitTemplate.convertAndSend(I3CoreQueueConfig.DEMO_OBJ_QUEUE, new MachineFactory("111mq","rabbit"));
return new ResultBean(true,"操作成功"); return new ResultBean(true,"操作成功");
} }*/
@GetMapping(value="/get-mq-handle") /*@GetMapping(value="/get-mq-handle")
@ApiOperation(value="手动获取队列",notes="接收队列") @ApiOperation(value="手动获取队列",notes="接收队列")
public ResultBean getHandleMQ(){ public ResultBean getHandleMQ(){
Object data = this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_HANDLE_QUEUE); Object data = this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_HANDLE_QUEUE);
@ -119,7 +142,7 @@ public class DemoRedisMqController extends CoreBaseController{
} }
return new ResultBean(true,""); return new ResultBean(true,"");
} }*/
/** /**
* *
@ -129,7 +152,7 @@ public class DemoRedisMqController extends CoreBaseController{
* @throws IOException * @throws IOException
* @throws TimeoutException * @throws TimeoutException
*/ */
@GetMapping(value="/send-returnmsg") /*@GetMapping(value="/send-returnmsg")
@ApiOperation(value="队列返回信息",notes="发送") @ApiOperation(value="队列返回信息",notes="发送")
public ResultBean sendReturnMQ(int type,String data) throws IOException, TimeoutException { public ResultBean sendReturnMQ(int type,String data) throws IOException, TimeoutException {
if(type == 1) { if(type == 1) {
@ -152,16 +175,15 @@ public class DemoRedisMqController extends CoreBaseController{
String returnMsg = (String) rabbitTemplate.convertSendAndReceive(I3CoreQueueConfig.DEMO_RETURN_QUEUE, data); String returnMsg = (String) rabbitTemplate.convertSendAndReceive(I3CoreQueueConfig.DEMO_RETURN_QUEUE, data);
System.out.println("===返回数据==="+returnMsg); System.out.println("===返回数据==="+returnMsg);
return new ResultBean(true,"操作成功"); return new ResultBean(true,"操作成功");
} }*/
/** /**
* ackRabbitListener * ackRabbitListener
* @param data
* @return * @return
* @throws IOException * @throws IOException
* @throws TimeoutException * @throws TimeoutException
*/ */
@GetMapping(value="/send-ackmsg") /*@GetMapping(value="/send-ackmsg")
@ApiOperation(value="ack队列",notes="发送") @ApiOperation(value="ack队列",notes="发送")
public ResultBean sendAckMQ(String data) throws IOException, TimeoutException { public ResultBean sendAckMQ(String data) throws IOException, TimeoutException {
System.out.println("发送ack数据 : " + data); System.out.println("发送ack数据 : " + data);
@ -181,13 +203,13 @@ public class DemoRedisMqController extends CoreBaseController{
Message message = rabbitTemplate.receive(I3CoreQueueConfig.DEMO_ACK_QUEUE); Message message = rabbitTemplate.receive(I3CoreQueueConfig.DEMO_ACK_QUEUE);
System.out.println("3=============="+message); System.out.println("3=============="+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);
if("ack".equals(data)){ if("ack".equals(data)){
System.out.println("【client】数据抛出异常"); System.out.println("【client】数据抛出异常");
throw new RuntimeException("【队列抛出异常】" + data); throw new RuntimeException("【队列抛出异常】" + data);
}*/ }*//*
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);
@ -211,7 +233,7 @@ public class DemoRedisMqController extends CoreBaseController{
} }
} }
return new ResultBean(true,"操作成功"); return new ResultBean(true,"操作成功");
} }*/
@GetMapping(value="/exception-demo") @GetMapping(value="/exception-demo")
@ApiOperation(value="异常demo",notes="异常demo") @ApiOperation(value="异常demo",notes="异常demo")

@ -29,7 +29,7 @@ public class I3CoreQueueConfig {
/*********** 队列demo ***********/ /*********** 队列demo ***********/
public static final String DEMO_STR_QUEUE = "demo_str_queue"; /*public static final String DEMO_STR_QUEUE = "demo_str_queue";
@Bean @Bean
public Queue getStrQueue() { public Queue getStrQueue() {
//LOGGER.info("【DEMO_STR_QUEUE队列】"); //LOGGER.info("【DEMO_STR_QUEUE队列】");
@ -62,5 +62,5 @@ public class I3CoreQueueConfig {
public Queue getReturnQueue() throws Exception { public Queue getReturnQueue() throws Exception {
//LOGGER.info("【DEMO_RETURN_QUEUE队列】"); //LOGGER.info("【DEMO_RETURN_QUEUE队列】");
return new Queue(DEMO_RETURN_QUEUE); return new Queue(DEMO_RETURN_QUEUE);
} }*/
} }

@ -59,7 +59,7 @@ public class I3CoreQueueReceiver {
System.out.println("强转对象:" + data); System.out.println("强转对象:" + data);
}*/ }*/
@RabbitListener(queues = I3CoreQueueConfig.DEMO_RETURN_QUEUE) /*@RabbitListener(queues = I3CoreQueueConfig.DEMO_RETURN_QUEUE)
public Message processReturn(String data, Channel channel, Message message) { public Message processReturn(String data, Channel channel, Message message) {
try { try {
System.out.println("【client】数据接收成功" + data); System.out.println("【client】数据接收成功" + data);
@ -96,10 +96,10 @@ public class I3CoreQueueReceiver {
try { try {
System.out.println("【client】数据接收成功" + data); System.out.println("【client】数据接收成功" + data);
/*if(data.startsWith("ack")){ *//*if(data.startsWith("ack")){
System.out.println("【client】数据抛出异常"); System.out.println("【client】数据抛出异常");
throw new RuntimeException("【队列抛出异常】" + data); throw new RuntimeException("【队列抛出异常】" + data);
}*/ }*//*
//在队列删掉 不会再发了 否则消息服务器以为这条消息没处理掉 后续还会在发 //在队列删掉 不会再发了 否则消息服务器以为这条消息没处理掉 后续还会在发
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
} catch (IOException e) { } catch (IOException e) {
@ -114,5 +114,5 @@ public class I3CoreQueueReceiver {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
} }*/
} }

@ -22,7 +22,6 @@ public class DataSimpleServiceImpl implements IDataSimpleService {
@Override @Override
public void saveMachineFactory(MachineFactory machineFactory) { public void saveMachineFactory(MachineFactory machineFactory) {
//生成主键 //生成主键
machineFactory.setId(new SnowflakeIdMaker().nextId());
machineFactoryDao.save(machineFactory); machineFactoryDao.save(machineFactory);
}*/ }*/
/* /*

Loading…
Cancel
Save