RobertIndie commented on code in PR #1210:
URL: https://github.com/apache/pulsar-client-go/pull/1210#discussion_r1610912960
##########
pulsar/internal/connection.go:
##########
@@ -928,6 +937,51 @@ func (c *connection) handleCloseProducer(closeProducer
*pb.CommandCloseProducer)
}
}
+func (c *connection) getMigratedBrokerServiceURL(commandTopicMigrated
*pb.CommandTopicMigrated) string {
+ if c.tlsOptions == nil {
+ if commandTopicMigrated.GetBrokerServiceUrl() != "" {
+ return commandTopicMigrated.GetBrokerServiceUrl()
+ }
+ } else if commandTopicMigrated.GetBrokerServiceUrlTls() != "" {
+ return commandTopicMigrated.GetBrokerServiceUrlTls()
+ }
+ return ""
+}
+
+func (c *connection) handleTopicMigrated(commandTopicMigrated
*pb.CommandTopicMigrated) {
+ resourceID := commandTopicMigrated.GetResourceId()
+ migratedBrokerServiceURL :=
c.getMigratedBrokerServiceURL(commandTopicMigrated)
+ if migratedBrokerServiceURL == "" {
+ c.log.Warnf("Failed to find the migrated broker url for
resource: %s, migratedBrokerUrl: %s, migratedBrokerUrlTls:%s",
+ resourceID,
+ commandTopicMigrated.GetBrokerServiceUrl(),
+ commandTopicMigrated.GetBrokerServiceUrlTls())
+ return
+ }
+ if commandTopicMigrated.ResourceType.Number() == 0 {
Review Comment:
Can we use the const value `pb.CommandTopicMigrated_Producer` here?
##########
pulsar/internal/connection.go:
##########
@@ -928,6 +937,51 @@ func (c *connection) handleCloseProducer(closeProducer
*pb.CommandCloseProducer)
}
}
+func (c *connection) getMigratedBrokerServiceURL(commandTopicMigrated
*pb.CommandTopicMigrated) string {
+ if c.tlsOptions == nil {
+ if commandTopicMigrated.GetBrokerServiceUrl() != "" {
+ return commandTopicMigrated.GetBrokerServiceUrl()
+ }
+ } else if commandTopicMigrated.GetBrokerServiceUrlTls() != "" {
+ return commandTopicMigrated.GetBrokerServiceUrlTls()
+ }
+ return ""
+}
+
+func (c *connection) handleTopicMigrated(commandTopicMigrated
*pb.CommandTopicMigrated) {
+ resourceID := commandTopicMigrated.GetResourceId()
+ migratedBrokerServiceURL :=
c.getMigratedBrokerServiceURL(commandTopicMigrated)
+ if migratedBrokerServiceURL == "" {
+ c.log.Warnf("Failed to find the migrated broker url for
resource: %s, migratedBrokerUrl: %s, migratedBrokerUrlTls:%s",
+ resourceID,
+ commandTopicMigrated.GetBrokerServiceUrl(),
+ commandTopicMigrated.GetBrokerServiceUrlTls())
+ return
+ }
+ if commandTopicMigrated.ResourceType.Number() == 0 {
+ c.listenersLock.RLock()
+ producer, ok := c.listeners[resourceID]
+ c.listenersLock.RUnlock()
+ if ok {
+
producer.SetRedirectedClusterURI(migratedBrokerServiceURL)
+ c.log.Infof("producerID:{%d} migrated to
RedirectedClusterURI:{%s}",
+ resourceID, migratedBrokerServiceURL)
+ } else {
+ c.log.WithField("producerID", resourceID).Warn("Failed
to SetRedirectedClusterURI")
+ }
+ } else {
+ consumer, ok := c.consumerHandler(resourceID)
Review Comment:
Can we also register the consumer as a listener? This way, we won't need two
separate logic.
--
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]