The Webhook Sender Application is designed to send webhooks with a robust retry mechanism using an exponential back-off strategy. This ensures reliable delivery of webhooks even in the face of temporary network issues or endpoint unavailability.
Follow these steps to set up and run the application:
-
Ensure Prerequisites Are Installed:
-
Build the Project:
- Open your terminal and navigate to the project directory.
- Run the following command to compile the Kotlin files and create a JAR file:
./gradlew clean build jar
-
Prepare for Execution:
- Ensure that the
webhooks.txtfile is located in thebuild/libsdirectory. This file should contain the list of webhooks to be sent.
- Ensure that the
-
Run the Application:
- Execute the following command to start the application:
java -jar build/libs/WebhookSender-1.0-SNAPSHOT.jar
- Execute the following command to start the application:
You can verify the functionality of the application by running tests:
-
Execute Tests:
- Run the following command to execute the test suite:
./gradlew test
- Run the following command to execute the test suite:
-
View Test Reports:
- After the tests complete, navigate to
build/reports/tests/test. - Open
index.htmlin your browser to view the detailed test report.
- After the tests complete, navigate to
- The strategy is implemented using the Strategy pattern, with
ExponentialBackoffStrategyas the core implementation. ExponentialBackoffStrategycontains the logic for exponential retries and is configurable through its constructor, allowing easy adjustments to retry parameters.- The
WebhookSenderclass leverages theBackoffStrategyinterface for retry logic and theNetworkClientinterface for HTTP requests. - A
ThreadUtilsinterface is used to simulate delays in tests, speeding up test execution.
- The application tracks failures for each endpoint within the
ExponentialBackoffStrategyclass. - Sending attempts to an endpoint are halted after five consecutive failures to prevent further unnecessary retries.
- Utilizes a
ConcurrentLinkedQueueto ensure thread-safe operations. - Simple in-memory queue without persistence (trade-off for simplicity).
- Uses HTTPS for secure communication (assuming URLs in the input file use HTTPS).
- Does not implement authentication for simplicity, but in a real-world scenario, you'd want to add authentication mechanisms.
- Catches and logs exceptions during webhook sending.
- Continues processing the queue even if individual webhooks fail.
- Simplicity over Scalability: This implementation works well for moderate loads but may not scale to very high volumes.
- Lack of Persistence: Webhooks are lost if the application crashes (could be improved with a persistent queue).
- Synchronous Processing: Each webhook is processed sequentially, which may not be optimal for high-throughput scenarios.