pocozh commented on a change in pull request #2670:
URL: https://github.com/apache/incubator-inlong/pull/2670#discussion_r813546045
##########
File path:
inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/sink/PulsarSink.java
##########
@@ -283,21 +291,28 @@ public void diffSetPublish(PulsarClientService
pulsarClientService, Set<String>
* @param originalCluster
* @param endCluster
*/
- public void diffRestartPulsarClient(Set<String> originalCluster,
Set<String> endCluster) {
- if (!originalCluster.equals(endCluster)) {
- logger.info("pulsarConfig has changed, close current
pulsarClientService and restart");
- pulsarClientService.close();
-
- pulsarCluster = configManager.getPulsarUrl2Token();
- configManager.getPulsarConfig().setUrl2token(pulsarCluster);
- pulsarClientService.initCreateConnection(this);
- try {
- initTopicSet(pulsarClientService, new
HashSet<String>(topicProperties.values()));
- } catch (Exception e) {
- logger.info("pulsar sink restart, publish topic fail.", e);
- }
+ public void diffUpdatePulsarClient(PulsarClientService
pulsarClientService, Map<String, String> originalCluster,
+ Map<String, String> endCluster) {
+ MapDifference<String, String> mapDifference =
Maps.difference(originalCluster, endCluster);
+ if (mapDifference.areEqual()) {
+ return;
+ }
+ logger.info("pulsarConfig has changed, close unused url clients and
start new url clients");
+ Map<String, String> needToStart = new HashMap<>();
+ Map<String, String> needToClose = new HashMap<>();
+ needToClose.putAll(mapDifference.entriesOnlyOnLeft());
+ needToStart.putAll(mapDifference.entriesOnlyOnRight());
+ Map<String, MapDifference.ValueDifference<String>> differentToken =
mapDifference.entriesDiffering();
+ for (String url : differentToken.keySet()) {
+ needToClose.put(url, originalCluster.get(url));
+ needToStart.put(url, endCluster.get(url));//token changed
}
+
+ pulsarClientService.updatePulsarClients(this, needToClose, needToStart,
Review comment:
There is a resend mechanism in sendMessage method. If its send operation
is not completed when a pulsar client is closed, current event will be added
into resendQueue to resend.
--
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]