Commit 542478e0 by songxiang

促销MQ发UAT

parent 6fe6a96e
package com.pcloud.common.core.biz; package com.pcloud.common.core.biz;
import com.pcloud.common.core.dto.PromotionTaskDto; import com.pcloud.common.core.dto.PromotionTaskDto;
import com.pcloud.common.exceptions.BizException;
/** /**
* @Description:促销任务队列 * @Description:促销任务队列
* @Author:lixg * @Author:lixg @Date:2018/6/12 @Version:1.0
* @Date:2018/6/12
* @Version:1.0
*/ */
public interface PromotionTaskQueueBiz { public interface PromotionTaskQueueBiz {
/**
void send(PromotionTaskDto promotionTaskDto); * 发送消息
*
* @param promotionTaskDto
*/
void send(PromotionTaskDto promotionTaskDto) throws BizException;
} }
package com.pcloud.common.core.biz; package com.pcloud.common.core.biz;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.constant.MQQueueConstant;
import com.pcloud.common.core.dto.PromotionTaskDto; import com.pcloud.common.core.dto.PromotionTaskDto;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.exceptions.BizException;
import org.slf4j.Logger; import org.springframework.amqp.core.AmqpTemplate;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Session;
@Service("promotionTaskQueueBiz") @Service("promotionTaskQueueBiz")
public class PromotionTaskQueueBizImpl implements PromotionTaskQueueBiz { public class PromotionTaskQueueBizImpl implements PromotionTaskQueueBiz {
@Autowired
private AmqpTemplate amqpTemplate;
/** /**
* * 促销任务QUEUE
*/
private final static Logger logger = LoggerFactory.getLogger(PromotionTaskQueueBizImpl.class);
/**
* 消息模板
*/ */
@Autowired(required = false)
@Qualifier("jmsPromotionTaskTemplate")
private JmsTemplate jmsPromotionTaskTemplate;
@Override @Override
@ParamLog("促销任务QUEUE")
public void send(PromotionTaskDto promotionTaskDto) throws BizException { public void send(PromotionTaskDto promotionTaskDto) throws BizException {
MessageCreator messageCreator = new MessageCreator() { amqpTemplate.convertAndSend(MQQueueConstant.PROMOTION_TASK, promotionTaskDto);
@Override
public ObjectMessage createMessage(Session session) throws JMSException {
return session.createObjectMessage(promotionTaskDto);
}
};
try {
jmsPromotionTaskTemplate.send(messageCreator);
} catch (Exception e) {
logger.error("发送失败," + e.getMessage() + "," + promotionTaskDto, e);
throw BizException.SEND_QUEUE_FAIL;
}
logger.info("发送成功," + promotionTaskDto);
} }
} }
package com.pcloud.common.core.biz; package com.pcloud.common.core.biz;
import com.pcloud.common.core.dto.PromotionTerminateDto; import com.pcloud.common.core.dto.PromotionTerminateDto;
import com.pcloud.common.exceptions.BizException;
/** /**
* @Description:促销终止队列 * @Description:促销终止队列
* @Author:lixg * @Author:lixg @Date:2018/6/12 @Version:1.0
* @Date:2018/6/12
* @Version:1.0
*/ */
public interface PromotionTerminateQueueBiz { public interface PromotionTerminateQueueBiz {
/**
void send(PromotionTerminateDto promotionTerminateDto); * 促销终止队列
*
* @param promotionTerminateDto
*/
void send(PromotionTerminateDto promotionTerminateDto) throws BizException;
} }
package com.pcloud.common.core.biz; package com.pcloud.common.core.biz;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.constant.MQQueueConstant;
import com.pcloud.common.core.dto.PromotionTerminateDto; import com.pcloud.common.core.dto.PromotionTerminateDto;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.exceptions.BizException;
import org.slf4j.Logger; import org.springframework.amqp.core.AmqpTemplate;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Session;
@Service("promotionTerminateQueueBiz") @Service("promotionTerminateQueueBiz")
public class PromotionTerminateQueueBizImpl implements PromotionTerminateQueueBiz { public class PromotionTerminateQueueBizImpl implements PromotionTerminateQueueBiz {
@Autowired
private AmqpTemplate amqpTemplate;
/** /**
* * 促销终止QUEUE
*/ */
private final static Logger logger = LoggerFactory.getLogger(PromotionTerminateQueueBizImpl.class);
/**
* 消息模板
*/
@Autowired(required = false)
@Qualifier("jmsPromotionTerminateTemplate")
private JmsTemplate jmsPromotionTerminateTemplate;
@Override @Override
@ParamLog("促销终止QUEUE")
public void send(PromotionTerminateDto promotionTerminateDto) throws BizException { public void send(PromotionTerminateDto promotionTerminateDto) throws BizException {
MessageCreator messageCreator = new MessageCreator() { amqpTemplate.convertAndSend(MQQueueConstant.PROMOTION_TERMINATE, promotionTerminateDto);
@Override
public ObjectMessage createMessage(Session session) throws JMSException {
return session.createObjectMessage(promotionTerminateDto);
}
};
try {
jmsPromotionTerminateTemplate.send(messageCreator);
} catch (Exception e) {
logger.error("发送失败," + e.getMessage() + "," + promotionTerminateDto, e);
throw BizException.SEND_QUEUE_FAIL;
}
logger.info("发送成功," + promotionTerminateDto);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment