Declaring message contracts
Steps to declare what your service produces and consumes, so the Message Contract Service can document and validate it. See Message contracts for why contracts exist and how they're processed.
-
The annotations come from
jeap-messaging-contract-annotations, normally already on the classpath transitively via the generated message-type JARs — no extra dependency is usually needed. -
Add
@JeapMessageProducerContract/@JeapMessageConsumerContract(or their repeatable...Contractsforms) for every message type the service produces or consumes. They can go anywhere, but are commonly placed on the@SpringBootApplicationclass. Each references the generatedTypeRefinner class of the message type, e.g.JmeCreateDeclarationCommand.TypeRef.class. -
appNamedefaults tospring.application.nameandtopicdefaults to the message type's default topic — only set them to override, e.g. for a shared event consumed from several topics, or a contract declared on behalf of another application:@JeapMessageProducerContract(JmeDeclarationCreatedEvent.TypeRef.class)@JeapMessageConsumerContract(JmeCreateDeclarationCommand.TypeRef.class)@JeapMessageConsumerContract(value = JmeSharedEvent.TypeRef.class,topic = {"my-topic", "my-topic-2"})@JeapMessageProducerContract(value = JmeAuditEvent.TypeRef.class,appName = "my-audit-service")@SpringBootApplicationpublic class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}} -
Only if your build configures
annotationProcessorPathsexplicitly on themaven-compiler-plugin(most builds don't), add the processor path explicitly too:<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><annotationProcessorPaths><path><groupId>ch.admin.bit.jeap</groupId><artifactId>jeap-messaging-contract-annotations</artifactId><version>${jeap-messaging.version}</version></path></annotationProcessorPaths></configuration></plugin> -
Build the service. The annotation processor generates the contract JSON (and the message type's schema) at compile time, and the jEAP build pipeline uploads both to the Message Contract Service — no further action is needed.
For relaxing enforcement in tests, see publishWithoutContractAllowed /
consumeWithoutContractAllowed in the Configuration reference.