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/05/10 14:36:28 UTC
[incubator-servicecomb-saga] branch master updated (d8ad37c ->
877a278)
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git.
from d8ad37c SCB-245 Added log dependency for tracking the test error
new dabc951 SCB-571 Decouple OmegaContext in omega-transport-resttemplate
new de13058 SCB-571 Decouple OmegaContext in omega-transport-servicecomb
new 00cfad9 SCB-571 Decouple OmegaContext in omega-transport-dubbo
new 877a278 SCB-571 reformate the code of omega-transport-dubbo
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../transport/dubbo/SagaDubboConsumerFilter.java | 39 ++++++++---------
.../transport/dubbo/SagaDubboProviderFilter.java | 49 ++++++++++++----------
.../transport/resttemplate/RestTemplateConfig.java | 3 +-
.../TransactionClientHttpRequestInterceptor.java | 3 +-
.../TransactionHandlerInterceptor.java | 14 ++++---
.../omega/transport/resttemplate/WebConfig.java | 12 +++++-
.../transport/servicecomb/SagaConsumerHandler.java | 8 ++--
.../transport/servicecomb/SagaProviderHandler.java | 21 ++++++----
8 files changed, 87 insertions(+), 62 deletions(-)
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.
[incubator-servicecomb-saga] 04/04: SCB-571 reformate the code of
omega-transport-dubbo
Posted by ni...@apache.org.
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 877a2783f9a3336b71230eadef7fd54a5b40a125
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Thu May 10 17:00:15 2018 +0800
SCB-571 reformate the code of omega-transport-dubbo
---
.../transport/dubbo/SagaDubboConsumerFilter.java | 39 +++++++++--------
.../transport/dubbo/SagaDubboProviderFilter.java | 51 +++++++++++-----------
2 files changed, 46 insertions(+), 44 deletions(-)
diff --git a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
index a6a73e8..35f02a2 100644
--- a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
+++ b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
@@ -37,26 +37,27 @@ import static org.apache.servicecomb.saga.omega.context.OmegaContext.LOCAL_TX_ID
/**
* add saga transaction id to dubbo invocation
-*/
+ */
@Activate(group = {Constants.CONSUMER})
public class SagaDubboConsumerFilter implements Filter {
- private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
- // TODO not sure if it's a good way to look up OmegaContext during every invoke
- OmegaContext omegaContext = (OmegaContext) (new SpringExtensionFactory()).getExtension(OmegaContext.class, "omegaContext");
- if(omegaContext != null){
- invocation.getAttachments().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
- invocation.getAttachments().put(LOCAL_TX_ID_KEY, omegaContext.localTxId());
- }
- if (omegaContext != null && omegaContext.globalTxId() != null) {
- LOG.info("Added {} {} and {} {} to dubbo invocation", new Object[]{GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
- LOCAL_TX_ID_KEY, omegaContext.localTxId()});
- }
-
- if (invoker != null) {
- return invoker.invoke(invocation);
- }
- return null;
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ // TODO not sure if it's a good way to look up OmegaContext during every invoke
+ OmegaContext omegaContext = (OmegaContext) (new SpringExtensionFactory())
+ .getExtension(OmegaContext.class, "omegaContext");
+ if (omegaContext != null) {
+ invocation.getAttachments().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
+ invocation.getAttachments().put(LOCAL_TX_ID_KEY, omegaContext.localTxId());
+ }
+ if (omegaContext != null && omegaContext.globalTxId() != null) {
+ LOG.info("Added {} {} and {} {} to dubbo invocation", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
+ LOCAL_TX_ID_KEY, omegaContext.localTxId()});
+ }
+
+ if (invoker != null) {
+ return invoker.invoke(invocation);
}
+ return null;
+ }
}
diff --git a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
index 32d253b..acb0524 100644
--- a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
+++ b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
@@ -20,6 +20,7 @@ import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.config.spring.extension.SpringExtensionFactory;
import com.alibaba.dubbo.rpc.*;
+
import org.apache.servicecomb.saga.omega.context.OmegaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,33 +32,33 @@ import static org.apache.servicecomb.saga.omega.context.OmegaContext.LOCAL_TX_ID
/**
* get saga transaction id from dubbo invocation and set into omega context
-*/
+ */
@Activate(group = Constants.PROVIDER)
public class SagaDubboProviderFilter implements Filter {
- private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- @Override
- public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
- // TODO not sure if it's a good way to look up OmegaContext during every invoke
- OmegaContext omegaContext = new SpringExtensionFactory().getExtension(OmegaContext.class, "omegaContext");
- if (omegaContext != null) {
- String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY);
- if (globalTxId == null) {
- LOG.info("no such omega context global id: {}", GLOBAL_TX_ID_KEY);
- } else {
- omegaContext.setGlobalTxId(globalTxId);
- omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY));
- LOG.info("Added {} {} and {} {} to omegaContext", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
- LOCAL_TX_ID_KEY, omegaContext.localTxId()});
- }
- invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null);
- invocation.getAttachments().put(LOCAL_TX_ID_KEY, null);
- }
-
- if(invoker != null){
- return invoker.invoke(invocation);
- }
- return null;
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Override
+ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ // TODO not sure if it's a good way to look up OmegaContext during every invoke
+ OmegaContext omegaContext = new SpringExtensionFactory().getExtension(OmegaContext.class, "omegaContext");
+ if (omegaContext != null) {
+ String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY);
+ if (globalTxId == null) {
+ LOG.info("no such omega context global id: {}", GLOBAL_TX_ID_KEY);
+ } else {
+ omegaContext.setGlobalTxId(globalTxId);
+ omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY));
+ LOG.info("Added {} {} and {} {} to omegaContext", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
+ LOCAL_TX_ID_KEY, omegaContext.localTxId()});
+ }
+ invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null);
+ invocation.getAttachments().put(LOCAL_TX_ID_KEY, null);
+ }
+
+ if (invoker != null) {
+ return invoker.invoke(invocation);
}
+ return null;
+ }
}
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.
[incubator-servicecomb-saga] 03/04: SCB-571 Decouple OmegaContext
in omega-transport-dubbo
Posted by ni...@apache.org.
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 00cfad97b4a7c33dbed3f68b6c58a3e0f0a80c4a
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Thu May 10 16:56:13 2018 +0800
SCB-571 Decouple OmegaContext in omega-transport-dubbo
SCB-571 Decouple OmegaContext in omega-transport-dubbo
---
.../omega/transport/dubbo/SagaDubboConsumerFilter.java | 2 +-
.../omega/transport/dubbo/SagaDubboProviderFilter.java | 18 ++++++++++--------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
index 40605e8..a6a73e8 100644
--- a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
+++ b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
@@ -37,13 +37,13 @@ import static org.apache.servicecomb.saga.omega.context.OmegaContext.LOCAL_TX_ID
/**
* add saga transaction id to dubbo invocation
-* @date 03/05/2018 10:44 AM
*/
@Activate(group = {Constants.CONSUMER})
public class SagaDubboConsumerFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ // TODO not sure if it's a good way to look up OmegaContext during every invoke
OmegaContext omegaContext = (OmegaContext) (new SpringExtensionFactory()).getExtension(OmegaContext.class, "omegaContext");
if(omegaContext != null){
invocation.getAttachments().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
diff --git a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
index a426880..32d253b 100644
--- a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
+++ b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
@@ -31,7 +31,6 @@ import static org.apache.servicecomb.saga.omega.context.OmegaContext.LOCAL_TX_ID
/**
* get saga transaction id from dubbo invocation and set into omega context
-* @date 03/05/2018 10:44 AM
*/
@Activate(group = Constants.PROVIDER)
public class SagaDubboProviderFilter implements Filter {
@@ -40,18 +39,21 @@ public class SagaDubboProviderFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ // TODO not sure if it's a good way to look up OmegaContext during every invoke
OmegaContext omegaContext = new SpringExtensionFactory().getExtension(OmegaContext.class, "omegaContext");
- String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY);
- if (globalTxId == null) {
+ if (omegaContext != null) {
+ String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY);
+ if (globalTxId == null) {
LOG.info("no such omega context global id: {}", GLOBAL_TX_ID_KEY);
- }else{
+ } else {
omegaContext.setGlobalTxId(globalTxId);
omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY));
- LOG.info("Added {} {} and {} {} to omegaContext", new Object[]{GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
- LOCAL_TX_ID_KEY, omegaContext.localTxId()});
+ LOG.info("Added {} {} and {} {} to omegaContext", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
+ LOCAL_TX_ID_KEY, omegaContext.localTxId()});
+ }
+ invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null);
+ invocation.getAttachments().put(LOCAL_TX_ID_KEY, null);
}
- invocation.getAttachments().put(GLOBAL_TX_ID_KEY,null);
- invocation.getAttachments().put(LOCAL_TX_ID_KEY,null);
if(invoker != null){
return invoker.invoke(invocation);
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.
[incubator-servicecomb-saga] 01/04: SCB-571 Decouple OmegaContext
in omega-transport-resttemplate
Posted by ni...@apache.org.
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 dabc951cd24e13f10966c76603829eae60d7e415
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Thu May 10 16:51:42 2018 +0800
SCB-571 Decouple OmegaContext in omega-transport-resttemplate
---
.../omega/transport/resttemplate/RestTemplateConfig.java | 3 ++-
.../TransactionClientHttpRequestInterceptor.java | 3 ++-
.../resttemplate/TransactionHandlerInterceptor.java | 14 ++++++++------
.../saga/omega/transport/resttemplate/WebConfig.java | 12 +++++++++++-
4 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/RestTemplateConfig.java b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/RestTemplateConfig.java
index e9aac31..98bf70b 100644
--- a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/RestTemplateConfig.java
+++ b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/RestTemplateConfig.java
@@ -20,6 +20,7 @@ package org.apache.servicecomb.saga.omega.transport.resttemplate;
import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
@@ -31,7 +32,7 @@ import org.apache.servicecomb.saga.omega.context.OmegaContext;
public class RestTemplateConfig {
@Bean
- public RestTemplate restTemplate(OmegaContext context) {
+ public RestTemplate restTemplate(@Autowired(required=false) OmegaContext context) {
RestTemplate template = new RestTemplate();
List<ClientHttpRequestInterceptor> interceptors = template.getInterceptors();
interceptors.add(new TransactionClientHttpRequestInterceptor(context));
diff --git a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionClientHttpRequestInterceptor.java b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionClientHttpRequestInterceptor.java
index 88ea564..958be54 100644
--- a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionClientHttpRequestInterceptor.java
+++ b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionClientHttpRequestInterceptor.java
@@ -27,6 +27,7 @@ import java.lang.invoke.MethodHandles;
import org.apache.servicecomb.saga.omega.context.OmegaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
@@ -44,7 +45,7 @@ class TransactionClientHttpRequestInterceptor implements ClientHttpRequestInterc
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
- if (omegaContext.globalTxId() != null) {
+ if (omegaContext!= null && omegaContext.globalTxId() != null) {
request.getHeaders().add(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
request.getHeaders().add(LOCAL_TX_ID_KEY, omegaContext.localTxId());
diff --git a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptor.java b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptor.java
index 9b003f8..50b8a0e 100644
--- a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptor.java
+++ b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptor.java
@@ -46,12 +46,14 @@ class TransactionHandlerInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
- String globalTxId = request.getHeader(GLOBAL_TX_ID_KEY);
- if (globalTxId == null) {
- LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY);
- } else {
- omegaContext.setGlobalTxId(globalTxId);
- omegaContext.setLocalTxId(request.getHeader(LOCAL_TX_ID_KEY));
+ if (omegaContext != null) {
+ String globalTxId = request.getHeader(GLOBAL_TX_ID_KEY);
+ if (globalTxId == null) {
+ LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY);
+ } else {
+ omegaContext.setGlobalTxId(globalTxId);
+ omegaContext.setLocalTxId(request.getHeader(LOCAL_TX_ID_KEY));
+ }
}
return true;
}
diff --git a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/WebConfig.java b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/WebConfig.java
index 255d20b..3218d47 100644
--- a/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/WebConfig.java
+++ b/omega/omega-transport/omega-transport-resttemplate/src/main/java/org/apache/servicecomb/saga/omega/transport/resttemplate/WebConfig.java
@@ -20,7 +20,11 @@
package org.apache.servicecomb.saga.omega.transport.resttemplate;
+import java.lang.invoke.MethodHandles;
+
import org.apache.servicecomb.saga.omega.context.OmegaContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -33,13 +37,19 @@ public class WebConfig extends WebMvcConfigurerAdapter {
private final OmegaContext omegaContext;
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+
@Autowired
- public WebConfig(OmegaContext omegaContext) {
+ public WebConfig(@Autowired(required=false) OmegaContext omegaContext) {
this.omegaContext = omegaContext;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
+ if (omegaContext == null) {
+ LOG.info("The OmegaContext is not injected, The transaction handler is disabled");
+ }
registry.addInterceptor(new TransactionHandlerInterceptor(omegaContext));
}
}
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.
[incubator-servicecomb-saga] 02/04: SCB-571 Decouple OmegaContext
in omega-transport-servicecomb
Posted by ni...@apache.org.
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 de13058dbdd7ddfcd444a373cac5c94b74b77481
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Thu May 10 16:52:43 2018 +0800
SCB-571 Decouple OmegaContext in omega-transport-servicecomb
---
.../transport/servicecomb/SagaConsumerHandler.java | 8 +++++---
.../transport/servicecomb/SagaProviderHandler.java | 21 +++++++++++++--------
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
index 5e0dcb2..82e49ef 100644
--- a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
+++ b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
@@ -36,14 +36,16 @@ public class SagaConsumerHandler implements Handler {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final OmegaContext omegaContext;
- @Autowired
- public SagaConsumerHandler(OmegaContext omegaContext) {
+ public SagaConsumerHandler(@Autowired(required=false) OmegaContext omegaContext) {
this.omegaContext = omegaContext;
+ if (omegaContext == null) {
+ LOG.info("The OmegaContext is not injected, The SagaConsumerHandler is disabled.");
+ }
}
@Override
public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
- if (omegaContext.globalTxId() != null) {
+ if (omegaContext!= null && omegaContext.globalTxId() != null) {
invocation.getContext().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
invocation.getContext().put(LOCAL_TX_ID_KEY, omegaContext.localTxId());
diff --git a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
index 73a7394..a3a72b6 100644
--- a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
+++ b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
@@ -36,19 +36,24 @@ public class SagaProviderHandler implements Handler {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final OmegaContext omegaContext;
- @Autowired
- public SagaProviderHandler(OmegaContext omegaContext) {
+ public SagaProviderHandler(@Autowired(required=false) OmegaContext omegaContext) {
this.omegaContext = omegaContext;
+ if (omegaContext == null) {
+ LOG.info("The OmegaContext is not injected, The SagaProviderHander is disabled.");
+ }
}
@Override
public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
- String globalTxId = invocation.getContext().get(GLOBAL_TX_ID_KEY);
- if (globalTxId == null) {
- LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY);
- } else {
- omegaContext.setGlobalTxId(globalTxId);
- omegaContext.setLocalTxId(invocation.getContext().get(LOCAL_TX_ID_KEY));
+ if (omegaContext != null) {
+ String globalTxId = invocation.getContext().get(GLOBAL_TX_ID_KEY);
+ if (globalTxId == null) {
+ LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY);
+ } else {
+
+ omegaContext.setGlobalTxId(globalTxId);
+ omegaContext.setLocalTxId(invocation.getContext().get(LOCAL_TX_ID_KEY));
+ }
}
invocation.next(asyncResponse);
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.