| @@ -2,11 +2,13 @@ package com.iformall.service.test; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||||
| import com.iformall.domain.vo.WxBillAll; | import com.iformall.domain.vo.WxBillAll; | ||||
| import com.iformall.enums.EnumSettleRecordWay; | |||||
| import com.iformall.enums.EnumSettleStatus; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.mapper.WxBillSettleMapper; | import com.iformall.mapper.WxBillSettleMapper; | ||||
| import com.iformall.mq.MqBaseProducer; | |||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.Constant; | |||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.authc.UsernamePasswordToken; | import org.apache.shiro.authc.UsernamePasswordToken; | ||||
| @@ -32,6 +34,8 @@ import org.springframework.web.context.WebApplicationContext; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| @Slf4j | @Slf4j | ||||
| @AutoConfigureMockMvc | @AutoConfigureMockMvc | ||||
| @@ -62,6 +66,10 @@ public class Test { | |||||
| private MockMvc mockMvc; | private MockMvc mockMvc; | ||||
| @Autowired | |||||
| MqBaseProducer mqBaseProducer; | |||||
| @Autowired | @Autowired | ||||
| private WxBillSettleService wxBillSettleService; | private WxBillSettleService wxBillSettleService; | ||||
| @Autowired | @Autowired | ||||
| @@ -121,6 +129,18 @@ public class Test { | |||||
| wxBillSettleMapper.updateByPrimaryKeySelective(wxBillSettle); | wxBillSettleMapper.updateByPrimaryKeySelective(wxBillSettle); | ||||
| } | } | ||||
| @org.junit.Test | |||||
| public void testmq(){ | |||||
| Map<String,String> dynamicContentMap = new HashMap<>(); | |||||
| dynamicContentMap.put("page", Constant.adminPage); | |||||
| WxMsgRecord wxMsgRecord = new WxMsgRecord(); | |||||
| wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); | |||||
| wxMsgRecord.setModelType(EnumMsgModel.FLOW_ASSIGNEE_NODIFY.getCode()); | |||||
| wxMsgRecord.setReceiver("18601973448"); | |||||
| wxMsgRecord.setTenantId("456"); | |||||
| wxMsgRecord.setDynamicContentMap(dynamicContentMap); | |||||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } | |||||
| } | } | ||||
| @@ -1,8 +1,9 @@ | |||||
| package com.iformall.mq; | package com.iformall.mq; | ||||
| import com.iformall.domain.po.msg.BaseMsg; | import com.iformall.domain.po.msg.BaseMsg; | ||||
| import org.springframework.amqp.rabbit.core.RabbitTemplate; | |||||
| public interface MqBaseProducer { | |||||
| public interface MqBaseProducer extends RabbitTemplate.ConfirmCallback{ | |||||
| void sendMessage(BaseMsg record, String topic, String tags, String keys); | void sendMessage(BaseMsg record, String topic, String tags, String keys); | ||||
| } | } | ||||
| @@ -1,7 +1,6 @@ | |||||
| package com.iformall.mq.impl; | package com.iformall.mq.impl; | ||||
| import com.iformall.domain.po.msg.BaseMsg; | import com.iformall.domain.po.msg.BaseMsg; | ||||
| import com.iformall.enums.EnumMsgRecordStatus; | |||||
| import com.iformall.mapper.WxMsgRecordMapper; | import com.iformall.mapper.WxMsgRecordMapper; | ||||
| import com.iformall.mq.MQConfig; | import com.iformall.mq.MQConfig; | ||||
| import com.iformall.mq.MqBaseProducer; | import com.iformall.mq.MqBaseProducer; | ||||
| @@ -10,6 +9,7 @@ import com.iformall.utils.JsonUtil; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.amqp.core.AmqpTemplate; | import org.springframework.amqp.core.AmqpTemplate; | ||||
| import org.springframework.amqp.rabbit.support.CorrelationData; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.context.annotation.Profile; | import org.springframework.context.annotation.Profile; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| @@ -31,17 +31,30 @@ public class RabbitMqMessageProducer implements MqBaseProducer { | |||||
| @Autowired | @Autowired | ||||
| private WxMsgRecordService wxMsgRecordService; | private WxMsgRecordService wxMsgRecordService; | ||||
| @Override | |||||
| public void confirm(CorrelationData correlationData, boolean b, String s) { | |||||
| log.info("------correlationData"+correlationData.toString()); | |||||
| System.out.println(); | |||||
| if(b){ | |||||
| System.out.println(); | |||||
| }else{ | |||||
| } | |||||
| } | |||||
| @Override | @Override | ||||
| public void sendMessage(BaseMsg data, String topic, String tags, String keys) { | public void sendMessage(BaseMsg data, String topic, String tags, String keys) { | ||||
| try { | try { | ||||
| data.setUuid(UUID.randomUUID().toString()); | data.setUuid(UUID.randomUUID().toString()); | ||||
| wxMsgRecordService.save(data); | wxMsgRecordService.save(data); | ||||
| rabbitTemplate.convertAndSend(topic, JsonUtil.obj2Json(data)); | |||||
| CorrelationData correlationData = new CorrelationData("16746324"); | |||||
| rabbitTemplate.convertAndSend(topic, JsonUtil.obj2Json(data),correlationData); | |||||
| // data.setMsgStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); | // data.setMsgStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); | ||||
| // wxMsgRecordMapper.update(data); | // wxMsgRecordMapper.update(data); | ||||
| log.info(data.getUuid()+"发送mq成功。"); | log.info(data.getUuid()+"发送mq成功。"); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| log.error("RabbitMqMessageProducer: Send Message Error ", e); | log.error("RabbitMqMessageProducer: Send Message Error ", e); | ||||
| } | } | ||||
| @@ -14,6 +14,7 @@ import org.apache.rocketmq.common.message.Message; | |||||
| import org.apache.rocketmq.remoting.common.RemotingHelper; | import org.apache.rocketmq.remoting.common.RemotingHelper; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.amqp.rabbit.support.CorrelationData; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.context.annotation.Profile; | import org.springframework.context.annotation.Profile; | ||||
| @@ -42,6 +43,11 @@ public class RocketMqMessageProducer implements MqBaseProducer { | |||||
| @Autowired | @Autowired | ||||
| private WxMsgRecordService wxMsgRecordService; | private WxMsgRecordService wxMsgRecordService; | ||||
| @Override | |||||
| public void confirm(CorrelationData correlationData, boolean b, String s) { | |||||
| } | |||||
| @PostConstruct | @PostConstruct | ||||
| public void start(){ | public void start(){ | ||||
| try { | try { | ||||