Skip to content

progfer/http-request-retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Http Request Retry

Example http request with retry and interval control

Version

1.0.0

Tech Stack

  • Java 8
  • Maven >=3
  • HTTPCOMPONENTS - Fluent API - 4.5.8
  • Logback Classic - 1.2.3
  • Junit - 4.11
  • Wiremock - 2.5.1

Roadmap

  • Implement POST method

Create Repeater

        // Runnable mode without return
		Repeater retry = Repeater.builder()
				.delay(2000L)
				.maxAttempts(2)
				.executionErrorMessage(ERROR_MESSAGE)
				.build();
		retry.perform(() -> {
			throw new RetryOperationException(OPERATION_FAILED_MESSAGE);
		});	

        // Callable mode with return
		Repeater retry = Repeater.builder()
				.delay(2000L)
				.maxAttempts(2)
				.executionErrorMessage(ERROR_MESSAGE)
				.build();
		
		String result = retry.perform(() -> "Hi");
		assertEquals("Hi", result);

Create Http Request Retry

		HttpRequestClientRetry hrcr = HttpRequestClientRetry.builder()
				.connectTimeout(5000)
				.socketTimeout(5000)
				.maxAttempts(2)
                .delay(2000) // 2 seconds
				.build();
		
		String result = hrcr.get("http://localhost:8089/countries", ContentType.APPLICATION_JSON.getMimeType());

Running the project

Run all the unit test classes.

$ mvn test

About

Http request retry implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages