Lagom Publish message with Kafka

半城伤御伤魂 提交于 2019-12-24 20:19:42

问题


Only one way of publishing is described here. There is another way? The example I need to make a publication with dynamic topic id and custom event without persistentEntityRegistry? And how do I can publish the event with eventId?

 @Override
  default Descriptor descriptor() {
    return named("helloservice").withCalls(
        pathCall("/api/hello/:id",  this::hello),
        pathCall("/api/event/:id", this::pushEventWithId) // id - eventId
      )
      .withTopics(
        topic(GREETINGS_TOPIC, this::greetingsTopic)
      )
      .withAutoAcl(true);
  }

Processing request.

public ServiceCall<RequestMessage, NotUsed> pushEventWithId(String eventId) {
    return message -> {
        // Here I need push this message to kafka with eventId. Another service should be subscribed on this eventId

    }
}

Lagom version: 1.3.10


回答1:


This is not currently supported. What you can do is instantiate the Kafka client directly yourself (this is not hard to do) to publish messages imperatively like that.

While support will be added for publishing messages imperatively in the future, one reason Lagom hasn't added support yet is that very often when people want to do this, they're actually introducing anti patterns into their system, such as the opportunity for inconsistency. For example, if you have service that updates some database, then publishes a message to Kafka, you've got a problem, because if the database update succeeds, but the message publish fails, then nothing is going to get that update, and your system will be in an inconsistent state. What this presentation for a detailed look into why this is a problem, and how publishing events from an event log solves it.



来源:https://stackoverflow.com/questions/47632257/lagom-publish-message-with-kafka

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!