Skip to content

Commit

Permalink
Hibernate Search: Add support for new outbox-polling properties in 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jun 22, 2023
1 parent 05631f7 commit 94b6caa
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 1 deletion.
18 changes: 18 additions & 0 deletions docs/src/main/asciidoc/hibernate-search-orm-elasticsearch.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,24 @@ then no worries: the entities required by Hibernate Search will be included in t
* Otherwise, you must
link:{hibernate-search-doc-prefix}#coordination-outbox-polling-schema[manually alter your schema to add the necessary tables/sequences].

[NOTE]
====
The database schema Hibernate Search will expect for outbox-polling coordination
may be customized through the following configuration properties:
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.catalog[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.catalog`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.schema[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.schema`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.table[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.table`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-gen-strategy[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-gen-strategy`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-type[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-type`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.catalog[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.catalog`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.schema[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.schema`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.table[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.table`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-gen-strategy[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-gen-strategy`]
* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-type[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-type`]
====

Once you are done with the above, you're ready to use Hibernate Search with an outbox.
Don't change any code, and just start your application:
it will automatically detect when multiple applications are connected to the same database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem;
import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingBuildTimeConfig;
import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingRecorder;
import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingRuntimeConfig;
import io.quarkus.hibernate.search.orm.elasticsearch.deployment.HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem;
Expand Down Expand Up @@ -43,6 +44,7 @@ void registerInternalModel(BuildProducer<AdditionalIndexedClassesBuildItem> addi
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void setStaticConfig(HibernateSearchOutboxPollingRecorder recorder,
HibernateSearchOutboxPollingBuildTimeConfig buildTimeConfig,
List<HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem> configuredPersistenceUnits,
BuildProducer<HibernateSearchIntegrationStaticConfiguredBuildItem> staticConfigured) {
for (HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem configuredPersistenceUnit : configuredPersistenceUnits) {
Expand All @@ -51,7 +53,8 @@ void setStaticConfig(HibernateSearchOutboxPollingRecorder recorder,
}
String puName = configuredPersistenceUnit.getPersistenceUnitName();
staticConfigured.produce(new HibernateSearchIntegrationStaticConfiguredBuildItem(
HIBERNATE_SEARCH_ORM_COORDINATION_OUTBOX_POLLING, puName, null)
HIBERNATE_SEARCH_ORM_COORDINATION_OUTBOX_POLLING, puName,
recorder.createStaticInitListener(buildTimeConfig, puName))
// Additional entities such as Agent and OutboxEvent are defined through XML
// (because there's no other way).
.setXmlMappingRequired(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.hibernate.SessionFactory;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.HibernateOrmMapperOutboxPollingSettings;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.UuidGenerationStrategy;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
Expand All @@ -32,6 +33,20 @@ public class ConfigPropertiesTest {
.addPackage(IndexedEntity.class.getPackage())
.addPackage(IndexedEntityForPU1.class.getPackage()))
.withConfigurationResource("application-multiple-persistence-units.properties")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.catalog", "myagentcatalog")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.schema", "myagentschema")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.table", "myagenttable")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-gen-strategy", "random")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-type", "uuid-char")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.catalog",
"myoutboxeventcatalog")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.schema",
"myoutboxeventschema")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.table",
"myoutboxeventtable")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-gen-strategy",
"time")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-type", "uuid-binary")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.event-processor.enabled", "false")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.event-processor.shards.total-count", "10")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.event-processor.shards.assigned", "1,2")
Expand All @@ -44,6 +59,28 @@ public class ConfigPropertiesTest {
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.polling-interval", "0.048S")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-interval", "0.049S")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-expiration", "50S")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-interval", "0.049S")
.overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-expiration", "50S")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.catalog",
"myagentcatalogpu1")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.schema",
"myagentschemapu1")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.table",
"myagenttablepu1")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.uuid-gen-strategy",
"time")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.uuid-type",
"uuid-binary")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.catalog",
"myoutboxeventcatalogpu1")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.schema",
"myoutboxeventschemapu1")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.table",
"myoutboxeventtablepu1")
.overrideConfigKey(
"quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.uuid-gen-strategy", "random")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.uuid-type",
"uuid-char")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.event-processor.enabled", "false")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.event-processor.shards.total-count", "110")
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.event-processor.shards.assigned", "11,12")
Expand Down Expand Up @@ -100,6 +137,24 @@ public class ConfigPropertiesTest {
public void root() {
assertThat(sessionFactory.getProperties())
.contains(
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_CATALOG,
"myagentcatalog"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_SCHEMA,
"myagentschema"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_TABLE, "myagenttable"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_GEN_STRATEGY,
UuidGenerationStrategy.RANDOM),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_TYPE, "uuid-char"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_CATALOG,
"myoutboxeventcatalog"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_SCHEMA,
"myoutboxeventschema"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_TABLE,
"myoutboxeventtable"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_GEN_STRATEGY,
UuidGenerationStrategy.TIME),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_TYPE,
"uuid-binary"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_ENABLED, false),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_TOTAL_COUNT, 10),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_ASSIGNED,
Expand All @@ -119,6 +174,26 @@ public void root() {
public void perNamedPersistenceUnit() {
assertThat(sessionFactoryForNamedPU1.getProperties())
.contains(
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_CATALOG,
"myagentcatalogpu1"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_SCHEMA,
"myagentschemapu1"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_TABLE,
"myagenttablepu1"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_GEN_STRATEGY,
UuidGenerationStrategy.TIME),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_TYPE,
"uuid-binary"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_CATALOG,
"myoutboxeventcatalogpu1"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_SCHEMA,
"myoutboxeventschemapu1"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_TABLE,
"myoutboxeventtablepu1"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_GEN_STRATEGY,
UuidGenerationStrategy.RANDOM),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_TYPE,
"uuid-char"),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_ENABLED, false),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_TOTAL_COUNT, 110),
entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_ASSIGNED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime;

import java.util.Map;

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithParentName;

@ConfigMapping(prefix = "quarkus.hibernate-search-orm")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface HibernateSearchOutboxPollingBuildTimeConfig {

/**
* Configuration for the default persistence unit.
*/
@WithParentName
HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit defaultPersistenceUnit();

/**
* Configuration for additional named persistence units.
*/
@ConfigDocSection
@ConfigDocMapKey("persistence-unit-name")
@WithParentName
Map<String, HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit> persistenceUnits();

}
Loading

0 comments on commit 94b6caa

Please sign in to comment.