Defining Diffusion topic type for source service handlers

Each source service publishes to specified Diffusion topics. If the topic does not exist on the Diffusion server, a new topic of the specified topic type in the service properties of the ServiceHandler will be created. Defining a topic type in source service properties can be done as follows, but it is not mandatory.

    @Override
    public SourceServiceProperties getSourceServiceProperties() throws InvalidConfigurationException {
        return
            newSourceServicePropertiesBuilder()
                .updateMode(UpdateMode.STREAMING)
                .topicType(TopicType.JSON)
                .payloadConverter("$CSV_to_JSON")
                .build();
    }

If defined together with a payload converter, it will also be used to validate that the defined payload converter generates data that is compatible with the topic type.

If a topic type is not defined explicitly, and only a payload converter is defined, the topic type will be inferred from the type of data the converter will produce.

If neither a topic type nor a payload converter is defined, the default value of JSON topic type will be used. This implies the use of the $Object_to_JSON payload converter. Hence, by default, it is expected that the source service handler will publish JSON String data.

If only a topic type is defined, the framework uses the corresponding payload converter to convert the data published by the SourceHandler to the defined topic type. The table below presents the payload converter used implicitly for each Diffusion topic type. See here for details on how these converters operate.

Topic type to payload converter mapping
Topic type Payload converter name

JSON

$Object_to_JSON

STRING

$Object_to_String

INT64

$Object_to_Long

DOUBLE

$Object_to_Double

BINARY

$Object_to_BINARY

The associated topic type will be applied to all services associated with this service handler, unless the user configures the service to publish to a specific topic type.