Skip to content

Commit

Permalink
[update] 帖子发布,不使用redis作为失败反馈,直接使用kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYNORl committed Jan 18, 2024
1 parent b3c0180 commit 6b85215
Show file tree
Hide file tree
Showing 116 changed files with 403 additions and 1,861 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package top.zynorl.petplanet.common.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* Created by zynorl on 2024/1/18 15:25
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class RepeatConsumptionException extends RuntimeException{
private static final long serialVersionUID = 1L;
private String transactionId;

public RepeatConsumptionException(String message, String transactionId) {
super(message);
this.transactionId = transactionId;
}

}
17 changes: 10 additions & 7 deletions petplanet-post/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
<artifactId>petplanet-common</artifactId>
<version>${petplanet-common.version}</version>
</dependency>
<dependency>
<groupId>top.zynorl.petplanet</groupId>
<artifactId>petplanet-sqlServer</artifactId>
<version>${petplanet-sqlServer.version}</version>
</dependency>
<dependency>
<groupId>top.zynorl.petplanet</groupId>
<artifactId>petplanet-mongoServer</artifactId>
Expand All @@ -55,11 +50,19 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<!--Mysql数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 服务发现-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
Expand Down Expand Up @@ -104,7 +107,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>top.zynorl.petplanet.user.PetplanetUserApplication</mainClass>
<mainClass>top.zynorl.petplanet.post.PetplanetPostApplication</mainClass>
<goal>repackage</goal>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public interface PostControllerConverter extends BaseConverter {
@Mapping(target = "startEditTime", source = "startEditTime", qualifiedByName = "toLocalDataTime")
PublishPostReqBO toPublishPostReqBO(PublishPostReq publishPostReq);

PublishPostReqBO toPublishPostReqBO1(PublishPostReq publishPostReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import top.zynorl.petplanet.common.converter.ConverterConfig;
import top.zynorl.petplanet.mongoserver.entity.PostMO;
import top.zynorl.petplanet.post.common.pojo.bo.req.PublishPostReqBO;
import top.zynorl.petplanet.post.common.pojo.dto.PublishPostDTO;
import top.zynorl.petplanet.sqlServer.entity.LocationInfoDO;
import top.zynorl.petplanet.post.sqlServer.entity.LocationInfoDO;

/**
* @version 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package top.zynorl.petplanet.post.common.pojo.dto;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
* Created by zynorl on 2024/1/17 10:20
*/
@Data
public class BaseTransactionDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 事务id
*/
private String transactionId;

/**
* kafka主题
*/
private String topic;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
import java.io.Serializable;

/**
* @version 1.0
* @Author niuzy
* @Date 2024/01/10
**/
* Created by zynorl on 2024/1/18 16:14
*/
@Data
public class PublishPostDTO implements Serializable {
public class PublishPostFailedCallbackDTO implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 关联用户id
* 帖子id
*/
private Long userId;
private String postId;

/**
* 帖子id
* 地点Id
*/
private String postId;
private Long locationId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package top.zynorl.petplanet.post.common.pojo.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* @version 1.0
* @Author niuzy
* @Date 2024/01/10
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PublishPostTransactionDTO extends BaseTransactionDTO implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 关联用户id
*/
private Long userId;

/**
* 帖子id
*/
private String postId;

/**
* 地点Id
*/
private Long locationId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package top.zynorl.petplanet.post.listener;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import top.zynorl.petplanet.post.common.pojo.dto.PublishPostFailedCallbackDTO;
import top.zynorl.petplanet.post.transaction.PostPublishTransactionalService;

/**
* @version 1.0
* @Author niuzy
* @Date 2024/01/05
**/
@Component
@Slf4j
public class TransactionFailedCallbackListener {
private static final String postPublishTopic = "post_publish";
@Autowired
private PostPublishTransactionalService postPublishTransactionalService;

@KafkaListener(topics = postPublishTopic)
public void postPublishListener(String message) {
PublishPostFailedCallbackDTO publishPostFailedCallbackDTO = JSONUtil.toBean(message, PublishPostFailedCallbackDTO.class);
postPublishTransactionalService.DoCancel(publishPostFailedCallbackDTO);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6b85215

Please sign in to comment.