index.ts 5.01 KB
import { FormSchema } from '/@/components/Form';

/**
 * Kafka表单相关默认值配置
 */
class KafkaFormPartialConfig {
  static topicPattern = 'my-topic'; //消息主题默认值
  static bootstrapServers = 'localhost:9092'; //服务器
  static retries = 0; //重连次数
  static batchSize = 16384; //生产者并发
  static linger = 0; //缓存时间
  static bufferMemory = 33554432; //最大缓存
  static acks = '-1'; //响应码
  static keySerializer = 'org.apache.kafka.common.serialization.StringSerializer'; //键序列化
  static valueSerializer = 'org.apache.kafka.common.serialization.StringSerializer'; //值序列化
  static kafkaHeadersCharset = 'UTF-8'; //字符集

  //acks Select options配置
  static getAcks() {
    return [
      { label: 'all', value: 'all' },
      { label: '-1', value: '-1' },
      { label: '0', value: '0' },
      { label: '1', value: '1' },
    ];
  }
  //kafkaHeadersCharset Select options配置
  static getkafkaHeadersCharset() {
    return [
      { label: 'US-ASCII', value: 'US' },
      { label: 'ISO-8859-1', value: 'ISO-8859-1' },
      { label: 'UTF-8', value: 'UTF-8' },
      { label: 'UTF-16BE', value: 'UTF-16BE' },
      { label: 'UTF-16LE', value: 'UTF-16LE' },
      { label: 'UTF-16', value: 'UTF-16' },
    ];
  }
}

export const modelKafkaForm: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    colProps: { span: 12 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入名称',
    },
  },
  {
    field: 'topicPattern',
    label: '消息主题',
    colProps: { span: 12 },
    required: true,
    component: 'Input',
    defaultValue: KafkaFormPartialConfig.topicPattern,
    componentProps: {
      maxLength: 255,
      placeholder: '请输入消息主题',
    },
  },
  {
    field: 'bootstrapServers',
    label: '服务器',
    colProps: { span: 12 },
    component: 'Input',
    defaultValue: KafkaFormPartialConfig.bootstrapServers,
    required: true,
    componentProps: {
      maxLength: 255,
      placeholder: 'localhost:9092',
    },
  },
  {
    field: 'retries',
    label: '重连次数',
    colProps: { span: 12 },
    component: 'InputNumber',
    defaultValue: KafkaFormPartialConfig.retries,
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'batchSize',
    label: '生产者并发',
    colProps: { span: 12 },
    component: 'InputNumber',
    defaultValue: KafkaFormPartialConfig.batchSize,
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'linger',
    label: '缓存时间',
    colProps: { span: 12 },
    component: 'InputNumber',
    defaultValue: KafkaFormPartialConfig.linger,
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'bufferMemory',
    label: '最大缓存',
    colProps: { span: 12 },
    component: 'InputNumber',
    defaultValue: KafkaFormPartialConfig.bufferMemory,
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'acks',
    component: 'Select',
    label: '响应码',
    colProps: { span: 12 },
    defaultValue: KafkaFormPartialConfig.acks,
    componentProps: {
      placeholder: '请选择响应码',
      options: KafkaFormPartialConfig.getAcks(),
    },
  },
  {
    field: 'keySerializer',
    label: '键序列化',
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    defaultValue: KafkaFormPartialConfig.keySerializer,
    componentProps: {
      maxLength: 255,
      placeholder: 'org.apache.kafka.common.serialization.StringSerializer',
    },
  },
  {
    field: 'valueSerializer',
    label: '值序列化',
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    defaultValue: KafkaFormPartialConfig.valueSerializer,
    componentProps: {
      maxLength: 255,
      placeholder: 'org.apache.kafka.common.serialization.StringSerializer',
    },
  },
  {
    field: 'otherProperties',
    label: '其他属性',
    colProps: { span: 24 },
    component: 'JAddInput',
  },
  {
    field: 'addMetadataKeyValuesAsKafkaHeaders',
    label: '是否启用',
    colProps: { span: 12 },
    component: 'Checkbox',
    renderComponentContent: '将消息的元数据以键值对的方式添加到Kafka消息头中',
  },
  {
    field: 'kafkaHeadersCharset',
    component: 'Select',
    label: '字符集',
    required: true,
    colProps: { span: 12 },
    defaultValue: KafkaFormPartialConfig.kafkaHeadersCharset,
    componentProps: {
      placeholder: '请选择字符集编码',
      options: KafkaFormPartialConfig.getkafkaHeadersCharset(),
    },
    ifShow: ({ values }) => {
      return !!values.addMetadataKeyValuesAsKafkaHeaders;
    },
  },
  {
    field: 'description',
    label: '说明',
    colProps: { span: 24 },
    component: 'InputTextArea',
    componentProps: {
      maxLength: 255,
      rows: 4,
      placeholder: '请输入说明',
    },
  },
];