Skip to content

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

Merged
merged 3 commits into from
Aug 3, 2025

Conversation

tcheeric
Copy link
Owner

@tcheeric tcheeric commented Aug 3, 2025

Summary

  • enable Spring Retry on the client module and expose retry configuration
  • convert SpringWebSocketClient to a Spring component with retryable send operations
  • document and test WebSocket retry behaviour

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

Copilot

This comment was marked as outdated.

…pringWebSocketClient.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tcheeric tcheeric requested a review from Copilot August 3, 2025 13:18
Copy link
Contributor

@Copilot Copilot AI left a 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

Comment on lines +31 to +39
@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))
Copy link
Preview

Copilot AI Aug 3, 2025

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.

Suggested change
@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>
@tcheeric tcheeric merged commit 8a76afa into develop Aug 3, 2025
@tcheeric tcheeric deleted the codex/add-spring-retry-and-configure-client branch August 3, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant