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 2018/08/31 00:43:27 UTC
[incubator-servicecomb-saga] 01/07: SCB-876 Add TCC aspect and
eventService into configuration file.
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/incubator-servicecomb-saga.git
commit 088038248f3a839641c2471058f750cacb1541a0
Author: cherrylzhao <zh...@126.com>
AuthorDate: Wed Aug 29 16:28:16 2018 +0800
SCB-876 Add TCC aspect and eventService into configuration file.
---
.../saga/omega/spring/OmegaSpringConfig.java | 13 +++++++++++++
.../spring/TransactionAspectConfig.java | 22 ++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/saga/omega/spring/OmegaSpringConfig.java b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/saga/omega/spring/OmegaSpringConfig.java
index 217e102..624ef84 100644
--- a/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/saga/omega/spring/OmegaSpringConfig.java
+++ b/omega/omega-spring-starter/src/main/java/org/apache/servicecomb/saga/omega/spring/OmegaSpringConfig.java
@@ -18,7 +18,10 @@
package org.apache.servicecomb.saga.omega.spring;
import com.google.common.collect.ImmutableList;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
import org.apache.servicecomb.saga.omega.connector.grpc.AlphaClusterConfig;
+import org.apache.servicecomb.saga.omega.connector.grpc.GrpcTccEventService;
import org.apache.servicecomb.saga.omega.connector.grpc.LoadBalancedClusterMessageSender;
import org.apache.servicecomb.saga.omega.context.CompensationContext;
import org.apache.servicecomb.saga.omega.context.IdGenerator;
@@ -29,6 +32,7 @@ import org.apache.servicecomb.saga.omega.format.KryoMessageFormat;
import org.apache.servicecomb.saga.omega.format.MessageFormat;
import org.apache.servicecomb.saga.omega.transaction.MessageHandler;
import org.apache.servicecomb.saga.omega.transaction.MessageSender;
+import org.apache.servicecomb.saga.omega.transaction.tcc.TccEventService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -99,4 +103,13 @@ class OmegaSpringConfig {
}));
return sender;
}
+
+ // TODO should integrate with loadBalance message sender in future.
+ @Bean
+ TccEventService tccEventService(ServiceConfig serviceConfig,
+ @Lazy org.apache.servicecomb.saga.omega.transaction.tcc.MessageHandler coordinateMessageHandler,
+ @Value("${alpha.cluster.address:localhost:8080}") String address) {
+ ManagedChannel channel = ManagedChannelBuilder.forTarget(address).usePlaintext().build();
+ return new GrpcTccEventService(serviceConfig, channel, address, coordinateMessageHandler);
+ }
}
diff --git a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionAspectConfig.java b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionAspectConfig.java
index 4fd4188..73d02cf 100644
--- a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionAspectConfig.java
+++ b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionAspectConfig.java
@@ -24,6 +24,10 @@ import org.apache.servicecomb.saga.omega.transaction.MessageHandler;
import org.apache.servicecomb.saga.omega.transaction.MessageSender;
import org.apache.servicecomb.saga.omega.transaction.SagaStartAspect;
import org.apache.servicecomb.saga.omega.transaction.TransactionAspect;
+import org.apache.servicecomb.saga.omega.transaction.tcc.CoordinateMessageHandler;
+import org.apache.servicecomb.saga.omega.transaction.tcc.TccEventService;
+import org.apache.servicecomb.saga.omega.transaction.tcc.TccParticipatorAspect;
+import org.apache.servicecomb.saga.omega.transaction.tcc.TccStartAspect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -55,4 +59,22 @@ public class TransactionAspectConfig {
CompensationContext compensationContext) {
return new CompensableAnnotationProcessor(omegaContext, compensationContext);
}
+
+ @Bean
+ org.apache.servicecomb.saga.omega.transaction.tcc.MessageHandler coordinateMessageHandler(
+ TccEventService tccEventService) {
+ return new CoordinateMessageHandler(tccEventService);
+ }
+
+ @Order(2)
+ @Bean
+ TccStartAspect tccStartAspect(TccEventService tccEventService, OmegaContext context) {
+ return new TccStartAspect(tccEventService, context);
+ }
+
+ @Order(3)
+ @Bean
+ TccParticipatorAspect tccParticipatorAspect(TccEventService tccEventService, OmegaContext context) {
+ return new TccParticipatorAspect(tccEventService, context);
+ }
}