• Distributed Message Service

dms
  1. Help Center
  2. Distributed Message Service
  3. Developer Guide
  4. Code of the Sample Project

Code of the Sample Project

Kafka Producer

DMS Kafka APIs are compatible with native open-source Kafka clients. Compared with native Kafka service code, the sample project code additionally contains a client certificate and simple authentication and security layer (SASL) configuration, which are used for identity authentication and secure communication. To realize smooth migration of producer applications, you only need to import the client certificate and SASL configuration before creating the Kafka Producer without modifying any other Kafka service code.

Code pertaining to client certificate and SASL:

 Properties producerConfig = Config.getProducerConfig();
    producerConfig.put("ssl.truststore.location", Config.getTrustStorePath());
    System.setProperty("java.security.auth.login.config", Config.getSaslConfig());

The code for creating a producer and sending messages does not need to be modified.

Kafka Consumer

DMS Kafka APIs are compatible with native open-source Kafka clients. Compared with native Kafka service code, the sample project code additionally contains a client certificate and SASL configuration, which are used for identity authentication and secure communication. To realize smooth migration of consumer applications, you only need to import the client certificate and SASL configuration before creating the Kafka Consumer without modifying any other Kafka service code.

Code pertaining to client certificate and SASL:

 Properties consumerConfig = Config.getConsumerConfig();
    consumerConfig.put("ssl.truststore.location", Config.getTrustStorePath());
    System.setProperty("java.security.auth.login.config", Config.getSaslConfig());

The code for creating a consumer and consuming messages does not need to be modified.