Hibernate Search 6:从另一个微服务更新嵌入式索引

huangapple go评论56阅读模式
英文:

Hibernate search 6 : updating EmbededIndex from another Microservice

问题

以下是翻译的内容:

早上好,
我有一个相当特殊的情景,我想听听您对处理这种情况的最佳方式的意见。
我们有一个分为多个功能微服务的应用程序,但共用一个数据库(这并不理想,但目前我们没有选择)。
从微服务A,我使用IndexedEmbeded索引实体A与实体B、C和D。
1- 如果我对A进行修改,更改B、C或D,是否会自动传播到索引文档,还是需要额外的配置?
2- 实体B、C和D的表格由其他微服务更新,在这种情况下,我需要更新实体A的索引。最佳方法是什么?

我考虑在其他微服务中每次更改时手动进行索引修剪,但我不确定这是否是最佳方式。

谢谢

英文:

Good morning,
I have a rather special scenario and I would like to have your opinion on the best way to handle this situation.
We have an application divided into several functional microservices, but a common database (it's not ideal but for the moment we have no choice).
From a microservice A, I index entity A with entities B, C and D, like IndexedEmbeded.
1- if I make modifications on A, by changing B or C or D, is it automatically propagated in the indexing document or does it require additional configuration?
2- the tables of entities B, C and D are updated by other microservices and in this case I have to update my index of entity A. What is the best way to do this?

I thought of doing manual indexing trimmed every change in the other microservices. but I'm not sure that's the best way to do it.

Thank you

答案1

得分: 0

我会遵循您的指示,只翻译您提供的内容,不添加额外的内容。以下是翻译:

I'll state the obvious and say that if you use the same model across microservices, you're in for some headaches, especially when updating your schema, but I guess you know that and can't do anything about it. So, let's have a look at solutions...

if I make modifications on A, by changing B or C or D, is it automatically propagated in the indexing document or does it require additional configuration

假设所有操作发生在同一个微服务中,并且使用 Hibernate ORM 进行更新(而不是使用本机 SQL),那么它应该是自动的。请参阅 https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-reindexing-basics

the tables of entities B, C, and D are updated by other microservices, and in this case, I have to update my index of entity A. What is the best way to do this?

假设您的其他微服务共享相同的 Hibernate ORM 映射(它们知道实体 A,只是不与之交互),例如,它们都导入一个包含您的注释实体的共同 JAR 文件...您可以简单地依赖于 outbox-polling 协调,它允许应用程序的多个实例(或具有相同模型/映射的不同应用程序)安全可靠地协作和索引,只要它们都使用具有兼容配置的 Hibernate Search。

如果这不是您的情况,例如,每个微服务都有自己的实体类,可能不包含其他微服务的所有实体...恐怕 Hibernate Search 无法为您解决这个问题(暂时还不能)。Hibernate Search 提供了一种基于实体事件触发重新索引的方法(实体创建、实体属性 'foo.bar' 更新、实体删除等),您可以通过 SearchIndexingPlan 手动输入这些事件,但您将需要想出一种从一个微服务传播这些事件到另一个微服务的方式。这使得 Hibernate Search 不太有用,不幸的是。

英文:

I'll state the obvious and say that if you use the same model across microservices, you're in for some headaches, especially when updating your schema, but I guess you know that and can't do anything about it. So, let's have a look at solutions...

> if I make modifications on A, by changing B or C or D, is it automatically propagated in the indexing document or does it require additional configuration

Assuming everything happens in the same microservice, and the updates are performed using Hibernate ORM (and not native SQL), it should be automatic. See https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-reindexing-basics .

> the tables of entities B, C and D are updated by other microservices and in this case I have to update my index of entity A. What is the best way to do this?

Assuming your other microservices share the same Hibernate ORM mapping (they know of entity A, they just don't deal with it), e.g. they all import a common JAR that contains your annotated entities... you could simply rely on outbox-polling coordination, which allows multiple instances of an application (or of different applications with the same model/mapping) to cooperate and index safely and reliably, as long as they all use Hibernate Search with compatible configuration.

If that's not your case, e.g. each microservice has its own entity classes, and may not include all entities from other microservices... I'm afraid Hibernate Search can't solve that problem for you (yet). Hibernate Search exposes a way to trigger reindexing based on entity events (entity created, entity property 'foo.bar' updated, entity deleted, ...) that you input manually, via the SearchIndexingPlan, but you will have to devise a way to propagate these events from one microservice to another. And that kind of makes Hibernate Search a lot less useful, unfortunately.

huangapple
  • 本文由 发表于 2023年2月8日 19:28:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385133.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定