Skip to main content

Message configuration

Message-to-operation mappings are loaded at startup from /opensearch/messages.json on the classpath. Each entry maps a Kafka message type and topic to one or more index operations that are executed when a message of that type arrives.

File structure

{
"messages": [
{
"messageName": "JmeDecreeDocumentCreatedEvent",
"topicName": "jme-decree-document-created",
"operations": [
{
"indexType": "DecreeDocument",
"indexOperation": "UPSERT",
"uri": "${jme.resource.base-uri}",
"oauthClientId": "jme-client-id",
"referenceProvider": "ch.admin.bit.jme.indexwriter.DecreeDocumentReferenceProvider",
"condition": "ch.admin.bit.jme.indexwriter.DecreeDocumentActiveCondition",
"featureFlag": "DECREE_DOCUMENT_INDEXING"
}
]
},
{
"messageName": "JmeDecreeDocumentDeletedEvent",
"topicName": "jme-decree-document-deleted",
"operations": [
{
"indexType": "DecreeDocument",
"indexOperation": "DELETE",
"uri": "${jme.resource.base-uri}",
"referenceProvider": "ch.admin.bit.jme.indexwriter.DecreeDocumentReferenceProvider"
}
]
}
]
}

Message fields

FieldRequiredDescription
messageNameYesSimple class name of the Avro-generated message type (e.g. JmeDecreeDocumentCreatedEvent).
topicNameYesKafka topic the message is consumed from.
operationsYesOne or more index operations to execute when the message arrives.

Operation fields

FieldRequiredDescription
indexTypeYesName of the target IndexType — must match the name() of a registered IndexTypeDescriptor bean.
indexOperationYesUPSERT or DELETE (case-insensitive).
uriYesURI of the SearchItem Provider endpoint. Spring property placeholders (${...}) are resolved at startup.
oauthClientIdNoThe OAuth2 client ID used to authenticate against the SearchItem Provider. Must be registered under spring.security.oauth2.client.registration. If omitted, the request is sent without authentication.
referenceProviderYesFully qualified class name of the Spring bean implementing ReferenceProvider<M>.
conditionNoFully qualified class name of the Spring bean implementing IndexingCondition. The operation is skipped when the condition returns false.
featureFlagNoName of a jEAP feature flag. The operation is skipped when the flag is inactive.

ReferenceProvider

The ReferenceProvider<M> interface extracts one or more OriginReference objects from a message. The service executes the configured operation independently for each returned reference:

@Component
class DecreeDocumentReferenceProvider implements ReferenceProvider<JmeDecreeDocumentCreatedEvent> {

@Override
public List<OriginReference> extractReference(JmeDecreeDocumentCreatedEvent event) {
return List.of(
OriginReference.builder()
.id(event.getPayload().getDecreeDocumentId())
.version(event.getPayload().getVersion())
.build()
);
}
}

Returning multiple references from a single message is useful when one event triggers indexing of several related business objects at once.

IndexingCondition

An IndexingCondition bean gates an operation — the operation is skipped when the condition returns false:

@Component
class DecreeDocumentActiveCondition implements IndexingCondition<JmeDecreeDocumentCreatedEvent> {

@Override
public boolean shouldIndex(JmeDecreeDocumentCreatedEvent event) {
return event.getPayload().getStatus() == Status.ACTIVE;
}
}

Feature flags

Operations can be guarded by a jEAP feature flag. When the flag is inactive the operation is skipped entirely, without fetching the SearchItem or contacting OpenSearch. The flag name must match a feature flag registered in the jEAP feature flag configuration.

Multiple operations per message

A single message can trigger multiple independent operations — for example an event that requires updating two different index types:

{
"messageName": "JmeRegistrationCompletedEvent",
"topicName": "jme-registration-completed",
"operations": [
{
"indexType": "Registration",
"indexOperation": "UPSERT",
"uri": "${jme.resource.base-uri}",
"referenceProvider": "ch.admin.bit.jme.indexwriter.RegistrationReferenceProvider"
},
{
"indexType": "DecreeDocument",
"indexOperation": "UPSERT",
"uri": "${jme.resource.base-uri}",
"referenceProvider": "ch.admin.bit.jme.indexwriter.DecreeDocumentByRegistrationReferenceProvider"
}
]
}