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
Add Cache for event writer. #1032
Add Cache for event writer. #1032
Conversation
@Technoboy-:Thanks for your contribution. For this PR, do we need to update docs? |
@@ -112,15 +125,14 @@ public CompletableFuture<Void> sendPSKEvent(PSKEvent event) { | |||
|
|||
@Override | |||
public CompletableFuture<Void> sendEvent(MqttEvent event) { | |||
CompletableFuture<SystemTopicClient.Writer<MqttEvent>> writerFuture = systemTopicClient.newWriterAsync(); | |||
CompletableFuture<SystemTopicClient.Writer<MqttEvent>> writerFuture = writerCaches.get(WRITER_KEY); | |||
return writerFuture.thenCompose(writer -> { | |||
CompletableFuture<MessageId> writeFuture = ActionType.DELETE.equals(event.getActionType()) | |||
? writer.deleteAsync(event.getKey(), event) : writer.writeAsync(event.getKey(), event); | |||
writeFuture.whenComplete((__, ex) -> { | |||
if (ex != null) { | |||
log.error("[{}] send event error.", SYSTEM_EVENT_TOPIC, ex); |
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 should be invalidated when the writer has any exceptions.
Motivation
Add cache for the event writer to avoid creating event writer every time.
Modifications
Describe the modifications you've done.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Documentation
Check the box below.
Need to update docs?
doc-required
(If you need help on updating docs, create a doc issue)
no-need-doc
(Please explain why)
doc
(If this PR contains doc changes)