coolbeevip commented on a change in pull request #394: [SCB 1128] Omega 
discovers alpha service from eureka
URL: https://github.com/apache/servicecomb-pack/pull/394#discussion_r250281865
 
 

 ##########
 File path: 
omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaConfig.java
 ##########
 @@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Get the access address of Alpah Server from Eureka Server
+ * Turn this feautre on by set alpha.cluster.register.type=spring-cloud
+ * First omega gets the Alpha address from Eureka with 
${alpha.cluster.serviceId}
+ * If omega can't get it in Eureka then use ${alpha.cluster.address}
+ */
+package org.apache.servicecomb.pack.omega.spring.cloud;
+
+import com.google.common.collect.ImmutableList;
+import com.netflix.discovery.EurekaClientConfig;
+import org.apache.servicecomb.pack.omega.connector.grpc.AlphaClusterConfig;
+import org.apache.servicecomb.pack.omega.format.KryoMessageFormat;
+import org.apache.servicecomb.pack.omega.format.MessageFormat;
+import org.apache.servicecomb.pack.omega.transaction.MessageHandler;
+import org.apache.servicecomb.pack.omega.transaction.tcc.TccMessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import 
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Configuration
+@ConditionalOnProperty(value = {"eureka.client.enabled"}, matchIfMissing = 
true)
+@AutoConfigureAfter(value = {EurekaDiscoveryClientConfiguration.class})
+class OmegaSpringEurekaConfig {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(OmegaSpringEurekaConfig.class);
+
+    @Autowired
+    public DiscoveryClient discoveryClient;
+
+    @Autowired
+    public EurekaClientConfig eurekaClientConfig;
+
+    @Bean(name = {"alphaClusterEurekaConfig"})
+    @ConditionalOnProperty(name = "alpha.cluster.register.type", havingValue = 
"spring-cloud")
+    AlphaClusterConfig alphaClusterEurekaConfig(
 
 Review comment:
   Maybe define an object AlphaClusterAddress, Attribute contains Alpha's 
address, registry center information...
   
   Add AlphaClusterAddress to the parameters of AlphaClusterConfig
   ```java
     AlphaClusterConfig alphaClusterConfig(
         @Value("${alpha.cluster.address:localhost:8080}") String[] addresses,
         @Value("${alpha.cluster.ssl.enable:false}") boolean enableSSL,
         @Value("${alpha.cluster.ssl.mutualAuth:false}") boolean mutualAuth,
         @Value("${alpha.cluster.ssl.cert:client.crt}") String cert,
         @Value("${alpha.cluster.ssl.key:client.pem}") String key,
         @Value("${alpha.cluster.ssl.certChain:ca.crt}") String certChain,
         @Lazy AlphaClusterAddress alphaClusterAddress,
         @Lazy MessageHandler handler,
         @Lazy TccMessageHandler tccMessageHandler) {
      ...
   }
   ```
   Define an default AlphaClusterAddress Bean in OmegaSpringConfig,it's Null
   Define an default AlphaClusterAddress Bean in OmegaSpringEurekaConfig,it's 
from Eureka
   
   use this AlphaClusterAddress if it is not empty, otherwise use the default 
${alpha.cluster.address address}
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to