-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add retry to websocket client #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…pringWebSocketClient.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds retry functionality to the WebSocket client by integrating Spring Retry capabilities. The changes enable automatic retries for failed WebSocket send operations with configurable backoff strategies.
- Convert SpringWebSocketClient to a Spring component with retryable send methods
- Add Spring Retry configuration and dependencies
- Update existing code to accommodate the new constructor signature
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
SpringWebSocketClient.java | Convert to Spring component with @retryable annotations and dependency injection |
RetryConfig.java | New configuration class to enable Spring Retry |
SpringWebSocketClientTest.java | New test class to verify retry behavior with mock WebSocket client |
pom.xml | Add Spring Retry and Spring Test dependencies |
Multiple integration test files | Update constructor calls to accommodate new signature |
WebSocketClientHandler.java | Update constructor calls for new SpringWebSocketClient signature |
Documentation files | Document the new retry behavior |
Comments suppressed due to low confidence (1)
nostr-java-client/src/test/java/nostr/client/springwebsocket/SpringWebSocketClientTest.java:78
- The test method name 'recoverAfterMaxAttempts' is misleading. The test verifies that an exception is thrown after max attempts, not that recovery occurs. Consider renaming to 'throwsExceptionAfterMaxAttempts' or 'failsAfterMaxRetries'.
@Test
nostr-java-client/src/main/java/nostr/client/springwebsocket/SpringWebSocketClient.java
Outdated
Show resolved
Hide resolved
@Retryable(value = IOException.class, maxAttempts = 3, | ||
backoff = @Backoff(delay = 500, multiplier = 2)) | ||
@SneakyThrows | ||
public List<String> send(@NonNull BaseMessage eventMessage) { | ||
return webSocketClientIF.send(eventMessage.encode()); | ||
} | ||
|
||
@Retryable(value = IOException.class, maxAttempts = 3, | ||
backoff = @Backoff(delay = 500, multiplier = 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retry configuration (maxAttempts = 3, delay = 500, multiplier = 2) is duplicated across both send methods. Consider extracting these values as constants or configurable properties to avoid duplication and improve maintainability.
@Retryable(value = IOException.class, maxAttempts = 3, | |
backoff = @Backoff(delay = 500, multiplier = 2)) | |
@SneakyThrows | |
public List<String> send(@NonNull BaseMessage eventMessage) { | |
return webSocketClientIF.send(eventMessage.encode()); | |
} | |
@Retryable(value = IOException.class, maxAttempts = 3, | |
backoff = @Backoff(delay = 500, multiplier = 2)) | |
@NostrRetryable | |
@SneakyThrows | |
public List<String> send(@NonNull BaseMessage eventMessage) { | |
return webSocketClientIF.send(eventMessage.encode()); | |
} | |
@NostrRetryable |
Copilot uses AI. Check for mistakes.
…pringWebSocketClient.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Testing
mvn -q verify
(fails: Could not find a valid Docker environment)Network Access
https://www.slf4j.org/codes.html#noProviders
https://chatgpt.com/codex/tasks/task_b_688f585beab48331b2a0bf186f6ad4ad