|
@@ -0,0 +1,79 @@
|
|
|
+//package com.slodon.b2b2c.investment.rabbitmq;
|
|
|
+//
|
|
|
+//import com.slodon.b2b2c.investment.bean.wordpress.PostBO;
|
|
|
+//import com.slodon.b2b2c.investment.config.DifyConfig;
|
|
|
+//import com.slodon.b2b2c.investment.model.DifyModel;
|
|
|
+//import com.slodon.b2b2c.investment.model.WordPressModel;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.amqp.core.ExchangeTypes;
|
|
|
+//import org.springframework.amqp.rabbit.annotation.Exchange;
|
|
|
+//import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
+//import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
|
|
+//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//import org.springframework.util.StringUtils;
|
|
|
+//
|
|
|
+//import javax.annotation.Resource;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @author sunshihao
|
|
|
+// * @version 1.0
|
|
|
+// * @description: 消费文章信息
|
|
|
+// * @date 2025/8/19 16:32
|
|
|
+// */
|
|
|
+//@Component
|
|
|
+//@Slf4j
|
|
|
+//public class WordPressConsumer {
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private DifyConfig difyConfig;
|
|
|
+// @Resource
|
|
|
+// private DifyModel difyModel;
|
|
|
+// @Resource
|
|
|
+// private WordPressModel wordPressModel;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 通过注解直接声明:交换机、队列、绑定关系
|
|
|
+// * 监听队列,自动消费消息并反序列化为PostEvent
|
|
|
+// */
|
|
|
+// @RabbitListener(
|
|
|
+// bindings = @QueueBinding(
|
|
|
+// value = @Queue(
|
|
|
+// value = "wordpress_posts",
|
|
|
+// durable = "true",
|
|
|
+// exclusive = "false",
|
|
|
+// autoDelete = "false"
|
|
|
+// ),
|
|
|
+// exchange = @Exchange(
|
|
|
+// value = "wordpress_events",
|
|
|
+// type = ExchangeTypes.DIRECT,
|
|
|
+// durable = "true",
|
|
|
+// autoDelete = "false"
|
|
|
+// ),
|
|
|
+// key = ""
|
|
|
+// )
|
|
|
+// )
|
|
|
+// public void handlePostEvent(PostBO postEvent) {
|
|
|
+// // 业务处理逻辑
|
|
|
+// if (!"updated".equals(postEvent.getEvent())) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// // 调用wp对外api接口,拉取文章信息
|
|
|
+// String post = wordPressModel.getPostById(postEvent.getPostId(), postEvent.getSiteUrl());
|
|
|
+// String title = postEvent.getPostTitle();
|
|
|
+// // 调用dify对外api接口,更新文章信息
|
|
|
+// String docId = difyModel.documents(difyConfig.getDatabaseId(), title);
|
|
|
+// // 根据文章id更新文章内容
|
|
|
+// if (StringUtils.isEmpty(docId)) {
|
|
|
+// // 新增
|
|
|
+// difyModel.createByText(difyConfig.getDatabaseId(), title, post);
|
|
|
+// } else {
|
|
|
+// // 修改
|
|
|
+// difyModel.updateByText(difyConfig.getDatabaseId(), docId, title, post);
|
|
|
+// }
|
|
|
+// }catch (Exception e){
|
|
|
+// log.error("同步wordpress到dify失败。"+e.getMessage(),e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|