【问题标题】:How to upgrade spring boot admin from 1.5 to 2.0如何将 Spring Boot Admin 从 1.5 升级到 2.0
【发布时间】:2021-08-13 01:21:52
【问题描述】:

有没有关于spring boot admin升级的参考指南? 我有一个需要从 1.5 升级到 2.0 的旧版应用程序,但整个 API 已更改并且官方参考指南中的信息为 0。 https://codecentric.github.io/spring-boot-admin/current/

例如,主域类现在似乎是 InstanceEvent,而以前是“应用程序”;但他们持有完全不同的信息。 与“AbstractStatusChangeNotifier”类相同;现在似乎使用 InstanceEvent & Spring webflux...

我更具体的问题是: 如何从 spring boot admin 2.0 获取应用程序信息? 我曾经能够做到这一点;现在不再存在于 api 中。

public class XXXMailNotifier extends AbstractStatusChangeNotifier {

@Override
protected void doNotify(ClientApplicationEvent event) {
    try {
        helper.setText(mailContentGenerator.statusChange(event), true);
    } catch (IOException | MessagingException e) {
        logger.error(e.getMessage());
    }
}

String statusChange(ClientApplicationEvent event) throws IOException {
    ImmutableMap.Builder<String, Object> content = ImmutableMap.<String, Object>builder()
            .put("name", event.getApplication().getName())
            .put("id", event.getApplication().getId())
            .put("healthUrl", event.getApplication().getHealthUrl())
            .put("managementUrl", event.getApplication().getManagementUrl())
            .put("serviceUrl", event.getApplication().getServiceUrl())
            .put("timestamp", DATE_TIME_FORMATTER.print(new LocalDateTime(event.getApplication().getInfo().getTimestamp())));

【问题讨论】:

    标签: spring-boot spring-boot-admin


    【解决方案1】:

    好吧,如果它可以帮助任何人...... 我查看了代码,发现可以从 instance.registration 对象中获取信息。 您可以在下面更改上述内容:

        @Override
    protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
        try {
            MimeMessage message = sender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setSubject(format(subject, environment, pool, instance.getRegistration().getName(), event.getInstance().getValue()));
            helper.setText(mailContentGenerator.statusChange(event, instance, getLastStatus(event.getInstance())), true);
    
        public String statusChange(InstanceEvent event, Instance instance, String lastStatus) throws IOException {
        Registration registration = instance.getRegistration();
        ImmutableMap.Builder<String, Object> content = ImmutableMap.<String, Object>builder()
                .put("name", registration.getName())
                .put("id", instance.getId().getValue())
                .put("healthUrl", registration.getHealthUrl())
                .put("managementUrl", registration.getManagementUrl())
                .put("serviceUrl", registration.getServiceUrl())
                .put("timestamp", DATE_TIME_FORMATTER.print(new LocalDateTime(instance.getStatusTimestamp())));
    

    【讨论】:

      猜你喜欢
      • 2019-09-16
      • 2018-12-20
      • 2023-04-03
      • 2019-02-17
      • 1970-01-01
      • 2019-10-29
      • 2019-05-30
      • 1970-01-01
      • 2020-07-28
      相关资源
      最近更新 更多