Lagom用Kafka发布消息 [英] Lagom Publish message with Kafka

查看:94
本文介绍了Lagom用Kafka发布消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处仅描述了一种发布方式. 还有另一种方法吗? 我需要使用动态主题ID和自定义事件创建发布而没有persistentEntityRegistry的示例吗? 以及如何使用eventId发布事件?

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);
  }

处理请求.

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版本:1.3.10

Lagom version: 1.3.10

推荐答案

当前不支持此功能.您可以做的就是直接实例化Kafka客户端(这并不难),这样就可以强制性地发布消息.

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.

虽然将来会增加强制性发布消息的支持,但Lagom仍未添加支持的一个原因是,很多时候人们想要这样做时,他们实际上是在系统中引入了反模式,例如不一致的机会.例如,如果您具有更新某些数据库的服务,然后将消息发布到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. 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.

这篇关于Lagom用Kafka发布消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆