Topics
This page focuses on how Java applications create and use topics, also see Topic Structure.
Creating Topics
Use the Topics factory to create topics.
| Message Type | Helper |
|---|---|
| SBE | Topics.create(SampleMessageDecoder.class, source, group, id) |
| DTO | Topics.create(SampleMessageDto.class, source, group, id) |
| Flexible | Topics.create(source, group, id) |
| Custom | Topics.create(schemaId, templateId, source, group, id) |
| Raw | Topics.create(schemaId, templateId, source, group, id) |
SBE and DTO classes generated from the same schema identify the same platform data type. One application can subscribe with a DTO topic while another uses the SBE decoder for the same published data. Therefore the following two topics are equivalent:
Topic dtoTopic = Topics.create(SampleMessageDto.class, Topic.SOURCE_WILDCARD, "samples", "sample-1");
Topic sbeTopic = Topics.create(SampleMessageDecoder.class, Topic.SOURCE_WILDCARD, "samples", "sample-1");
Wildcards
Wildcards can be used when subscribing.
| Wildcard | Meaning |
|---|---|
Topic.SOURCE_WILDCARD | Match any source. |
Topic.GROUP_WILDCARD | Match any group. |
Topic.ID_WILDCARD | Match any id. |
// match any SampleMessage where the group = "sample"
Topic topic = Topics.create(
SampleMessageDto.class,
Topic.SOURCE_WILDCARD,
"sample",
Topic.ID_WILDCARD);