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

查看:34
本文介绍了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天全站免登陆