3 changed files with 46 additions and 1 deletions
@ -0,0 +1,15 @@ |
|||||
|
package com.ccsens.common.service; |
||||
|
|
||||
|
import com.ccsens.util.bean.message.common.InMessage; |
||||
|
|
||||
|
/** |
||||
|
* @author zy |
||||
|
*/ |
||||
|
public interface IMessageService { |
||||
|
/** |
||||
|
* 发送消息到消息系统 |
||||
|
* @param inMessage 消息 |
||||
|
* @throws Exception 异常 |
||||
|
*/ |
||||
|
void sendTo(InMessage inMessage) throws Exception; |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.ccsens.common.service; |
||||
|
|
||||
|
import com.ccsens.util.JacksonUtil; |
||||
|
import com.ccsens.util.bean.message.common.InMessage; |
||||
|
import com.ccsens.util.config.RabbitMQConfig; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.amqp.core.AmqpTemplate; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Propagation; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* @author zy |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
||||
|
public class MessageService implements IMessageService{ |
||||
|
@Resource |
||||
|
private AmqpTemplate rabbitTemplate; |
||||
|
|
||||
|
@Override |
||||
|
public void sendTo(InMessage inMessage) throws Exception{ |
||||
|
log.info("向消息系统推送消息:{}", JacksonUtil.beanToJson(inMessage)); |
||||
|
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, |
||||
|
JacksonUtil.beanToJson(inMessage)); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue