最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - How to implement Kafka Message when I want to use polling publisher pattern? - Stack Overflow

programmeradmin1浏览0评论

I'm now implementing a transactional outbox pattern with polling publisher. and I have a question about how to anize kafka message to publish.

I have this Outbox mongodb document.

@Data
@Document
public class PaymentOutbox {
    @Id
    private String id;
    private String aggId;
    private ProcessStage processStage;
    private String payload;

    @Builder
    protected PaymentOutbox(String aggId, ProcessStage processStage, String payload) {
        this.aggId = aggId;
        this.processStage = processStage;
        this.payload = payload;
    }
}

and I use avro to publish Outbox Message through kafka. my avro schema is this.

{
  "namespace": "com.someexample",
  "name": "PaymentOutboxMessage",
  "type": "record",
  "fields": [
    {
      "name": "aggId",
      "type": "string"
    },
    {
      "name": "processStage",
      "type": "string"
    },
    {
      "name": "payload",
      "type": "string"
    }
  ]
}

payload will carry result of payment. at this point, I have a question.

which is better way and most practical way to make avro schema?

  1. using full payload which is result of payment. -> first I thought it is little bit awkward because it is duplication of document. but I don't have to do select query in @KafkaListener.

  2. using only id of payment that can @KafkaListener perform select query. -> I have to do findOne() using mongoTemplate but less cost of Kafka Message.

I'm sorry for my poor english skill.

first I implemented with first scenario. but I just want to know proper way to implementing it.

发布评论

评论列表(0)

  1. 暂无评论