更新时间:2023-06-21 GMT+08:00

使用AuthToken认证

代码样例

本代码只展示AuthToken配置方法,具体消费代码请参考5.5.3、5.5.4章节
package com.huaweicloud.dis.demo.adapter;
import com.huaweicloud.dis.DISConfig;
import com.huaweicloud.dis.adapter.kafka.clients.producer.*;
import com.huaweicloud.dis.adapter.kafka.common.serialization.StringSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;
 
public class DISKafkaProducerDemo
{
    private static final Logger LOGGER = LoggerFactory.getLogger(DISKafkaProducerDemo.class);
 
    public static void main(String[] args)
    {
        // YOU AuthType
        String authtype="authtoken";
        // YOU AuthToken
        String authToken="XXXXXXXX";
        // YOU ProjectId
        String projectId = "YOU_PROJECT_ID";
        // YOU DIS Stream
        String streamName = "YOU_STREAM_NAME";
        // DIS region
        String region = "YOU_Region";
 
        Properties props = new Properties();
        props.setProperty(DISConfig.PROPERTY_AUTH_TYPE,authtype);
        props.setProperty(DISConfig.PROPERTY_AUTH_TOKEN,authToken);
        props.setProperty(DISConfig.PROPERTY_PROJECT_ID, projectId);
        props.setProperty(DISConfig.PROPERTY_REGION_ID, region);
        props.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        
        //doing next...
    }

}