Pil0tXia commented on code in PR #4451:
URL: https://github.com/apache/eventmesh/pull/4451#discussion_r1329844679
##########
eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/SourceWorker.java:
##########
@@ -177,19 +179,30 @@ public void startPollAndSend() {
// todo: convert connectRecord to cloudevent
CloudEvent event = convertRecordToEvent(connectRecord);
Optional<RecordOffsetManagement.SubmittedPosition>
submittedRecordPosition = prepareToUpdateRecordOffset(connectRecord);
- Package sendResult = eventMeshTCPClient.publish(event, 3000);
- if (sendResult.getHeader().getCode() == 0) {
- // publish success
- // commit record
- this.source.commit(connectRecord);
-
submittedRecordPosition.ifPresent(RecordOffsetManagement.SubmittedPosition::ack);
- } else {
- // todo: retry or other strategy
- log.error("{} failed to send record to {}, failed record {}",
this, event.getSubject(), connectRecord);
+ int retryTimes = 0;
+ // retry until MAX_RETRY_TIMES is reached
+ while (retryTimes < MAX_RETRY_TIMES) {
+ try {
+ Package sendResult = eventMeshTCPClient.publish(event,
3000);
+ if (sendResult.getHeader().getCode() == 0) {
+ // publish success
+ // commit record
+ this.source.commit(connectRecord);
+
submittedRecordPosition.ifPresent(RecordOffsetManagement.SubmittedPosition::ack);
+ break;
+ }
+ retryTimes++;
+ log.warn("{} failed to send record to {}, retry times =
{}, failed record {}",
+ this, event.getSubject(), retryTimes,
connectRecord);
+ } catch (Throwable t) {
+ retryTimes++;
+ log.error("{} failed to send record to {}, retry times =
{}, failed record {}, throw {}",
+ this, event.getSubject(), retryTimes,
connectRecord, t.getMessage());
+ }
}
- offsetManagement.awaitAllMessages(5000, TimeUnit.MILLISECONDS);
+ offsetManagement.awaitAllMessages(15000, TimeUnit.MILLISECONDS);
Review Comment:
A reduced timeout value that covers 90% of the timeout cases would be
preferable, instead of waiting for a long time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]