Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
afanti-open-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
java-ms
afanti-open-api
Commits
45a6eebb
Commit
45a6eebb
authored
Dec 20, 2024
by
王明生
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed: 为BydOpenService添加 ES 连接异常重试逻辑
parent
ee828685
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
BydOpenService.java
...a/com/afanticar/afantiopenapi/service/BydOpenService.java
+23
-2
No files found.
src/main/java/com/afanticar/afantiopenapi/service/BydOpenService.java
View file @
45a6eebb
...
...
@@ -10,16 +10,22 @@ import com.afanticar.afantiopenapi.model.vo.BydXiaoHongShuMemberDayVO;
import
com.afanticar.afantiopenapi.model.vo.BydXiaoHongShuNoteDayVO
;
import
com.afanticar.core.entity.EsBaseQuery
;
import
com.afanticar.core.entity.InnerHits
;
import
com.afanticar.core.exception.ConnectionClosedException
;
import
com.afanticar.core.exception.EsRuntimeException
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.time.LocalDate
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@Slf4j
@Service
public
class
BydOpenService
{
@Resource
...
...
@@ -35,7 +41,7 @@ public class BydOpenService {
@Resource
XiaoHongShuNoteDayMapper
noteDayMapper
;
@
Resource
@
Autowired
XiaoHongShuNoteDocService
noteDocService
;
...
...
@@ -162,7 +168,22 @@ public class BydOpenService {
EsBaseQuery
esQuery
=
new
EsBaseQuery
();
esQuery
.
terms
(
"note_id"
,
noteIds
);
List
<
InnerHits
<
XiaoHongShuNoteDocQTO
>>
searchResult
=
noteDocService
.
search
(
esQuery
).
getHits
().
getHits
();
List
<
InnerHits
<
XiaoHongShuNoteDocQTO
>>
searchResult
;
int
retryCnt
=
0
;
while
(
true
)
{
try
{
searchResult
=
noteDocService
.
search
(
esQuery
).
getHits
().
getHits
();
break
;
}
catch
(
ConnectionClosedException
e
)
{
retryCnt
+=
1
;
if
(
retryCnt
>=
3
){
throw
e
;
}
else
{
// 生成一个简洁的错误日志
log
.
warn
(
this
.
getClass
().
getName
()
+
".fetchNoteDaySnap encountered connection closure exception, retry count:\n"
+
retryCnt
,
e
);
}
}
}
Map
<
String
,
String
>
noteDocs
=
CollectionUtils
.
isNotEmpty
(
searchResult
)
?
searchResult
.
stream
()
.
map
(
InnerHits:
:
getSource
)
.
collect
(
Collectors
.
toMap
(
XiaoHongShuNoteDocQTO:
:
getNoteId
,
XiaoHongShuNoteDocQTO:
:
getDescription
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment