public boolean publishBeat()

in service/src/main/java/org/apache/fineract/cn/rhythm/service/internal/service/BeatPublisherService.java [133:170]


  public boolean publishBeat(
          final String beatIdentifier,
          final String tenantIdentifier,
          final String applicationIdentifier,
          final LocalDateTime timestamp) {
    final BeatPublish beatPublish = new BeatPublish(beatIdentifier, DateConverter.toIsoString(timestamp));
    logger.info("Attempting publish {} with timestamp {} under user {}.", beatPublish, timestamp, properties.getUser());

    final List<InstanceInfo> applicationsByName = eurekaClient.getApplication(applicationIdentifier).getInstances();
    if (applicationsByName.isEmpty())
      return false;

    final InstanceInfo beatListenerService = applicationsByName.get(0);
    final BeatListener beatListener = apiFactory.create(BeatListener.class, beatListenerService.getHomePageUrl());

    try (final AutoTenantContext ignored = new AutoTenantContext(tenantIdentifier)) {
      final String accessToken;
      try {
        accessToken = applicationAccessTokenService.getAccessToken(
                properties.getUser(), tenantIdentifier);
      }
      catch (final Exception e) {
        logger.warn("Unable to publish beat '{}' to application '{}' for tenant '{}', " +
                "because access token could not be acquired from identity. Exception was {}.",
                beatIdentifier, applicationIdentifier, tenantIdentifier, e);
        return false;
      }
      try (final AutoUserContext ignored2 = new AutoUserContext(properties.getUser(), accessToken)) {
        beatListener.publishBeat(beatPublish);
        return true;
      }
    }
    catch (final Throwable e) {
      logger.warn("Unable to publish beat '{}' to application '{}' (uri: '{}') for tenant '{}' with user '{}'" +
              "because exception was thrown in publish", beatIdentifier, applicationIdentifier,beatListenerService.getHomePageUrl(), tenantIdentifier, properties.getUser(), e);
      return false;
    }
  }