Helius
2021-06-21 5812839f3e23bb09e1a9b100b63273a646155709
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 <T>
     * @param message
     * @param beanClass
     * @return
     * @throws UnsupportedEncodingException
     */
    public <T> T getBean(Message message, Class<T> 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();
    }
}