Documentation for a newer release is available. View Latest

Client Library

This section will guide you through how to connect to an external Persistent Scheduler via HTTP. The guide for setting up your Java application with the IPF Persistent Scheduler exposed as an HTTP API is here.

Step 1: Add dependency

Add this to pom.xml:

<dependency>
    <groupId>com.iconsolutions.ipf.core.platform</groupId>
    <artifactId>scheduler-client-connector-http</artifactId>
</dependency>

Step 2: Configure

The API operations have configurable properties, namely the host and the port. The reference configuration provides these as localhost and 8080 respectively. For your implementation you will have to override these properties.

ipf.scheduler.api {
  schedule.request.http.client { (1)
    host = ${ipf.scheduler.api.http.client.host}
    port = ${ipf.scheduler.api.http.client.port}
    endpoint-url = "/api/v1/schedule-job"
  }
  update.request.http.client { (2)
    host = ${ipf.scheduler.api.http.client.host}
    port = ${ipf.scheduler.api.http.client.port}
    endpoint-url = "/api/v1/update-job"
  }
  find.request.http.client { (3)
    host = ${ipf.scheduler.api.http.client.host}
    port = ${ipf.scheduler.api.http.client.port}
    endpoint-url = "/api/v1/find-job-by-id"
  }
  cancel.request.http.client { (4)
    host = ${ipf.scheduler.api.http.client.host}
    port = ${ipf.scheduler.api.http.client.port}
    endpoint-url = "/api/v1/cancel-job"
  }

  http.client { (5)
    host = "localhost"
    port = 8080
  }
}
1 configuration for the schedule-job endpoint
2 configuration for the update-job endpoint
3 configuration for the find-job-by-id endpoint
4 configuration for the cancel-job endpoint
5 convenience reference, if all API endpoints are located on the same host and port then you can override this property set

By default, all host and port properties look at the ipf.scheduler.api.http.client property. This is for convenience so not all host and port properties need to be individually overridden.

Step 3: Wire In Mandatory Spring Beans

You are required to have a Spring Bean present in your Java application of:

  1. com.iconsolutions.ipf.core.messagelogger.MessageLogger

  2. akka.actor.ClassicActorSystemProvider

Step 4: Call the API

Your application is now ready to call the external HTTP API. You do this by using the SchedulerConnectorInterface Spring Bean that was introduced by the Maven dependency in Step 1 and calling the respective methods in the class.

package com.iconsolutions.ipf.core.scheduler.client.connector.http.api;

import com.iconsolutions.ipf.core.platform.api.models.CancelScheduleRequest;
import com.iconsolutions.ipf.core.platform.api.models.JobSpecification;
import com.iconsolutions.ipf.core.platform.api.models.JobSpecificationWithExecutionStatusResponse;
import com.iconsolutions.ipf.core.platform.api.models.ScheduleJobSpecification;

import java.util.Optional;
import java.util.concurrent.CompletionStage;

public interface SchedulerConnectorInterface {

    CompletionStage<JobSpecification> scheduleJob(ScheduleJobSpecification scheduleJobSpecification);

    CompletionStage<Optional<JobSpecification>> cancelJob(CancelScheduleRequest cancelScheduleRequest);

    CompletionStage<Optional<JobSpecification>> updateJob(JobSpecification jobSpecification);

    CompletionStage<Optional<JobSpecificationWithExecutionStatusResponse>> findJobById(String id);

}

For more information on how to schedule your first job, please see Scheduling Your First Job (via HTTP Client Library)