package com.xzx.log.util; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.xzx.log.entity.IntefaceAdminLog; import lombok.experimental.UtilityClass; import org.springframework.amqp.core.Message; import java.io.UnsupportedEncodingException; @UtilityClass public class MqUtil { /** * 将消息内容转换成实体 * @param * @param message * @param beanClass * @return * @throws UnsupportedEncodingException */ public T getBean(Message message, Class beanClass) throws UnsupportedEncodingException { String msg = new String(message.getBody(), "UTF-8"); T t = JSONUtil.toBean(msg, beanClass); return t; } public long getTag(Message message){ return message.getMessageProperties().getDeliveryTag(); } public String getMsg(Message message){ return StrUtil.str(message.getBody(),"UTF-8"); } public String getId(Message message){ return message.getMessageProperties().getMessageId(); } }