Highly optimize topic name
This commit is contained in:
parent
344be2b320
commit
aa887ba954
@ -34,10 +34,10 @@ public class KafkaProducer {
|
||||
sender = KafkaSender.create(senderOptions.maxInFlight(1024));
|
||||
}
|
||||
|
||||
public Mono<Void> sendMessages(long userId, Flux<ClientBoundEvent> eventsFlux) {
|
||||
public Mono<Void> sendMessages(UserTopic userId, Flux<ClientBoundEvent> eventsFlux) {
|
||||
return eventsFlux
|
||||
.<SenderRecord<Integer, ClientBoundEvent, Integer>>map(event -> SenderRecord.create(new ProducerRecord<>(
|
||||
"tdlib.event.%d".formatted(userId),
|
||||
userId.getTopic(),
|
||||
event
|
||||
), null))
|
||||
.transform(sender::send)
|
||||
|
@ -75,6 +75,7 @@ public abstract class ReactiveApiPublisher {
|
||||
|
||||
private final AtomicReference<State> state = new AtomicReference<>(new State(LOGGED_OUT));
|
||||
protected final long userId;
|
||||
protected final UserTopic userTopic;
|
||||
protected final long liveId;
|
||||
private final String dynamicIdResolveSubject;
|
||||
|
||||
@ -90,6 +91,7 @@ public abstract class ReactiveApiPublisher {
|
||||
this.eventService = atomix.getEventService();
|
||||
this.resultingEventTransformerSet = resultingEventTransformerSet;
|
||||
this.userId = userId;
|
||||
this.userTopic = new UserTopic(userId);
|
||||
this.liveId = liveId;
|
||||
this.dynamicIdResolveSubject = SubjectNaming.getDynamicIdResolveSubject(userId);
|
||||
this.rawTelegramClient = ClientManager.createReactive();
|
||||
@ -197,7 +199,7 @@ public abstract class ReactiveApiPublisher {
|
||||
// Buffer requests to avoid halting the event loop
|
||||
.onBackpressureBuffer();
|
||||
|
||||
kafkaProducer.sendMessages(userId, messagesToSend).subscribeOn(Schedulers.parallel()).subscribe();
|
||||
kafkaProducer.sendMessages(userTopic, messagesToSend).subscribeOn(Schedulers.parallel()).subscribe();
|
||||
|
||||
publishedResultingEvents
|
||||
// Obtain only cluster-bound events
|
||||
|
14
src/main/java/it/tdlight/reactiveapi/UserTopic.java
Normal file
14
src/main/java/it/tdlight/reactiveapi/UserTopic.java
Normal file
@ -0,0 +1,14 @@
|
||||
package it.tdlight.reactiveapi;
|
||||
|
||||
public class UserTopic {
|
||||
|
||||
private final String value;
|
||||
|
||||
public UserTopic(long userId) {
|
||||
value = "tdlib.event.%d".formatted(userId);
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return value;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user