赞
踩
<dependency>
<groupId>top.javatool</groupId>
<artifactId>canal-spring-boot-starter</artifactId>
<version>1.2.1-RELEASE</version>
</dependency>
spring:
application:
name: canal-service
cloud:
nacos:
config:
server-addr: 192.168.8.12:8848 #nacos中心地址
file-extension: yaml # 配置文件格式
shared-configs:
- data-id: nacos-discovery-config-dev.yaml
- data-id: redis-config-dev.yaml
profiles:
active: dev # 环境标识
server:
port: 8021
canal:
server: 192.168.8.12:11111
destination: example
logging:
level:
root: info
top:
javatool:
canal:
client:
client:
AbstractCanalClient: error
@Setter @Getter @Table(name = "t_order_info") public class OrderInfo implements Serializable { public static final Integer STATUS_ARREARAGE = 0;//未付款 public static final Integer STATUS_ACCOUNT_PAID = 1;//已付款 public static final Integer STATUS_CANCEL = 2;//手动取消订单 public static final Integer STATUS_TIMEOUT = 3;//超时取消订单 public static final Integer STATUS_REFUND = 4;//已退款 public static final int PAYTYPE_ONLINE = 0;//在线支付 public static final int PAYTYPE_INTERGRAL = 1;//积分支付 @Column(name = "order_no") private String orderNo;//订单编号 @Column(name = "user_id") private Long userId;//用户ID @Column(name = "product_id") private Long productId;//商品ID @Column(name = "delivery_addr_id") private Long deliveryAddrId;//收货地址 @Column(name = "product_name") private String productName;//商品名称 @Column(name = "product_img") private String productImg;//商品图片 @Column(name = "product_count") private Integer productCount;//商品总数 @Column(name = "product_price") private BigDecimal productPrice;//商品原价 @Column(name = "seckill_price") private BigDecimal seckillPrice;//秒杀价格 @Column(name = "intergral") private Long intergral;//消耗积分 @Column(name = "status") private Integer status = STATUS_ARREARAGE;//订单状态 @Column(name = "create_date") private Date createDate;//订单创建时间 @Column(name = "pay_date") private Date payDate;//订单支付时间 @Column(name = "pay_type") private Integer payType;//支付方式 1-在线支付 2-积分支付 @Column(name = "seckill_date") private Date seckillDate;//秒杀的日期 @Column(name = "seckill_time") private Integer seckillTime;// 秒杀场次 @Column(name = "seckill_id") private Long seckillId;//秒杀商品ID }
<>
中写入监听数据库表对应的实体类@Component @CanalTable("t_order_info") public class OrderInfoHandler implements EntryHandler<OrderInfo> { @Autowired private StringRedisTemplate redisTemplate; @Override public void insert(OrderInfo orderInfo) { System.out.println("新增操作"); } @Override public void update(OrderInfo before, OrderInfo after) { System.out.println("编辑操作"); // before 修改之前 只有修改的那列有值 // 修改之后的 修改之后的对象 所有值都有 System.out.println(before); System.out.println(after); } @Override public void delete(OrderInfo orderInfo) { System.out.println("删除操作"); } }
启动启动类,则开始连接Linux服务器中canal的端口,然后开始监听指定ip的mysql数据库
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。