From a334648450f124146c5c4ab3eb2eb6cf19132749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Sat, 7 May 2022 21:42:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(CanalListener.java):=20Canal=E7=9B=91?= =?UTF-8?q?=E5=90=ACMQ=E6=B6=88=E6=81=AF=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/component/listener/CanalListener.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/listener/CanalListener.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/listener/CanalListener.java index 6b20cd15f..16982c70d 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/listener/CanalListener.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/listener/CanalListener.java @@ -1,6 +1,5 @@ package com.youlai.admin.component.listener; -import cn.hutool.json.JSONUtil; import com.youlai.admin.service.ISysMenuService; import com.youlai.admin.service.ISysOauthClientService; import com.youlai.admin.service.ISysPermissionService; @@ -8,6 +7,7 @@ import com.youlai.common.dto.CanalMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Component; import java.util.Arrays; @@ -27,17 +27,10 @@ public class CanalListener { private final ISysOauthClientService oauthClientService; 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") - public void handleDataChange(String message) { - CanalMessage canalMessage = JSONUtil.toBean(message, CanalMessage.class); - String tableName = canalMessage.getTable(); + public void handleDataChange(@Payload CanalMessage message) { + String tableName = message.getTable(); log.info("Canal 监听 {} 发生变化;明细:{}", tableName, message);