config.ts 5.2 KB
import { FormSchema } from '/@/components/Form';

const PolicyTypeEnum = {
  SEQUENTIAL_BY_ORIGINATOR: 'SEQUENTIAL_BY_ORIGINATOR',
  SEQUENTIAL_BY_TENANT: 'SEQUENTIAL_BY_TENANT',
  SEQUENTIAL: 'SEQUENTIAL',
  BURST: 'BURST',
  BATCH: 'BATCH',
};
const PolicyTypeLabelEnum = {
  SEQUENTIAL_BY_ORIGINATOR: '按发起者顺序处理',
  SEQUENTIAL_BY_TENANT: '按租户顺序处理',
  SEQUENTIAL: '顺序处理',
  BURST: '突发处理',
  BATCH: '批量处理',
};

const ProcessTypeEnum = {
  RETRY_FAILED_AND_TIMED_OUT: 'RETRY_FAILED_AND_TIMED_OUT',
  SKIP_ALL_FAILURES: 'SKIP_ALL_FAILURES',
  SKIP_ALL_FAILURES_AND_TIMED_OUT: 'SKIP_ALL_FAILURES_AND_TIMED_OUT',
  RETRY_ALL: 'RETRY_ALL',
  RETRY_FAILED: 'RETRY_FAILED',
  RETRY_TIMED_OUT: 'RETRY_TIMED_OUT',
};

const ProcessTypeLabelEnum = {
  RETRY_FAILED_AND_TIMED_OUT: '失败与超时重试',
  SKIP_ALL_FAILURES: '跳过所有失败',
  SKIP_ALL_FAILURES_AND_TIMED_OUT: '跳过所有失败和超时',
  RETRY_ALL: '全部重试',
  RETRY_FAILED: '失败重试',
  RETRY_TIMED_OUT: '超时重试',
};

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true,
    rules: [
      {
        pattern: /^[A-Za-z0-9._-]*$/,
        message: "不能包含ASCII字母数字以外的字符, '.', '_' 和 '-'等",
      },
      {
        required: true,
      },
    ],
    slot: 'nameSlot',
  },
  {
    field: 'disabled',
    label: '',
    component: 'Checkbox',
    ifShow: false,
  },
  {
    // 用于判断名称是否是唯一的
    field: 'nameOnly',
    label: '',
    defaultValue: true,
    component: 'Checkbox',
    ifShow: false,
  },
  {
    field: 'topic',
    label: '',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'customProperties',
    label: '自定义属性',
    component: 'Input',
    helpMessage: [
      '自定义队列(主题)创建属性,例如:retention.ms:604800000;retention.bytes:1048576000',
    ],
  },
  {
    field: 'description',
    label: '说明',
    component: 'InputTextArea',
    helpMessage: ['此文本将显示在队列说明中,而不是所选策略中'],
  },
];

export const submitStrategySchema: FormSchema[] = [
  {
    field: 'type',
    label: '策略类型',
    component: 'Select',
    helpMessage: [
      '按发起者顺序处理:在确认设备A的前一条消息之前,不会提交设备A的新消息',
      '按租户顺序处理:在确认租户A的前一条消息之前,不会提交租户A的新消息',
      '顺序处理:在确认前一条消息之前,不会提交新消息',
      '突发处理:所有消息都按到达顺序提交到规则链',
      '批量处理:在确认前一批消息之前,不会提交新批',
    ],
    defaultValue: PolicyTypeEnum.BURST,
    componentProps: {
      options: Object.keys(PolicyTypeLabelEnum).map((item) => ({
        label: PolicyTypeLabelEnum[item],
        value: PolicyTypeEnum[item],
      })),
    },
  },
  {
    field: 'batchSize',
    label: '批量处理大小',
    required: true,
    component: 'InputNumber',
    ifShow: ({ model }) => model.type === PolicyTypeEnum.BATCH,
  },
];

export const processingStrategySchema: FormSchema[] = [
  {
    field: 'type',
    label: '处理类型',
    component: 'Select',
    colProps: { span: 24 },
    required: true,
    componentProps: {
      options: Object.keys(ProcessTypeLabelEnum).map((item) => ({
        label: ProcessTypeLabelEnum[item],
        value: ProcessTypeEnum[item],
      })),
    },
    helpMessage: [
      '失败与超时重试:重试处理包重所有失败和超时的消息',
      '跳过所有失败:忽略所有失败',
      '跳过所有失败和超时:忽略所有失败和超时',
      '全部重试:重试处理包中的所有消息',
      '失败重试:重试处理包重的所有失败消息',
      '超时重试:重试处理包中的所有超时消息',
    ],
    defaultValue: ProcessTypeEnum.SKIP_ALL_FAILURES,
  },
  {
    field: 'retries',
    label: '重试次数(0-无限制)',
    required: true,
    component: 'InputNumber',
    colProps: { span: 12 },
  },

  {
    field: 'failurePercentage',
    label: '跳过重试的失败消息百分比',
    required: true,
    component: 'InputNumber',
    colProps: { span: 12 },
  },
  {
    field: 'pauseBetweenRetries',
    label: '重试间隔(秒)',
    required: true,
    component: 'InputNumber',
    colProps: { span: 12 },
  },
  {
    field: 'maxPauseBetweenRetries',
    label: '最大重试间隔(秒)',
    required: true,
    component: 'InputNumber',
    colProps: { span: 12 },
  },
];

export const pollingSettingsSchema: FormSchema[] = [
  {
    field: 'pollInterval',
    label: '轮询间隔',
    required: true,
    colProps: { span: 12 },
    component: 'InputNumber',
  },
  {
    field: 'partitions',
    label: '分区',
    required: true,
    colProps: { span: 12 },
    component: 'InputNumber',
  },
  {
    field: 'consumerPerPartition',
    label: '每个分区消费者单独轮询消息',
    required: true,
    colProps: { span: 12 },
    component: 'Checkbox',
  },
  {
    field: 'packProcessingTimeout',
    label: '处理超时(毫秒)',
    required: true,
    colProps: { span: 12 },
    component: 'InputNumber',
  },
];