简体   繁体   English

Lagom用Kafka发布消息

[英]Lagom Publish message with Kafka

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? 我需要使用动态主题ID和自定义事件创建发布而没有persistentEntityRegistry的示例吗? And how do I can publish the event with eventId? 以及如何使用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 Lagom版本:1.3.10

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. 您可以做的就是直接实例化Kafka客户端(这并不难),这样就可以强制发布消息。

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. 尽管将来会增加对强制发布消息的支持,但Lagom尚未添加支持的一个原因是,很多时候人们想要这样做时,他们实际上是在系统中引入了反模式,例如出现不一致的机会。 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. 例如,如果您具有更新某些数据库的服务,然后将消息发布到Kafka,则可能会遇到问题,因为如果数据库更新成功,但是消息发布失败,则没有任何东西可以获取该更新,并且您的系统将处于不一致状态。 What this presentation for a detailed look into why this is a problem, and how publishing events from an event log solves it. 此演示文稿详细介绍了为什么会出现此问题以及如何通过事件日志发布事件来解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM