class AlarmProvider implements SubscriberProvider {

    private final EventBus eventBus;

    public AlarmProvider(EventBus eventBus) {
        this.eventBus = eventBus;
    }

    @Override
    public String getId() {
        return "alarm";
    }

    @Override
    public String getName() {
        return "告警";
    }

    @Override
    public ConfigMetadata getConfigMetadata() {
        return new DefaultConfigMetadata()
            .add("alarmConfigId", "告警规则", "告警规则,支持通配符:*", StringType.GLOBAL);
    }

    @Override
    public Mono<Subscriber> createSubscriber(String id, Authentication authentication, Map<String, Object> config) {

        String topic = Topics.alarm("*", "*", getAlarmId(config));

        return Mono.just(locale -> createSubscribe(locale, id, new String[]{topic})
            //有效期内去重,防止同一个用户所在多个部门推送同一个告警
            .as(FluxUtils.distinct(Notify::getDataId, Duration.ofSeconds(10))));

    }


    protected Mono<Subscriber> doCreateSubscriber(String id,
                                                  Authentication authentication,
                                                  String topic) {<FILL_FUNCTION_BODY>}

    protected String getAlarmId( Map<String, Object> config) {
        ValueObject configs = ValueObject.of(config);
        return configs.getString("alarmConfigId").orElse("*");
    }

    private Flux<Notify> createSubscribe(Locale locale,
                                         String id,
                                         String[] topics) {
        Subscription.Feature[] features = new Subscription.Feature[]{Subscription.Feature.local};
        return Flux
            .defer(() -> this
                .eventBus
                .subscribe(Subscription.of("alarm:" + id, topics, features))
                .map(msg -> {
                    JSONObject json = msg.bodyToJson();
                    return Notify.of(
                        getNotifyMessage(locale, json),
                        //告警记录ID
                        json.getString("id"),
                        System.currentTimeMillis(),
                        "alarm",
                        json
                    );
                }));
    }


    private static String getNotifyMessage(Locale locale, JSONObject json) {

        String message;
        TargetType targetType = TargetType.of(json.getString("targetType"));
        String targetName = json.getString("targetName");
        String alarmName = json.getString("alarmConfigName");
        if (targetType == TargetType.other) {
            message = String.format("[%s]发生告警:[%s]!", targetName, alarmName);
        } else {
            message = String.format("%s[%s]发生告警:[%s]!", targetType.getText(), targetName, alarmName);
        }
        return LocaleUtils.resolveMessage("message.alarm.notify." + targetType.name(), locale, message, targetName, alarmName);
    }

    @Override
    public Flux<PropertyMetadata> getDetailProperties(Map<String, Object> config) {
        //todo 根据配置来获取输出数据
        return Flux.just(
            SimplePropertyMetadata.of("targetType", "告警类型", StringType.GLOBAL),
            SimplePropertyMetadata.of("alarmName", "告警名称", StringType.GLOBAL),
            SimplePropertyMetadata.of("targetName", "目标名称", StringType.GLOBAL)
        );
    }

    @AllArgsConstructor
    @Getter
    enum TargetType {
        device("设备"),
        product("产品"),
        other("其它");

        private final String text;

        public static TargetType of(String name) {
            for (TargetType value : TargetType.values()) {
                if (Objects.equals(value.name(), name)) {
                    return value;
                }
            }
            return TargetType.other;
        }
    }
}

        return Mono.just(locale -> createSubscribe(locale, id, new String[]{topic})
            //有效期内去重,防止同一个用户所在多个部门推送同一个告警
            .as(FluxUtils.distinct(Notify::getDataId, Duration.ofSeconds(10))));
    
<no_super_class>