You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2019/01/27 08:02:17 UTC

[servicecomb-pack] branch master updated: [SCB-1128] Omega discovers alpha service from eureka (#394)

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git


The following commit(s) were added to refs/heads/master by this push:
     new 928e9d6  [SCB-1128] Omega discovers alpha service from eureka (#394)
928e9d6 is described below

commit 928e9d65248c211fec09e91ddca0b4b559bc75da
Author: Lei Zhang <co...@gmail.com>
AuthorDate: Sun Jan 27 16:02:13 2019 +0800

    [SCB-1128] Omega discovers alpha service from eureka (#394)
    
    * Add omega instanceid to properties
    
    * Add omega instanceid to properties
    
    * support register to spring cloud eureka server
    
    * support register to spring cloud eureka server
    
    * delete author
    
    * eureka dependency package to move to profile spring-cloud-eureka section
    
    * Omega discovery Alpha Server from Eureka
    
    * Add log information
    
    * Remove useless dependence
    
    * Delete SpringCloudEurekaConfiguration.java
    
    * Add license header
    
    * Code refactoring, deprecated @EnableOmega, Add omega.enabled parameters
    
    * revert upstream/master
    
    * revert upstream/master
    
    * revert upstream/master
    
    * revert upstream/master
    
    * Add license header
    
    * code format
    
    * 修改LOG声明方法LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
    
    * Delet @Import({OmegaSpringConfig.class, TransactionAspectConfig.class})
    
    * add Conditional alpha.cluster.address
    
    * tcc-inventory and tcc-payment set omega.enabled=false
---
 .../pack/demo/inventory/InventoryServiceTest.java  |   5 +-
 .../pack/demo/payment/PaymentServiceTest.java      |   5 +-
 .../connector/grpc/AlphaClusterDiscovery.java      |  88 +++++++++++++++++
 omega/omega-spring-cloud-starter/pom.xml           |  52 ++++++++++
 .../cloud/OmegaSpringEurekaAutoConfiguration.java} |  25 ++---
 .../spring/cloud/OmegaSpringEurekaConfig.java      | 105 +++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   |  17 ++++
 .../servicecomb/pack/omega/spring/EnableOmega.java |   3 +-
 ...mega.java => OmegaSpringAutoConfiguration.java} |  24 ++---
 .../pack/omega/spring/OmegaSpringConfig.java       |  21 ++++-
 .../src/main/resources/META-INF/spring.factories   |  17 ++++
 omega/pom.xml                                      |   1 +
 12 files changed, 323 insertions(+), 40 deletions(-)

diff --git a/demo/tcc-spring-demo/inventory/src/test/java/org/apache/servicecomb/pack/demo/inventory/InventoryServiceTest.java b/demo/tcc-spring-demo/inventory/src/test/java/org/apache/servicecomb/pack/demo/inventory/InventoryServiceTest.java
index 2962992..639cb63 100644
--- a/demo/tcc-spring-demo/inventory/src/test/java/org/apache/servicecomb/pack/demo/inventory/InventoryServiceTest.java
+++ b/demo/tcc-spring-demo/inventory/src/test/java/org/apache/servicecomb/pack/demo/inventory/InventoryServiceTest.java
@@ -33,7 +33,10 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 // Using test profile to avoid the Omega connection
 @ActiveProfiles("test")
-@SpringBootTest(classes = {TestApplication.class})
+@SpringBootTest(classes = {TestApplication.class},
+        properties = {
+                "omega.enabled=false"
+        })
 public class InventoryServiceTest {
   @Autowired
   private InventoryService inventoryService;
diff --git a/demo/tcc-spring-demo/payment/src/test/java/org/apache/servicecomb/pack/demo/payment/PaymentServiceTest.java b/demo/tcc-spring-demo/payment/src/test/java/org/apache/servicecomb/pack/demo/payment/PaymentServiceTest.java
index 3634ed0..878c7db 100644
--- a/demo/tcc-spring-demo/payment/src/test/java/org/apache/servicecomb/pack/demo/payment/PaymentServiceTest.java
+++ b/demo/tcc-spring-demo/payment/src/test/java/org/apache/servicecomb/pack/demo/payment/PaymentServiceTest.java
@@ -37,7 +37,10 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 // Using test profile to avoid the Omega connection
 @ActiveProfiles("test")
-@SpringBootTest(classes = {TestApplication.class})
+@SpringBootTest(classes = {TestApplication.class},
+        properties = {
+                "omega.enabled=false"
+        })
 public class PaymentServiceTest {
   @Autowired
   private PaymentService paymentService;
diff --git a/omega/omega-connector/omega-connector-grpc/src/main/java/org/apache/servicecomb/pack/omega/connector/grpc/AlphaClusterDiscovery.java b/omega/omega-connector/omega-connector-grpc/src/main/java/org/apache/servicecomb/pack/omega/connector/grpc/AlphaClusterDiscovery.java
new file mode 100644
index 0000000..54cd25c
--- /dev/null
+++ b/omega/omega-connector/omega-connector-grpc/src/main/java/org/apache/servicecomb/pack/omega/connector/grpc/AlphaClusterDiscovery.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.pack.omega.connector.grpc;
+
+public class AlphaClusterDiscovery {
+
+    private DiscoveryType discoveryType = DiscoveryType.DEFAULT;;
+
+    private String[] addresses;
+
+    private String discoveryInfo;
+
+    public DiscoveryType getDiscoveryType() {
+        return discoveryType;
+    }
+
+    public void setDiscoveryType(DiscoveryType discoveryType) {
+        this.discoveryType = discoveryType;
+    }
+
+    public String[] getAddresses() {
+        return addresses;
+    }
+
+    public void setAddresses(String[] addresses) {
+        this.addresses = addresses;
+    }
+
+    public String getDiscoveryInfo() {
+        return discoveryInfo;
+    }
+
+    public void setDiscoveryInfo(String discoveryInfo) {
+        this.discoveryInfo = discoveryInfo;
+    }
+
+    public enum DiscoveryType{
+        DEFAULT,SPRING_CLOUD_EUREKA
+    }
+
+    public static final Builder builder(){
+        return new Builder();
+    }
+
+    public static final class Builder {
+        private DiscoveryType discoveryType = DiscoveryType.DEFAULT;;
+        private String[] addresses;
+        private String discoveryInfo;
+
+        public Builder discoveryType(DiscoveryType discoveryType) {
+            this.discoveryType = discoveryType;
+            return this;
+        }
+
+        public Builder discoveryInfo(String discoveryInfo) {
+            this.discoveryInfo = discoveryInfo;
+            return this;
+        }
+
+        public Builder addresses(String[] addresses) {
+            this.addresses = addresses;
+            return this;
+        }
+
+        public AlphaClusterDiscovery build() {
+            AlphaClusterDiscovery alphaClusterDiscovery = new AlphaClusterDiscovery();
+            alphaClusterDiscovery.setDiscoveryType(discoveryType);
+            alphaClusterDiscovery.setAddresses(addresses);
+            alphaClusterDiscovery.setDiscoveryInfo(discoveryInfo);
+            return alphaClusterDiscovery;
+        }
+    }
+}
diff --git a/omega/omega-spring-cloud-starter/pom.xml b/omega/omega-spring-cloud-starter/pom.xml
new file mode 100644
index 0000000..8151c29
--- /dev/null
+++ b/omega/omega-spring-cloud-starter/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>omega</artifactId>
+    <groupId>org.apache.servicecomb.pack</groupId>
+    <version>0.4.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>omega-spring-cloud-starter</artifactId>
+  <name>Pack::Omega::Spring Cloud Starter</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.pack</groupId>
+      <artifactId>omega-spring-tx</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.pack</groupId>
+      <artifactId>omega-format</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.pack</groupId>
+      <artifactId>omega-connector-grpc</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+      <version>${spring.cloud.version}</version>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java b/omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaAutoConfiguration.java
similarity index 55%
copy from omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
copy to omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaAutoConfiguration.java
index 6117d48..516aee7 100644
--- a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
+++ b/omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaAutoConfiguration.java
@@ -15,25 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.pack.omega.spring;
+package org.apache.servicecomb.pack.omega.spring.cloud;
 
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.apache.servicecomb.pack.omega.context.OmegaContext;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 
-import org.apache.servicecomb.pack.omega.transaction.spring.TransactionAspectConfig;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Import({OmegaSpringConfig.class, TransactionAspectConfig.class})
-/**
- * Indicates create the OmegaContext and inject it into the interceptors
- * to pass the transactions id across the application.
- * @see OmegaContext
- */
-public @interface EnableOmega {
+@Configuration
+@Import(OmegaSpringEurekaConfig.class)
+@ConditionalOnProperty(value = {"omega.enabled"}, matchIfMissing = true)
+public class OmegaSpringEurekaAutoConfiguration {
 }
diff --git a/omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaConfig.java b/omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaConfig.java
new file mode 100644
index 0000000..23e3be0
--- /dev/null
+++ b/omega/omega-spring-cloud-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/cloud/OmegaSpringEurekaConfig.java
@@ -0,0 +1,105 @@
+/*
+ * 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-eureka
+ * 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.netflix.discovery.EurekaClientConfig;
+import org.apache.servicecomb.pack.omega.connector.grpc.AlphaClusterDiscovery;
+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 java.util.ArrayList;
+import java.util.List;
+
+@Configuration
+@ConditionalOnProperty(value = {"alpha.cluster.register.type"}, havingValue = "spring-cloud")
+@AutoConfigureAfter(value = {EurekaDiscoveryClientConfiguration.class})
+class OmegaSpringEurekaConfig {
+
+    private static final Logger LOG = LoggerFactory.getLogger(OmegaSpringEurekaConfig.class);
+
+    @Autowired
+    public DiscoveryClient discoveryClient;
+
+    @Autowired
+    public EurekaClientConfig eurekaClientConfig;
+
+    @Bean
+    AlphaClusterDiscovery alphaClusterAddress(
+            @Value("${alpha.cluster.serviceId:servicecomb-alpha-server}") String serviceId,
+            @Value("${alpha.cluster.address:localhost:8080}") String[] addresses) {
+        StringBuffer eurekaServiceUrls = new StringBuffer();
+        String[] zones = eurekaClientConfig.getAvailabilityZones(eurekaClientConfig.getRegion());
+        for (String zone : zones) {
+            eurekaServiceUrls.append(String.format(" [%s]:%s,", zone, eurekaClientConfig.getEurekaServerServiceUrls(zone)));
+        }
+        LOG.info("Eureka address{}", eurekaServiceUrls.toString());
+        String[] alphaAddresses = this.getAlphaAddress(serviceId);
+        if (alphaAddresses.length > 0) {
+            AlphaClusterDiscovery alphaClusterDiscovery = AlphaClusterDiscovery.builder()
+                    .discoveryType(AlphaClusterDiscovery.DiscoveryType.SPRING_CLOUD_EUREKA)
+                    .discoveryInfo(eurekaServiceUrls.toString())
+                    .addresses(alphaAddresses)
+                    .build();
+            return alphaClusterDiscovery;
+        } else {
+            AlphaClusterDiscovery alphaClusterDiscovery = AlphaClusterDiscovery.builder()
+                    .discoveryType(AlphaClusterDiscovery.DiscoveryType.DEFAULT)
+                    .addresses(addresses)
+                    .build();
+            return alphaClusterDiscovery;
+        }
+    }
+
+    private String[] getAlphaAddress(String serviceId) {
+        List<String> alphaAddresses = new ArrayList<>();
+        List<ServiceInstance> serviceInstances = discoveryClient.getInstances(serviceId);
+        boolean foundAlphaServer = Boolean.FALSE;
+        for (ServiceInstance serviceInstance : serviceInstances) {
+            foundAlphaServer = Boolean.TRUE;
+            if (serviceInstance.getMetadata().containsKey(serviceId)) {
+                String alphaAddress = serviceInstance.getMetadata().get(serviceId);
+                alphaAddresses.add(alphaAddress);
+            }
+        }
+        if (foundAlphaServer) {
+            if (alphaAddresses.size() == 0) {
+                LOG.warn("Alpha has been found in Eureka, " +
+                        "but Alpha's registered address information is not found in Eureka instance metadata. " +
+                        "Please check Alpha is configured spring.profiles.active=spring-cloud");
+            }
+        } else {
+            LOG.warn("No Alpha Server {} found in the Eureka", serviceId);
+        }
+        return alphaAddresses.toArray(new String[alphaAddresses.size()]);
+    }
+}
diff --git a/omega/omega-spring-cloud-starter/src/main/resources/META-INF/spring.factories b/omega/omega-spring-cloud-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..7189e0b
--- /dev/null
+++ b/omega/omega-spring-cloud-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.apache.servicecomb.pack.omega.spring.cloud.OmegaSpringEurekaAutoConfiguration
diff --git a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
index 6117d48..1db88ca 100644
--- a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
+++ b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
@@ -29,11 +29,12 @@ import org.apache.servicecomb.pack.omega.transaction.spring.TransactionAspectCon
 
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
-@Import({OmegaSpringConfig.class, TransactionAspectConfig.class})
 /**
  * Indicates create the OmegaContext and inject it into the interceptors
  * to pass the transactions id across the application.
  * @see OmegaContext
+ * @deprecated Use configuration omega.enabled, default value is true
  */
+@Deprecated
 public @interface EnableOmega {
 }
diff --git a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringAutoConfiguration.java
similarity index 64%
copy from omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
copy to omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringAutoConfiguration.java
index 6117d48..021cbae 100644
--- a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/EnableOmega.java
+++ b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringAutoConfiguration.java
@@ -17,23 +17,13 @@
 
 package org.apache.servicecomb.pack.omega.spring;
 
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.apache.servicecomb.pack.omega.context.OmegaContext;
-import org.springframework.context.annotation.Import;
-
 import org.apache.servicecomb.pack.omega.transaction.spring.TransactionAspectConfig;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
 
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Import({OmegaSpringConfig.class, TransactionAspectConfig.class})
-/**
- * Indicates create the OmegaContext and inject it into the interceptors
- * to pass the transactions id across the application.
- * @see OmegaContext
- */
-public @interface EnableOmega {
+@Configuration
+@Import({OmegaSpringConfig.class,TransactionAspectConfig.class})
+@ConditionalOnProperty(value = {"omega.enabled"}, matchIfMissing = true)
+public class OmegaSpringAutoConfiguration {
 }
diff --git a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringConfig.java b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringConfig.java
index 18e3ed1..37e2f39 100644
--- a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringConfig.java
+++ b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/pack/omega/spring/OmegaSpringConfig.java
@@ -18,6 +18,7 @@
 package org.apache.servicecomb.pack.omega.spring;
 
 import com.google.common.collect.ImmutableList;
+import org.apache.servicecomb.pack.omega.connector.grpc.AlphaClusterDiscovery;
 import org.apache.servicecomb.pack.omega.connector.grpc.AlphaClusterConfig;
 import org.apache.servicecomb.pack.omega.connector.grpc.core.FastestSender;
 import org.apache.servicecomb.pack.omega.connector.grpc.core.LoadBalanceContext;
@@ -38,15 +39,23 @@ import org.apache.servicecomb.pack.omega.transaction.tcc.DefaultParametersContex
 import org.apache.servicecomb.pack.omega.transaction.tcc.ParametersContext;
 import org.apache.servicecomb.pack.omega.transaction.tcc.TccMessageHandler;
 import org.apache.servicecomb.pack.omega.transaction.tcc.TccMessageSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Lazy;
 
+import java.lang.invoke.MethodHandles;
+
 @Configuration
+@ConditionalOnProperty(value = {"alpha.cluster.address"})
 class OmegaSpringConfig {
 
+  private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
   @Bean(name = {"omegaUniqueIdGenerator"})
   IdGenerator<String> idGenerator() {
     return new UniqueIdGenerator();
@@ -78,19 +87,27 @@ class OmegaSpringConfig {
   }
 
   @Bean
+  @ConditionalOnProperty(name = "alpha.cluster.register.type", havingValue = "default", matchIfMissing = true)
+  AlphaClusterDiscovery alphaClusterAddress(@Value("${alpha.cluster.address:localhost:8080}") String[] addresses){
+    return AlphaClusterDiscovery.builder().addresses(addresses).build();
+  }
+
+  @Bean
   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 AlphaClusterDiscovery alphaClusterDiscovery,
       @Lazy MessageHandler handler,
       @Lazy TccMessageHandler tccMessageHandler) {
 
+    LOG.info("Discovery alpha cluster address from {} {}",alphaClusterDiscovery.getDiscoveryType().name()
+            ,alphaClusterDiscovery.getDiscoveryInfo() == null ? "" : alphaClusterDiscovery.getDiscoveryInfo());
     MessageFormat messageFormat = new KryoMessageFormat();
     AlphaClusterConfig clusterConfig = AlphaClusterConfig.builder()
-        .addresses(ImmutableList.copyOf(addresses))
+        .addresses(ImmutableList.copyOf(alphaClusterDiscovery.getAddresses()))
         .enableSSL(enableSSL)
         .enableMutualAuth(mutualAuth)
         .cert(cert)
diff --git a/omega/omega-spring-starter/src/main/resources/META-INF/spring.factories b/omega/omega-spring-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..78529f1
--- /dev/null
+++ b/omega/omega-spring-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.apache.servicecomb.pack.omega.spring.OmegaSpringAutoConfiguration
diff --git a/omega/pom.xml b/omega/pom.xml
index f8e8b7c..df3c682 100644
--- a/omega/pom.xml
+++ b/omega/pom.xml
@@ -37,6 +37,7 @@
     <module>omega-transport</module>
     <module>omega-connector</module>
     <module>omega-spring-starter</module>
+    <module>omega-spring-cloud-starter</module>
     <module>omega-format</module>
   </modules>