fix(CanalListener.java): Canal监听MQ消息序列化失败问题修复

This commit is contained in:
郝先瑞 2022-05-07 21:42:07 +08:00
parent 89fc1ff8c4
commit a334648450

View File

@ -1,6 +1,5 @@
package com.youlai.admin.component.listener; package com.youlai.admin.component.listener;
import cn.hutool.json.JSONUtil;
import com.youlai.admin.service.ISysMenuService; import com.youlai.admin.service.ISysMenuService;
import com.youlai.admin.service.ISysOauthClientService; import com.youlai.admin.service.ISysOauthClientService;
import com.youlai.admin.service.ISysPermissionService; import com.youlai.admin.service.ISysPermissionService;
@ -8,6 +7,7 @@ import com.youlai.common.dto.CanalMessage;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@ -27,17 +27,10 @@ public class CanalListener {
private final ISysOauthClientService oauthClientService; private final ISysOauthClientService oauthClientService;
private final ISysMenuService menuService; private final ISysMenuService menuService;
/*@RabbitListener(bindings = {
@QueueBinding(
value = @Queue(value = "canal.queue", durable = "true"),
exchange = @Exchange(value = "canal.exchange"),
key = "canal.routing.key"
)
})*/
@RabbitListener(queues = "canal.queue") @RabbitListener(queues = "canal.queue")
public void handleDataChange(String message) { public void handleDataChange(@Payload CanalMessage message) {
CanalMessage canalMessage = JSONUtil.toBean(message, CanalMessage.class); String tableName = message.getTable();
String tableName = canalMessage.getTable();
log.info("Canal 监听 {} 发生变化;明细:{}", tableName, message); log.info("Canal 监听 {} 发生变化;明细:{}", tableName, message);