You can use a topic configuration for a consumer to specify the deserialization of messages for a topic.

The methods SetBodyDeserializer() and SetBodyDeserializerCodePage() can be used. You cannot set other Kafka properties on a per topic basis for a consumer.

In the following example code, two topic configurations are used, one for a customer and one for an order. Each topic configuration has its own custom deserializer.

using OpenEdge.Messaging.Kakfa.Acks.

// Retrieve instance of consumer builder
var ConsumerBuilder cb = ConsumerBuilder:Create("progress-kafka").
 
// Fetch the topic configuration builder
var TopicConfigurationBuilder topicConfigBuilder = cb:TopicConfigurationBuilder.
 
var ITopicConfiguration customerTopicConfiguration.
var ITopicConfiguration orderTopicConfiguration.
var IConsumer consumer.
 
// Assign the topic name to identify the destination to which the configuration applies
topicConfigBuilder:SetTopicName("customer").
 
// Assign the body deserializer for the customer
topicConfigBuilder:SetBodyDeserializer(new CustomerDeserializer()).
 
// Create a topic configuration for customer
customerTopicConfiguration = topicConfigBuilder:Build().
 
// Provide the freshly built customer topic configuration to the consumer builder
cb:AddTopicConfiguration(customerTopicConfiguration).


// Assign a separate deserializer for the order topic
topicConfigBuilder:SetBodyDeserializer(new OrderDeserializer()).
topicConfigBuilder:SetTopicName("order").

orderTopicConfiguration = topicConfigBuilder:Build().
cb:AddTopicConfiguration(orderTopicConfiguration).

//Subscribe to topics
cb:AddSubscription("customer").
cb:AddSubscription("order").

// When the configuration is complete, request the builder to create the consumer
consumer = cb:Build().


// Now read the 2 messages, one from each topic
msgCount = 0.
repeat while msgCount < 2:
   // request a record
   record = consumer:Poll(1000).
    if valid-object(record) then do;:
        message record:TopicName.
       msgCount += 1.
    end.
end.

delete object consumer.