| | |
| | | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.rabbitmq.client.Channel; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.web.task.PhoneTask; |
| | | import com.ruoyi.web.task.PhoneTask2; |
| | | import com.smartor.common.SendService; |
| | | import com.smartor.config.RabbitMqConfig; |
| | | import com.smartor.domain.IvrLibaTemplateVO; |
| | | import com.smartor.domain.IvrTask; |
| | | import com.smartor.domain.IvrTaskSingle; |
| | | import com.smartor.domain.IvrTaskcallMQ; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.config.RabbitMqCallPhoneConfig; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.IvrTaskMapper; |
| | | import com.smartor.mapper.IvrTaskSingleMapper; |
| | | import com.smartor.service.IIvrLibaTemplateService; |
| | |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; |
| | | import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
| | | import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.stereotype.Component; |
| | | import com.rabbitmq.client.Channel; |
| | | import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | |
| | | @Component//ç嬿¤éå |
| | | public class RabbitMqReceiver { |
| | | |
| | | |
| | | private static IIvrLibaTemplateService ivrLibaTemplateService; |
| | | |
| | | private static IvrTaskSingleMapper ivrTaskcallMapper; |
| | |
| | | private static SendService sendService; |
| | | |
| | | private static RedisCache redisCache; |
| | | |
| | | private static RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; |
| | | |
| | | // å建åºå®å¤§å°ççº¿ç¨æ± |
| | | private static final ExecutorService executorService = Executors.newFixedThreadPool(10); |
| | |
| | | @Autowired |
| | | public void setSendService(SendService sendService) { |
| | | RabbitMqReceiver.sendService = sendService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setRabbitMqCallPhoneConfig(RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig) { |
| | | RabbitMqReceiver.rabbitMqCallPhoneConfig = rabbitMqCallPhoneConfig; |
| | | } |
| | | |
| | | @Autowired |
| | |
| | | RabbitMqReceiver.redisCache = redisCache; |
| | | } |
| | | |
| | | // @RabbitListener(queues = RabbitMqConfig.delay_queue) |
| | | // public void consultReceiveDealy(String content, Message message, Channel channel) throws IOException { |
| | | // log.info("----------------æ¥æ¶å»¶è¿éåæ¶æ¯--------------------"); |
| | | // //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº |
| | | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| | | // try { |
| | | // log.info("=============Do Something=============="); |
| | | // } catch (Exception e) { |
| | | // log.error("============æ¶è´¹å¤±è´¥,å°è¯æ¶æ¯è¡¥å忬¡æ¶è´¹!=============="); |
| | | // log.error(e.getMessage()); |
| | | // /** |
| | | // * basicRecoveræ¹æ³æ¯è¿è¡è¡¥åæä½ï¼ |
| | | // * å
¶ä¸çåæ°å¦æä¸ºtrueæ¯ææ¶æ¯éåå°queue使¯æå¯è½è¢«å
¶å®çconsumer(é群)æ¥æ¶å°ï¼ |
| | | // * 设置为falseæ¯åªè¡¥åç»å½åçconsumer |
| | | // */ |
| | | // channel.basicRecover(false); |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * çµè¯é访 |
| | | * concurrency = "50" å¹¶åæ°ä¸º50 |
| | | */ |
| | | @RabbitListener(queues = RabbitMqConfig.phone_queue, concurrency = "50") |
| | | @RabbitListener(queues = "phone_queue", concurrency = "50") |
| | | public void phoneVisit(String content, Message message, Channel channel) throws IOException { |
| | | try { |
| | | IvrTaskcallMQ ivrTaskcallMQ = null; |
| | | |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | if (!content.contains("{")) { |
| | | ivrTaskcallMQ = mapper.readValue("{" + content + "}", IvrTaskcallMQ.class); |
| | | } else { |
| | | ivrTaskcallMQ = mapper.readValue(content, IvrTaskcallMQ.class); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | break; |
| | | } |
| | | // //éè¿å¤çº¿ç¨çæ¹å¼å»æçµè¯ |
| | | // executorService.submit(new PhoneTask(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, channel, message, sendService)); |
| | | new PhoneTask2().runPhone(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, channel, message, sendService); |
| | | executorService.submit(new PhoneTask(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, rabbitMqCallPhoneConfig, message, sendService)); |
| | | } |
| | | //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº ï¼è¿ä¸ªéè¦æ ¹æ®ä¸å¡åå»å¤çACKï¼ |
| | | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| | | |
| | | log.info("=============Do Something=============="); |
| | | } catch (Exception e) { |
| | | log.error("============æ¶è´¹å¤±è´¥,å°è¯æ¶æ¯è¡¥å忬¡æ¶è´¹!=============="); |
| | | log.error(e.getMessage()); |
| | | channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * basicRecoveræ¹æ³æ¯è¿è¡è¡¥åæä½ï¼ |
| | | * å
¶ä¸çåæ°å¦æä¸ºtrueæ¯ææ¶æ¯éåå°queue使¯æå¯è½è¢«å
¶å®çconsumer(é群)æ¥æ¶å°ï¼ |
| | | * 设置为falseæ¯åªè¡¥åç»å½åçconsumer |
| | | * æºå¨äººç¬¬ä¸å¥è¯è¯é³ |
| | | * concurrency = "50" å¹¶åæ°ä¸º50 |
| | | */ |
| | | channel.basicRecover(false); |
| | | @RabbitListener(queues = "ob_queue", concurrency = "50") |
| | | public void obVisit(String content, Message message, Channel channel) throws IOException { |
| | | try { |
| | | IvrTaskcallPhoneMQ ivrTaskcallMQ = null; |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | ivrTaskcallMQ = mapper.readValue(content, IvrTaskcallPhoneMQ.class); |
| | | //夿æ£è
æ¯å¦å·²ç»æ¥çµè¯ |
| | | String str = redisCache.getCacheObject(ivrTaskcallMQ.getUuid() + "state_id"); |
| | | System.out.println("-----------------" + str); |
| | | if (StringUtils.isNotEmpty(str) && str.equals("0")) { |
| | | //æ£è
å·²ç»æ¥å¬äºçµè¯ |
| | | new PhoneUtils().ttsPlayback(ivrTaskcallMQ.getScript(), ivrTaskcallMQ.getUuid()); |
| | | } else if (StringUtils.isNotEmpty(str) && str.equals("-10")) { |
| | | //è¿ä¸ªè¯´æ,å·²ç»æäºæå®éæ°è¿æ¯æ²¡æäººæ¥ï¼å¯ä»¥å°æ¶æ¯ä»éåä¸ç§»é¤äº |
| | | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| | | return; |
| | | } else { |
| | | //è¿è¡éåå°¾é¨ï¼è¿è¡ä¸ä¸æ¬¡æ ¡éª |
| | | // channel.basicRecover(false); |
| | | channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); |
| | | System.out.println("++++++++++++++++++++++" + str); |
| | | return; |
| | | } |
| | | //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº ï¼è¿ä¸ªéè¦æ ¹æ®ä¸å¡åå»å¤çACKï¼ |
| | | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| | | } catch (Exception e) { |
| | | log.error("============æ¶è´¹å¤±è´¥,å°è¯æ¶æ¯è¡¥å忬¡æ¶è´¹!=============="); |
| | | log.error(e.getMessage()); |
| | | channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); |
| | | } |
| | | } |
| | | |
| | |
| | | package com.ruoyi.web.controller.smartor; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.config.RabbitMqConfig; |
| | | import com.smartor.config.RabbitMqCallPhoneConfig; |
| | | import com.smartor.domain.IvrLibaTemplate; |
| | | import com.smartor.domain.IvrLibaTemplateVO; |
| | | import com.smartor.domain.Test1Vo; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.amqp.AmqpException; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.core.MessageBuilder; |
| | | import org.springframework.amqp.core.MessagePostProcessor; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * é访模æ¿åºController |
| | |
| | | @Autowired |
| | | private IIvrLibaTemplateService ivrLibaTemplateService; |
| | | |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | // @Autowired |
| | | // private RabbitTemplate rabbitTemplate; |
| | | |
| | | @Autowired |
| | | private PhoneUtils phoneUtils; |
| | | |
| | | @Autowired |
| | | private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; |
| | | |
| | | /** |
| | | * æ¥è¯¢æ¨¡æ¿åºå表 |
| | |
| | | @PostMapping("/queryRabbitmq") |
| | | public AjaxResult queryRabbitmq(@RequestBody Test1Vo test1Vo) { |
| | | |
| | | // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, "phone.001", "æµè¯æ°æ®001"); |
| | | // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, "phone.002", "æµè¯æ°æ®002"); |
| | | // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, "phone.003", "æµè¯æ°æ®003"); |
| | | // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, routintKey, message, new MessagePostProcessor() { |
| | | // @Override |
| | | // public Message postProcessMessage(Message message) throws AmqpException { |
| | | //// message.getMessageProperties().setDelay(times); |
| | | // message.getMessageProperties().getHeaders().put("x-delay", times); |
| | | ////message.getMessageProperties().setExpiration(); |
| | | // return message; |
| | | // } |
| | | // }); |
| | | |
| | | log.info("-------------å¯å¨å¨è¯¢åºçè¶
æ¶æéå»¶è¿éå-------------"); |
| | | String data = JSON.toJSONString(test1Vo.getTestVo()); |
| | | String substring = data.substring(1, data.length() - 1); |
| | | rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", substring, test1Vo.getTimes()); |
| | | |
| | | this.rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, substring, message -> { |
| | | //注æè¿éæ¶é´å¯ä»¥ä½¿longï¼è䏿¯è®¾ç½®header |
| | | message.getMessageProperties().setHeader("x-delay", test1Vo.getTimes()); |
| | | return message; |
| | | }); |
| | | log.info("-------------å»¶è¿éå{}msåæ§è¡.-------------", test1Vo.getTimes()); |
| | | return success(); |
| | | } |
| | | |
| | | @GetMapping("/tts") |
| | | public AjaxResult tts(@RequestParam("fileText") String fileText, @RequestParam("uuid") String uuid) { |
| | | new PhoneUtils().ttsPlayback(fileText, uuid); |
| | | return success(); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.web.task; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.rabbitmq.client.Channel; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.smartor.common.SendService; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.config.RabbitMqCallPhoneConfig; |
| | | import com.smartor.domain.*; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.data.convert.Jsr310Converters; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | private List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVO; |
| | | private RedisCache redisCache; |
| | | private IvrLibaTemplateVO ivrLibaTemplateVO; |
| | | private Channel channel; |
| | | private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; |
| | | private Message message; |
| | | private SendService sendService; |
| | | |
| | | |
| | | public PhoneTask(IvrTaskSingle ivrTaskSingle, IvrLibaTemplateVO ivrLibaTemplateVO, RedisCache redisCache, Channel channel, Message message, SendService sendService) { |
| | | public PhoneTask(IvrTaskSingle ivrTaskSingle, IvrLibaTemplateVO ivrLibaTemplateVO, RedisCache redisCache, RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig, Message message, SendService sendService) { |
| | | this.ivrTaskSingle = DtoConversionUtils.sourceToTarget(ivrTaskSingle, IvrTaskSingle.class); |
| | | this.ivrLibaTemplateScriptVO = DtoConversionUtils.sourceToTarget(ivrLibaTemplateVO.getIvrLibaTemplateScriptVOList(), IvrLibaTemplateScriptVO.class); |
| | | this.ivrLibaTemplateVO = DtoConversionUtils.sourceToTarget(ivrLibaTemplateVO, IvrLibaTemplateVO.class); |
| | | this.redisCache = redisCache; |
| | | this.channel = channel; |
| | | this.rabbitMqCallPhoneConfig = rabbitMqCallPhoneConfig; |
| | | this.message = message; |
| | | this.sendService = sendService; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | synchronized (PhoneTask.class) { |
| | | try { |
| | | //è·åçµè¯ç»ï¼æ¥çåªäºçµè¯å¯ä»¥ä½¿ç¨ |
| | | PhoneUtils phoneUtils = new PhoneUtils(); |
| | |
| | | |
| | | System.out.println("----------------uuID为 ï¼" + uuid + " " + ivrTaskSingle.getSendname() + " " + returnQues.getNowQuestion().getQuestionText() + " " + ivrTaskSingle.getPhone()); |
| | | |
| | | //è°ç¨æºå¨äººçµè¯ï¼å¼å§çµè¯ï¼éè¦å°åè°æ¹æ³ä¼ å
¥ï¼è¿ä¸ªçâçµè¯æ¹âåè¯æä¹ä¼ ï¼ç°å¨å
空ç,è¿æç¬¬ä¸å¥é®é¢è¯æ¯ï¼ |
| | | String ob = phoneUtils.ob("", "", "", "", "", "", "", ivrTaskSingle.getPhone(), uuid, true); |
| | | System.out.println("OBçå¼ä¸ºï¼" + ob); |
| | | //éäºä¹åï¼ç«é©¬å»è°å¼åºç½ |
| | | System.out.println("é®é¢çå¼ä¸ºï¼" + returnQues.getNowQuestion().getQuestionText() + " " + uuid); |
| | | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitBefore() + returnQues.getNowQuestion().getQuestionText(), uuid); |
| | | //å
å°è¯æ¯æ¾å°ob_queueéåä¸ |
| | | IvrTaskcallPhoneMQ ivrTaskcallPhoneMQ = new IvrTaskcallPhoneMQ(); |
| | | ivrTaskcallPhoneMQ.setScript(ivrLibaTemplateVO.getRevisitBefore() + returnQues.getNowQuestion().getQuestionText()); |
| | | ivrTaskcallPhoneMQ.setType("1"); |
| | | ivrTaskcallPhoneMQ.setUuid(uuid); |
| | | String data = JSON.toJSONString(ivrTaskcallPhoneMQ); |
| | | rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.ob1", data, 0L); |
| | | |
| | | // //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº ï¼è¿ä¸ªéè¦æ ¹æ®ä¸å¡åå»å¤çACKï¼ |
| | | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| | | //è°ç¨æºå¨äººçµè¯ï¼å¼å§çµè¯ |
| | | String ob = phoneUtils.ob("", "", "", "", "", "", "", ivrTaskSingle.getPhone(), uuid, true); |
| | | System.out.println("----------------uuID为 ï¼" + uuid + " " + ivrTaskSingle.getSendname() + " " + returnQues.getNowQuestion().getQuestionText() + " " + ivrTaskSingle.getPhone() + "----------å·²ç»æ¨æ"); |
| | | Map<String, String> obMap = objectMapper.readValue(ob, Map.class); |
| | | Thread.sleep(1000); |
| | | redisCache.setCacheObject(uuid + "state_id", "0", 10, TimeUnit.MINUTES); |
| | | //è¿éå
注éï¼state_id,çµè¯é£è¾¹ï¼åªè½è¿å6ï¼ä¸è½è¿å0ï¼è¿éè¦çµè¯é£è¾¹è¿è¡ä¿®æ¹ï¼é£è¾¹ä¿®æ¹ä¹åï¼ä¸é¢ä¸¤è¡å¯å é¤ï¼å°ä¸é¢çè§£å¼æ³¨é |
| | | // if (obMap.get("state_id").equals("0")) { |
| | | // // 说ææéäº |
| | | // redisCache.setCacheObject(uuid + "state_id", "0", 10, TimeUnit.MINUTES); |
| | | // } else { |
| | | // while (true) { |
| | | // Thread.sleep(2000); |
| | | // redisCache.setCacheObject(uuid + "state_id", "0", 10, TimeUnit.MINUTES); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | System.out.println("OBçå¼ä¸ºï¼" + ob); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | // 设å®åæ°ï¼å®¢æ·ç«¯çæ»è¿æ¥æ° |
| | | manager.getParams().setMaxTotalConnections(400); |
| | | // è®¾ç½®è¿æ¥è¶
æ¶æ¶é´,åä½ï¼æ¯«ç§ |
| | | manager.getParams().setConnectionTimeout(8000); |
| | | manager.getParams().setConnectionTimeout(30000); |
| | | // 设置请æ±è¯»åè¶
æ¶æ¶é´ï¼åä½ï¼æ¯«ç§ |
| | | manager.getParams().setSoTimeout(8000); |
| | | manager.getParams().setSoTimeout(30000); |
| | | // 设置ä»è¿æ¥æ± ä¸è·å龿¥æ¶é´ï¼ åä½ï¼æ¯«ç§ |
| | | manager.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 8000); |
| | | // 使ç¨è¿æ¥æ± ææ¯å建HttpClient对象 |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.config; |
| | | |
| | | import org.springframework.amqp.core.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class RabbitMqCallPhoneConfig { |
| | | |
| | | @Autowired |
| | | private AmqpAdmin amqpAdmin; |
| | | |
| | | @Autowired |
| | | private AmqpTemplate rabbitTemplate; |
| | | |
| | | /** |
| | | * åå»ºäº¤æ¢æº |
| | | * |
| | | * @param exchangeName äº¤æ¢æºåç§° |
| | | */ |
| | | public void createExchange(String exchangeName) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("x-delayed-type", "topic"); |
| | | CustomExchange exchange = new CustomExchange(exchangeName, "x-delayed-message", true, false, args); |
| | | amqpAdmin.declareExchange(exchange); |
| | | } |
| | | |
| | | /** |
| | | * å建éå |
| | | * |
| | | * @param queueName éååç§° |
| | | */ |
| | | public void createQueue(String queueName) { |
| | | Queue queue = new Queue(queueName, true, false, false); |
| | | amqpAdmin.declareQueue(queue); |
| | | } |
| | | |
| | | /** |
| | | * äº¤æ¢æºç»å® |
| | | * |
| | | * @param changeName äº¤æ¢æºåç§° |
| | | * @param routingKey è·¯ç±key |
| | | * @param queueName éååç§° |
| | | */ |
| | | public void bindExchange(String changeName, String routingKey, String queueName) { |
| | | Binding binding = new Binding(queueName, Binding.DestinationType.QUEUE, changeName, routingKey, null); |
| | | amqpAdmin.declareBinding(binding); |
| | | } |
| | | |
| | | /** |
| | | * åéä¿¡æ¯å°äº¤æ¢æº |
| | | * |
| | | * @param changeName äº¤æ¢æºåç§° |
| | | * @param routingKey è·¯ç±key |
| | | * @param data æ¶æ¯ |
| | | */ |
| | | public void sendMessage(String changeName, String routingKey, String data, Long times) { |
| | | |
| | | this.rabbitTemplate.convertAndSend(changeName, routingKey, data, message -> { |
| | | //注æè¿éæ¶é´å¯ä»¥ä½¿longï¼è䏿¯è®¾ç½®header |
| | | message.getMessageProperties().setHeader("x-delay", times); |
| | | return message; |
| | | }); |
| | | // rabbitTemplate.convertAndSend(changeName, routingKey, message); |
| | | } |
| | | |
| | | /** |
| | | * å é¤äº¤æ¢æº |
| | | * |
| | | * @param changeName äº¤æ¢æºåç§° |
| | | */ |
| | | public void deleteExchange(String changeName) { |
| | | amqpAdmin.deleteExchange(changeName); |
| | | } |
| | | |
| | | /** |
| | | * å é¤éå |
| | | * |
| | | * @param queueName éååç§° |
| | | */ |
| | | public void deleteQueue(String queueName) { |
| | | amqpAdmin.deleteQueue(queueName); |
| | | } |
| | | |
| | | /** |
| | | * å建MQ |
| | | * |
| | | * @param exchangName |
| | | * @param queueName |
| | | * @param routingKey |
| | | * @return |
| | | */ |
| | | public Boolean createRabbitMq(String exchangName, String queueName, String routingKey) { |
| | | this.createExchange(exchangName); |
| | | this.createQueue(queueName); |
| | | this.bindExchange(exchangName, routingKey, queueName); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * å
å°éè¦å建çéå建好 |
| | | */ |
| | | @Bean |
| | | public void createMq() { |
| | | createRabbitMq("phone_exchange", "ob_queue", "phone.ob1"); |
| | | createRabbitMq("phone_exchange", "phone_queue", "phone.123"); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.smartor.config; |
| | | |
| | | import org.springframework.amqp.core.*; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Configuration |
| | | public class RabbitMqConfig { |
| | | // public static final String EXCHANGE_NAME = "phone_topic_exchange2"; |
| | | // public static final String QUEUE_NAME = "phone_queue"; |
| | | //package com.smartor.config; |
| | | // |
| | | // /** |
| | | // * topicäº¤æ¢æº,å¹¶æä¹
å |
| | | // */ |
| | | // @Bean(EXCHANGE_NAME) |
| | | // public Exchange phoneExchange() { |
| | | // Map<String, Object> arguments = new HashMap<>(); |
| | | // //æå®éä¿¡æ¹å¼ä¸ºtopic |
| | | // arguments.put("x-delayed-type", "topic"); |
| | | // //使ç¨CustomExchangeç±»å建ï¼ç±»åè¦æå®ä¸ºâx-delayed-messageâç±»å |
| | | // Exchange exchange = new CustomExchange(EXCHANGE_NAME, "x-delayed-message", true, false, arguments); |
| | | // return exchange; |
| | | //import org.springframework.amqp.core.*; |
| | | //import org.springframework.beans.factory.annotation.Qualifier; |
| | | //import org.springframework.context.annotation.Bean; |
| | | //import org.springframework.context.annotation.Configuration; |
| | | // |
| | | //// |
| | | //// return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build(); |
| | | // } |
| | | //import java.util.HashMap; |
| | | //import java.util.Map; |
| | | // |
| | | ////@Configuration |
| | | //public class RabbitMqConfig { |
| | | // |
| | | ////å®ä¹å»¶è¿éå |
| | | // public static final String phone_queue = "phone_queue"; |
| | | // //å®ä¹å»¶è¿äº¤æ¢æº |
| | | // public static final String phone_exchange = "phone_exchange"; |
| | | // //å®ä¹è·¯ç±é® |
| | | // public static final String routing_key = "phone.123"; |
| | | // |
| | | // |
| | | // /** |
| | | // * éå |
| | | // */ |
| | | // @Bean(QUEUE_NAME) |
| | | // public Queue phoneQueue() { |
| | | // return QueueBuilder.durable(QUEUE_NAME).build(); |
| | | // } |
| | | // |
| | | // /** |
| | | // * äº¤æ¢æºä¸éåçç»å® |
| | | // * å®ä¹å»¶è¿éå |
| | | // * |
| | | // * @return |
| | | // */ |
| | | // @Bean |
| | | // public Binding bindQueueExchange(@Qualifier(QUEUE_NAME) Queue phoneQueue, @Qualifier(EXCHANGE_NAME) Exchange phoneExchange) { |
| | | // return BindingBuilder.bind(phoneQueue).to(phoneExchange).with(" phone.#").noargs(); |
| | | // public Queue delayQueue() { |
| | | // return new Queue(phone_queue, true); |
| | | // } |
| | | //å®ä¹å»¶è¿éå |
| | | public static final String phone_queue = "phone_queue"; |
| | | //å®ä¹å»¶è¿äº¤æ¢æº |
| | | public static final String phone_exchange = "phone_exchange"; |
| | | //å®ä¹è·¯ç±é® |
| | | public static final String routing_key = "phone.123"; |
| | | |
| | | |
| | | /** |
| | | * å®ä¹å»¶è¿éå |
| | | * |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public Queue delayQueue() { |
| | | return new Queue(phone_queue, true); |
| | | } |
| | | |
| | | /** |
| | | * å»¶æ¶éåäº¤æ¢æº |
| | | * äº¤æ¢æºç±»åï¼CustomExchange |
| | | * |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public CustomExchange delayExchange() { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("x-delayed-type", "topic"); |
| | | return new CustomExchange(phone_exchange, "x-delayed-message", true, false, args); |
| | | } |
| | | |
| | | /** |
| | | * 为延è¿éåç»å®äº¤æ¢æº |
| | | * |
| | | * @param queue |
| | | * @param exchange |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public Binding delayBinding(Queue queue, CustomExchange exchange) { |
| | | return BindingBuilder.bind(queue).to(exchange).with(routing_key).noargs(); |
| | | } |
| | | |
| | | } |
| | | // |
| | | // /** |
| | | // * å»¶æ¶éåäº¤æ¢æº |
| | | // * äº¤æ¢æºç±»åï¼CustomExchange |
| | | // * |
| | | // * @return |
| | | // */ |
| | | // @Bean |
| | | // public CustomExchange delayExchange() { |
| | | // Map<String, Object> args = new HashMap<>(); |
| | | // args.put("x-delayed-type", "topic"); |
| | | // return new CustomExchange(phone_exchange, "x-delayed-message", true, false, args); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 为延è¿éåç»å®äº¤æ¢æº |
| | | // * |
| | | // * @param queue |
| | | // * @param exchange |
| | | // * @return |
| | | // */ |
| | | // @Bean |
| | | // public Binding delayBinding(Queue queue, CustomExchange exchange) { |
| | | // return BindingBuilder.bind(queue).to(exchange).with(routing_key).noargs(); |
| | | // } |
| | | // |
| | | //} |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.domain; |
| | | |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MQä»»å¡ |
| | | * |
| | | * @author ruoyi |
| | | * @date 2024-02-02 |
| | | */ |
| | | @Data |
| | | public class IvrTaskcallPhoneMQ extends BaseEntity { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * ç±»å: 1 çµè¯ 2å
¶å® |
| | | */ |
| | | @ApiModelProperty(value = "ç±»å: 1 çµè¯ 2å
¶å®") |
| | | private String type; |
| | | |
| | | @ApiModelProperty(value = "é®é¢") |
| | | private String script; |
| | | |
| | | @ApiModelProperty(value = "é®é¢") |
| | | private String uuid; |
| | | |
| | | |
| | | } |
| | |
| | | @ApiModelProperty(value = "åéç±»å: 1 æ¶é´æ®µ 2 å³å»åé") |
| | | private String sendType; |
| | | |
| | | private String type; |
| | | |
| | | |
| | | } |
| | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | //import com.smartor.config.PhoneUtils; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.config.RabbitMqConfig; |
| | | import com.smartor.config.RabbitMqCallPhoneConfig; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | | import com.smartor.service.IIvrTaskService; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper; |
| | | |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; |
| | | |
| | | |
| | | /** |
| | |
| | | String ivrTaskcallMQJson = JSON.toJSONString(ivrTaskcallMQ); |
| | | ivrTaskcallMQJson = ivrTaskcallMQJson.substring(1, ivrTaskcallMQJson.length() - 1); |
| | | //ç«å³åé |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, ivrTaskcallMQJson, message -> { |
| | | //注æè¿éæ¶é´å¯ä»¥ä½¿longï¼è䏿¯è®¾ç½®header |
| | | message.getMessageProperties().setHeader("x-delay", 0); |
| | | return message; |
| | | }); |
| | | rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, 0L); |
| | | |
| | | } else if (ivrTaskcallVO.getSendType().equals("1")) { |
| | | //æ¶é´æ®µåé |
| | | if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) { |
| | |
| | | Long finalMilliseconds = milliseconds; |
| | | String ivrTaskcallMQJson = JSON.toJSONString(ivrTaskcallMQ); |
| | | ivrTaskcallMQJson = ivrTaskcallMQJson.substring(1, ivrTaskcallMQJson.length() - 1); |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, ivrTaskcallMQJson, message -> { |
| | | //注æè¿éæ¶é´å¯ä»¥ä½¿longï¼è䏿¯è®¾ç½®header |
| | | message.getMessageProperties().setHeader("x-delay", finalMilliseconds); |
| | | return message; |
| | | }); |
| | | rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, 0L); |
| | | } |
| | | //å°ä»»å¡ç¶æä¿®æ¹ææ§è¡ä¸ |
| | | IvrTask ivrTask = new IvrTask(); |
| | |
| | | |
| | | @Override |
| | | public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) { |
| | | synchronized (new IvrTaskSingleServiceImpl()) { |
| | | |
| | | phoneCallBackVO.setTextResult(phoneCallBackVO.getTextResult().substring(0, phoneCallBackVO.getTextResult().length() - 1)); |
| | | SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); |
| | | |
| | |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.info("æåçä¿¡æ¯åå¤-: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); |
| | | phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); |
| | | } |
| | | } |
| | | } |
| | | } |