-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feature:Support_reconnect_backoff_interface #155
Merged
crossoverJie
merged 10 commits into
crossoverJie:master
from
cmgyqjj:feature_Support_reconnect_backoff_interface
Sep 26, 2024
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6186f0d
feature:Support_reconnect_backoff_interface
cmgyqjj 5f3d1b0
feature:Support_reconnect_backoff_interface
cmgyqjj 92f7cb8
feature:Support_reconnect_backoff_interface
cmgyqjj 3446b87
Merge branch 'master' into feature_Support_reconnect_backoff_interface
crossoverJie 50eccb0
feature_Support_reconnect_backoff_interface
cmgyqjj 6fcf621
Merge branch 'master' into feature_Support_reconnect_backoff_interface
cmgyqjj 22429e1
feature_Support_reconnect_backoff_interface
cmgyqjj fd29769
feature_Support_reconnect_backoff_interface
cmgyqjj 5eabda1
Update cim-client/src/test/resources/application.yaml
cmgyqjj 7197188
Update cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/i…
cmgyqjj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/io/backoff/BackoffStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.crossoverjie.cim.client.sdk.io.backoff; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author:qjj | ||
* @create: 2024-09-21 12:16 | ||
* @Description: backoff strategy interface | ||
*/ | ||
|
||
public interface BackoffStrategy { | ||
/** | ||
* @return the backoff time in milliseconds | ||
*/ | ||
long nextBackoff(); | ||
|
||
/** | ||
* Run the backoff strategy | ||
* @throws InterruptedException | ||
*/ | ||
default void runBackoff() throws InterruptedException { | ||
TimeUnit.SECONDS.sleep(nextBackoff()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/io/backoff/RandomBackoff.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.crossoverjie.cim.client.sdk.io.backoff; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author:qjj | ||
* @create: 2024-09-21 12:22 | ||
* @Description: random backoff strategy | ||
*/ | ||
|
||
public class RandomBackoff implements BackoffStrategy { | ||
|
||
@Override | ||
public long nextBackoff() { | ||
int random = (int) (Math.random() * 7 + 3); | ||
return random; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import com.crossoverjie.cim.client.sdk.Client; | ||
import com.crossoverjie.cim.client.sdk.Event; | ||
import com.crossoverjie.cim.client.sdk.impl.ClientConfigurationData; | ||
import com.crossoverjie.cim.client.sdk.io.backoff.RandomBackoff; | ||
import com.crossoverjie.cim.client.service.MsgLogger; | ||
import com.crossoverjie.cim.client.service.ShutDownSign; | ||
import com.crossoverjie.cim.client.service.impl.MsgCallBackListener; | ||
|
@@ -61,6 +62,7 @@ public Client buildClient(@Qualifier("callBackThreadPool") ThreadPoolExecutor ca | |
.okHttpClient(okHttpClient) | ||
.messageListener(new MsgCallBackListener(msgLogger)) | ||
.callbackThreadPool(callbackThreadPool) | ||
.backoffStrategy(appConfiguration.getBackoffStrategy()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the |
||
.build(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
spring: | ||
application: | ||
name: cim-client | ||
|
||
# web port | ||
server: | ||
port: 8082 | ||
|
||
logging: | ||
level: | ||
root: error | ||
|
||
# enable swagger | ||
springdoc: | ||
swagger-ui: | ||
enabled: true | ||
|
||
# log path | ||
cim: | ||
msg: | ||
logger: | ||
path: /opt/logs/cim/ | ||
route: | ||
url: http://localhost:8083 # route url suggested that this is Nginx address | ||
user: # cim userId and userName | ||
id: 1725714450795 | ||
userName: cj4 | ||
callback: | ||
thread: | ||
queue: | ||
size: 2 | ||
pool: | ||
size: 2 | ||
heartbeat: | ||
time: 60 # cim heartbeat time (seconds) | ||
reconnect: | ||
count: 3 | ||
spring: | ||
application: | ||
name: cim-client | ||
|
||
# web port | ||
server: | ||
port: 8082 | ||
|
||
logging: | ||
level: | ||
root: error | ||
|
||
# enable swagger | ||
springdoc: | ||
swagger-ui: | ||
enabled: true | ||
|
||
# log path | ||
cim: | ||
msg: | ||
logger: | ||
path: /opt/logs/cim/ | ||
route: | ||
url: http://localhost:8083 # route url suggested that this is Nginx address | ||
user: # cim userId and userName | ||
id: 1725714450795 | ||
userName: cj4 | ||
callback: | ||
thread: | ||
queue: | ||
size: 2 | ||
pool: | ||
size: 2 | ||
heartbeat: | ||
time: 60 # cim heartbeat time (seconds) | ||
reconnect: | ||
count: 3 | ||
backoff: | ||
strategy: com.crossoverjie.cim.client.sdk.io.backoff.RandomBackoff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It is recommended to use the interface directly so that reflection is not needed.