DayPcDataTask.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //package me.zhengjie.modules.quartz.task;
  2. //
  3. //import com.alibaba.fastjson.JSON;
  4. //import com.alibaba.fastjson.JSONArray;
  5. //import com.rabbitmq.client.*;
  6. //import lombok.RequiredArgsConstructor;
  7. //import lombok.SneakyThrows;
  8. //import lombok.extern.slf4j.Slf4j;
  9. //import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
  10. //import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
  11. //import me.zhengjie.modules.dm.food.service.DmFoodService;
  12. //import me.zhengjie.utils.ConnectionUtil;
  13. //import org.springframework.amqp.rabbit.core.RabbitTemplate;
  14. //import org.springframework.beans.factory.annotation.Autowired;
  15. //import org.springframework.scheduling.annotation.Async;
  16. //import org.springframework.scheduling.annotation.Scheduled;
  17. //import org.springframework.stereotype.Component;
  18. //
  19. //import java.io.ByteArrayOutputStream;
  20. //import java.io.IOException;
  21. //import java.io.ObjectOutputStream;
  22. //import java.io.Serializable;
  23. //import java.sql.Timestamp;
  24. //import java.util.List;
  25. //import java.util.concurrent.TimeoutException;
  26. //
  27. //@Slf4j
  28. //@RequiredArgsConstructor
  29. //@Component
  30. //public class DayPcDataTask {
  31. // private final DmFoodService dmFoodService;
  32. // private final DmDayPcService dmDayPcService;
  33. // private static String isEable = "0";
  34. ////
  35. //// public void runSend1(){
  36. //// isEable = "1";
  37. //// }
  38. ////
  39. //// public void runSend2(){
  40. //// if(isEable!=null&&isEable=="1"){
  41. //// send();
  42. //// isEable = "0";
  43. //// }
  44. //// }
  45. ////
  46. //// public void runReceive1(){
  47. //// isEable = "1";
  48. //// }
  49. ////
  50. // @Scheduled(cron = "0 */5 * * * ?")
  51. // @Async("threadPoolTaskExecutor2")
  52. // public void runReceive2(){
  53. //// if(isEable!=null&&isEable=="1"){
  54. // receive();
  55. //// isEable = "0";
  56. //// }
  57. // }
  58. ////
  59. //// /**
  60. //// * 生产者
  61. //// */
  62. //// public void send(){
  63. //// //获取连接
  64. //// Connection connection = ConnectionUtil.getConnection();
  65. //// try {
  66. //// List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
  67. //// String userString = JSON.toJSONString(dmDayPc);
  68. //// Channel channel = connection.createChannel();
  69. //// String exchangeName = "schedule_consume";//交换机
  70. //// channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
  71. //// String queue1Name = "schedule_consume";//队列名称
  72. //// channel.queueDeclare(queue1Name, true, false, false, null);
  73. //// channel.queueBind(queue1Name, exchangeName, "schedule_consume");// 队列绑定hello路由
  74. //// channel.basicPublish(exchangeName, "schedule_consume", null, userString.getBytes());
  75. //// System.out.println("sned排菜:"+dmDayPc);
  76. //// channel.close();
  77. //// connection.close();
  78. //// } catch (IOException | TimeoutException e) {
  79. //// e.printStackTrace();
  80. //// }
  81. //// }
  82. ////
  83. // /**
  84. // * 消费者
  85. // */
  86. // public void receive(){
  87. // Connection connection = ConnectionUtil.getConnection();
  88. // try {
  89. // Channel channel = connection.createChannel();
  90. // //通过consumer来处理数据
  91. // Consumer consumer = new DefaultConsumer(channel){
  92. // @SneakyThrows
  93. // @Override
  94. // public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
  95. // //body就是从队列中获取的数据
  96. // String str = new String(body);
  97. // if (str==null){
  98. // System.out.println("erropc"+str);
  99. // System.out.println("erropc"+body);
  100. // }else {
  101. // System.out.println("sucesspc"+str);
  102. // System.out.println("sucesspc"+body);
  103. // }
  104. // System.out.println("dingshipc"+str);
  105. // List<DmDayPc> list = JSONArray.parseArray(str,DmDayPc.class);
  106. // for (DmDayPc dmDayPc : list) {
  107. // dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
  108. // dmDayPcService.create(dmDayPc);
  109. // System.out.println("新增food==="+dmDayPc.getFood());
  110. // dmFoodService.create(dmDayPc.getFood());
  111. // }
  112. // }
  113. // };
  114. // //参数1:接收哪个队列的数据
  115. // //参数2:消息确认 是否应答,收到消息是否回复
  116. // //参数3:
  117. // channel.basicConsume("schedule_produce",true,consumer);
  118. // } catch (IOException e) {
  119. // e.printStackTrace();
  120. // }
  121. // }
  122. //}