Просмотр исходного кода

订单失败,事物补偿处理

wuxw7 лет назад: 9
Родитель
Сommit
074a0d6b74
35 измененных файлов с 1076 добавлено и 535 удалено
  1. 575 348
      .idea/workspace.xml
  2. 164 0
      OrderService/AnnotationConfigEmbeddedWebApplicationContext.puml
  3. 96 0
      OrderService/ApplicationContext.puml
  4. 13 0
      OrderService/CreateApplicationContext.puml
  5. 16 0
      OrderService/SpringApplicationStart.puml
  6. 4 23
      OrderService/src/main/java/com/java110/order/listener/DeleteCustDispatchListener.java
  7. 10 139
      OrderService/src/main/java/com/java110/order/mq/MqConfig.java
  8. 56 1
      OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java
  9. 3 1
      OrderService/src/main/resources/application.yml
  10. 81 0
      OrderService/src/test/java/com/java110/order/executor/ExecutorTest.java
  11. 23 0
      OrderService/src/test/java/com/java110/order/executor/PrintInt.java
  12. BIN
      OrderService/target/classes/com/java110/order/listener/CustDispatchListener.class
  13. BIN
      OrderService/target/classes/com/java110/order/listener/DeleteCustDispatchListener.class
  14. BIN
      OrderService/target/classes/com/java110/order/smo/impl/OrderServiceSMOImpl.class
  15. BIN
      OrderService/target/test-classes/com/java110/order/executor/ExecutorTest.class
  16. BIN
      OrderService/target/test-classes/com/java110/order/executor/PrintInt.class
  17. 5 11
      Readme.md
  18. BIN
      common/target/classes/com/java110/common/constant/ActionTypeConstant.class
  19. BIN
      common/target/classes/com/java110/common/constant/AttrCdConstant.class
  20. BIN
      common/target/classes/com/java110/common/constant/CommonConstant.class
  21. BIN
      common/target/classes/com/java110/common/constant/DomainContant.class
  22. BIN
      common/target/classes/com/java110/common/constant/ItemSpecCdConstant.class
  23. BIN
      common/target/classes/com/java110/common/constant/StatusConstant.class
  24. 25 11
      config/target/classes/META-INF/spring-configuration-metadata.json
  25. BIN
      config/target/classes/com/java110/config/properties/CustProperties.class
  26. BIN
      config/target/classes/com/java110/config/properties/OrderProperties.class
  27. 3 1
      config/target/classes/config/event.properties
  28. 2 0
      config/target/classes/config/order.properties
  29. BIN
      core/target/classes/com/java110/core/SystemStartUpInit.class
  30. BIN
      core/target/classes/com/java110/core/event/AppCustEvent.class
  31. BIN
      core/target/classes/com/java110/core/event/AppDeleteCustEvent.class
  32. BIN
      core/target/classes/com/java110/core/event/AppEvent.class
  33. BIN
      core/target/classes/com/java110/core/event/AppEventPublishing$1.class
  34. BIN
      core/target/classes/com/java110/core/event/AppEventPublishing.class
  35. BIN
      core/target/classes/com/java110/core/factory/AppFactory.class

Разница между файлами не показана из-за своего большого размера
+ 575 - 348
.idea/workspace.xml


+ 164 - 0
OrderService/AnnotationConfigEmbeddedWebApplicationContext.puml

@@ -0,0 +1,164 @@
+@startuml
+
+class AnnotationConfigEmbeddedWebApplicationContext extends EmbeddedWebApplicationContext{
+
+
+    public AnnotationConfigEmbeddedWebApplicationContext();
+
+    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory);
+
+    public final void scan(String... basePackages) ;
+
+    public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver);
+
+}
+
+class EmbeddedWebApplicationContext extends GenericWebApplicationContext{
+
+    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory);
+
+    public final void refresh();
+
+    protected void onRefresh();
+
+    protected void finishRefresh();
+
+    private void createEmbeddedServletContainer();
+
+    protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory();
+}
+
+class GenericWebApplicationContext extends GenericApplicationContext implements ConfigurableWebApplicationContext, ThemeSource{
+
+    public void setServletContext(ServletContext servletContext);
+
+    public ServletContext getServletContext();
+
+    protected ConfigurableEnvironment createEnvironment();
+
+    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory);
+
+    protected Resource getResourceByPath(String path);
+
+    protected void onRefresh();
+
+    public String[] getConfigLocations();
+}
+
+class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry{
+
+    public Resource getResource(String location);
+
+    public final ConfigurableListableBeanFactory getBeanFactory();
+}
+
+class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext, DisposableBean{
+
+    public void publishEvent(ApplicationEvent event);
+
+    public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);
+
+    public void addApplicationListener(ApplicationListener<?> listener);
+
+    public void refresh() ;
+}
+
+class DefaultResourceLoader implements ResourceLoader{
+    public Resource getResource(String location) ;
+
+    protected Resource getResourceByPath(String path);
+}
+
+
+
+
+interface ConfigurableWebApplicationContext extends ConfigurableApplicationContext,WebApplicationContext{
+    void setServletContext(ServletContext servletContext);
+    void setServletConfig(ServletConfig servletConfig);
+    void setConfigLocation(String configLocation);
+    String[] getConfigLocations();
+}
+
+interface ApplicationContext extends HierarchicalBeanFactory,MessageSource,ApplicationEventPublisher,ResourcePatternResolver{
+
+	String getId();
+
+	String getApplicationName();
+
+	String getDisplayName();
+
+	long getStartupDate();
+
+	ApplicationContext getParent();
+
+	AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;
+}
+
+interface ConfigurableApplicationContext{
+
+}
+
+interface Lifecycle{
+
+}
+
+interface Closeable{
+     public void close() throws IOException;
+}
+
+interface EnvironmentCapable{
+     Environment getEnvironment();
+}
+
+interface ListableBeanFactory extends BeanFactory{
+    String[] getBeanNamesForType(ResolvableType type);
+}
+
+interface BeanFactory{
+
+    Object getBean(String name) throws BeansException;
+
+    <T> T getBean(String name, Class<T> requiredType) throws BeansException;
+    <T> T getBean(Class<T> requiredType) throws BeansException;
+}
+
+interface HierarchicalBeanFactory extends BeanFactory{
+
+    BeanFactory getParentBeanFactory();
+}
+
+interface MessageSource{
+    String getMessage(String code, Object[] args, String defaultMessage, Locale locale);
+}
+
+interface ApplicationEventPublisher{
+    void publishEvent(ApplicationEvent event);
+}
+
+interface ResourcePatternResolver extends ResourceLoader{
+    Resource[] getResources(String locationPattern) throws IOException;
+
+}
+
+interface ResourceLoader{
+
+    Resource getResource(String location);
+    ClassLoader getClassLoader();
+
+}
+
+ApplicationContext <|-- ConfigurableApplicationContext : 继承关系
+
+Lifecycle <|-- ConfigurableApplicationContext : 继承关系
+
+Closeable <|-- ConfigurableApplicationContext : 继承关系
+
+EnvironmentCapable <|-- ApplicationContext:继承关系
+
+ListableBeanFactory <|-- ApplicationContext:继承关系
+
+
+
+
+
+@enduml

+ 96 - 0
OrderService/ApplicationContext.puml

@@ -0,0 +1,96 @@
+@startuml
+
+title SpringApplication context 分析过程
+
+class SpringApplication {
+
+private boolean webEnvironment;
+
+}
+
+interface ConfigurableWebApplicationContext extends ConfigurableApplicationContext,WebApplicationContext{
+    void setServletContext(ServletContext servletContext);
+    void setServletConfig(ServletConfig servletConfig);
+    void setConfigLocation(String configLocation);
+    String[] getConfigLocations();
+}
+
+interface ApplicationContext extends HierarchicalBeanFactory,MessageSource,ApplicationEventPublisher,ResourcePatternResolver{
+
+	String getId();
+
+	String getApplicationName();
+
+	String getDisplayName();
+
+	long getStartupDate();
+
+	ApplicationContext getParent();
+
+	AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;
+}
+
+interface ConfigurableApplicationContext{
+
+}
+
+interface Lifecycle{
+
+}
+
+interface Closeable{
+     public void close() throws IOException;
+}
+
+interface EnvironmentCapable{
+     Environment getEnvironment();
+}
+
+interface ListableBeanFactory extends BeanFactory{
+    String[] getBeanNamesForType(ResolvableType type);
+}
+
+interface BeanFactory{
+
+    Object getBean(String name) throws BeansException;
+
+    <T> T getBean(String name, Class<T> requiredType) throws BeansException;
+    <T> T getBean(Class<T> requiredType) throws BeansException;
+}
+
+interface HierarchicalBeanFactory extends BeanFactory{
+
+    BeanFactory getParentBeanFactory();
+}
+
+interface MessageSource{
+    String getMessage(String code, Object[] args, String defaultMessage, Locale locale);
+}
+
+interface ApplicationEventPublisher{
+    void publishEvent(ApplicationEvent event);
+}
+
+interface ResourcePatternResolver extends ResourceLoader{
+    Resource[] getResources(String locationPattern) throws IOException;
+
+}
+
+interface ResourceLoader{
+
+    Resource getResource(String location);
+    ClassLoader getClassLoader();
+
+}
+
+ApplicationContext <|-- ConfigurableApplicationContext : 继承关系
+
+Lifecycle <|-- ConfigurableApplicationContext : 继承关系
+
+Closeable <|-- ConfigurableApplicationContext : 继承关系
+
+EnvironmentCapable <|-- ApplicationContext:继承关系
+
+ListableBeanFactory <|-- ApplicationContext:继承关系
+
+@enduml

+ 13 - 0
OrderService/CreateApplicationContext.puml

@@ -0,0 +1,13 @@
+@startuml
+autonumber 1 "[0.0]"
+title ApplicationContext 创建过程
+
+SpringApplication -> SpringApplication : createApplicationContext\n创建上下文对象
+
+SpringApplication -> AnnotationConfigEmbeddedWebApplicationContext : BeanUtils.instantiate(contextClass) \n创建实例\nAnnotationConfigEmbeddedWebApplicationContext()
+
+AnnotationConfigEmbeddedWebApplicationContext --> AnnotatedBeanDefinitionReader : 初始化AnnotatedBeanDefinitionReader\n(BeanDefinitionRegistry registry)
+
+AnnotatedBeanDefinitionReader -> AnnotatedBeanDefinitionReader:getOrCreateEnvironment\n(BeanDefinitionRegistry registry)
+
+@enduml

+ 16 - 0
OrderService/SpringApplicationStart.puml

@@ -0,0 +1,16 @@
+@startuml
+title <b><u>Spring 启动过程
+autonumber 1 "[0.0]"
+SpringApplication --> SpringApplication: 调用run(source,args) \nsource为启动类class,\nargs 为main方法的参数
+Bob <--> Alice: Authentication Response
+newpage
+Bob --[#red]> wuxw: java方法调用
+note left: <i><s><w><size:22>爱情买卖
+wuxw -->
+ note left of Alice #aqua
+       This is displayed
+       left of Alice.
+  end note
+Alice -> Bob: Another authentication Request
+Alice <-- Bob: another authentication Response
+@enduml

+ 4 - 23
OrderService/src/main/java/com/java110/order/listener/DeleteCustDispatchListener.java

@@ -38,29 +38,18 @@ public class DeleteCustDispatchListener implements AppListener<AppDeleteCustEven
 
         //这里写 客户信息处理逻辑
 
-       // AppContext context = event.getContext();
+        // AppContext context = event.getContext();
 
         JSONArray dataCustInfos = event.getData();
 
         JSONObject custInfoJson = new JSONObject();
-        custInfoJson.put("data",dataCustInfos.toJSONString());
+        custInfoJson.put("data", dataCustInfos.toJSONString());
 
         String custInfo = custInfoJson.toJSONString();
 
 
-        Assert.hasLength(custInfo,"没有需要处理的信息[custInfo="+custInfo+"]");
-
-        /**
-         * 同步处理
-         */
-        if(CommonConstant.PROCESS_ORDER_SYNCHRONOUS.equals(orderProperties.getDeleteOrderAsyn())){
-            processSynchronous(custInfo);
-        }else{
-            //异步消息队里处理
-            processAsynchronous(custInfo);
-        }
-
-
+        Assert.hasLength(custInfo, "没有需要处理的信息[custInfo=" + custInfo + "]");
+        processSynchronous(custInfo);
     }
 
     /**
@@ -82,14 +71,6 @@ public class DeleteCustDispatchListener implements AppListener<AppDeleteCustEven
         }
     }
 
-    /**
-     * 异步方式处理,主要是通过消息队列处理,缺点是对结果无法预知
-     * @param custInfo
-     */
-    private void processAsynchronous(String custInfo){
-
-    }
-
     @Override
     public int getOrder() {
         return order;

+ 10 - 139
OrderService/src/main/java/com/java110/order/mq/MqConfig.java

@@ -1,15 +1,12 @@
 package com.java110.order.mq;
 
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.pool.PooledConnectionFactory;
-import org.apache.commons.lang.math.NumberUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
-import org.springframework.jms.core.JmsTemplate;
 
-import javax.jms.ConnectionFactory;
+import javax.jms.Queue;
+import javax.jms.Topic;
 
 /**
  * Created by wuxw on 2017/4/17.
@@ -17,139 +14,13 @@ import javax.jms.ConnectionFactory;
 @ConfigurationProperties(prefix = "mq.queue.name",locations="classpath:mq/mq.properties")
 public class MqConfig {
 
-    @Autowired
-    ConnectionFactory mqConnectionFactory;
-
-    @Autowired
-    PooledConnectionFactory pooledConnectionFactory;
-
-    @Value("user")
-    private String userQueueName;
-
-    @Value("deleteOrderQueue")
-    private String deleteOrderQueueName;
-    @Value("deleteOrderTopic")
-    private String deleteOrderTopicName;
-
-    private String brokerUrl;
-
-    private String username;
-
-    private String password;
-
-    private String maxConnection;
-
-    /**
-     * 默认最大链接数
-     */
-    private final static int DEFAULT_MAX_CONNECTION = 50;
-
-
-    /**
-     * activemq 链接工厂
-     * 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供
-     * @return
-     */
-    @Bean(name="mqConnectionFactory")
-    public ConnectionFactory mqConnectionFactory(){
-        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
-        connectionFactory.setBrokerURL(brokerUrl);
-        connectionFactory.setUserName(username);
-        connectionFactory.setPassword(password);
-        return connectionFactory;
-    }
-
-    /**
-     * 池链接
-     * ActiveMQ为我们提供了一个PooledConnectionFactory,通过往里面注入一个ActiveMQConnectionFactory
-     可以用来将Connection、Session和MessageProducer池化,这样可以大大的减少我们的资源消耗。 要依赖于 activemq-pool包
-     * @return
-     */
-    @Bean(name="pooledConnectionFactory")
-    public PooledConnectionFactory pooledConnectionFactory(){
-
-        PooledConnectionFactory connectionFactory = new PooledConnectionFactory();
-        connectionFactory.setConnectionFactory(mqConnectionFactory);
-        connectionFactory.setMaxConnections(NumberUtils.isNumber(maxConnection)?NumberUtils.toInt(maxConnection):DEFAULT_MAX_CONNECTION);
-        return connectionFactory;
-    }
-
-    @Bean(name="deleteOrderQueueJmsTemplate")
-    public JmsTemplate deleteOrderQueueJmsTemplate(){
-        JmsTemplate jmsTemplate = new JmsTemplate();
-        jmsTemplate.setConnectionFactory(pooledConnectionFactory);
-        jmsTemplate.setDefaultDestinationName(deleteOrderQueueName);
-        return jmsTemplate;
-    }
-    public String getUserQueueName() {
-        return userQueueName;
-    }
-
-    public void setUserQueueName(String userQueueName) {
-        this.userQueueName = userQueueName;
-    }
-
-    public String getDeleteOrderQueueName() {
-        return deleteOrderQueueName;
-    }
-
-    public void setDeleteOrderQueueName(String deleteOrderQueueName) {
-        this.deleteOrderQueueName = deleteOrderQueueName;
-    }
-
-    public String getDeleteOrderTopicName() {
-        return deleteOrderTopicName;
-    }
-
-    public void setDeleteOrderTopicName(String deleteOrderTopicName) {
-        this.deleteOrderTopicName = deleteOrderTopicName;
-    }
-
-    public String getUsername() {
-        return username;
-    }
-
-    public void setUsername(String username) {
-        this.username = username;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public void setPassword(String password) {
-        this.password = password;
-    }
-
-    public String getBrokerUrl() {
-        return brokerUrl;
-    }
-
-    public void setBrokerUrl(String brokerUrl) {
-        this.brokerUrl = brokerUrl;
-    }
-
-    public ConnectionFactory getMqConnectionFactory() {
-        return mqConnectionFactory;
-    }
-
-    public void setMqConnectionFactory(ConnectionFactory mqConnectionFactory) {
-        this.mqConnectionFactory = mqConnectionFactory;
-    }
-
-    public String getMaxConnection() {
-        return maxConnection;
-    }
-
-    public void setMaxConnection(String maxConnection) {
-        this.maxConnection = maxConnection;
-    }
-
-    public PooledConnectionFactory getPooledConnectionFactory() {
-        return pooledConnectionFactory;
+    @Bean
+    public Queue queue() {
+        return new ActiveMQQueue("sample.queue");
     }
 
-    public void setPooledConnectionFactory(PooledConnectionFactory pooledConnectionFactory) {
-        this.pooledConnectionFactory = pooledConnectionFactory;
+    @Bean
+    public Topic deleteOrderTopic() {
+        return new ActiveMQTopic("sample.topic");
     }
 }

+ 56 - 1
OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java

@@ -17,6 +17,7 @@ import com.java110.entity.order.OrderList;
 import com.java110.entity.order.OrderListAttr;
 import com.java110.feign.base.IPrimaryKeyService;
 import com.java110.order.dao.IOrderServiceDao;
+import com.java110.order.mq.DeleteOrderInfoProducer;
 import com.java110.order.smo.IOrderServiceSMO;
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -44,6 +45,9 @@ public class OrderServiceSMOImpl extends BaseServiceSMO implements IOrderService
     @Autowired
     EventProperties eventProperties;
 
+    @Autowired
+    DeleteOrderInfoProducer deleteOrderInfoProducer;
+
     /**
      * 根据购物车ID 或者 外部系统ID 或者 custId 或者 channelId 查询订单信息
      * @param orderList
@@ -230,7 +234,8 @@ public class OrderServiceSMOImpl extends BaseServiceSMO implements IOrderService
             //发布事件
             AppEventPublishing.multicastEvent(context,datasTmp,orderListTmp.getString("asyn"));
         }catch (Exception e){
-            //这里补偿事物
+            //这里补偿事物,这里发布广播
+            compensateTransactional(datasTmp);
             throw e;
         }
         return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(orderList)));
@@ -405,6 +410,7 @@ public class OrderServiceSMOImpl extends BaseServiceSMO implements IOrderService
             AppEventPublishing.multicastEvent(context,datasTmp,orderListTmp.getString("asyn"));
         }catch (Exception e){
             //这里补偿事物
+            compensateTransactional(datasTmp);
             throw e;
         }
         return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(orderList)));
@@ -506,6 +512,55 @@ public class OrderServiceSMOImpl extends BaseServiceSMO implements IOrderService
         }
         dataJsonTmp.add(JSONObject.parseObject(JSONObject.toJSONString(needDeleteBoIdMap)));
         datasTmp.put(actionTypeCd,dataJsonTmp);
+
+        deleteOrderInfoProducer.send(datasTmp.toString());
+    }
+
+
+    /**
+     * 补偿事物,这里不用手工作废 购物车信息,事物会自动回退掉,这里这需要手工给其他的系统发布事物回退
+     *
+     * { 'data': [
+
+     {
+     'boId': '222222',
+     'actionTypeCd': 'C1',
+     'oldBoId':'11111'
+     },
+     {
+     'boId': '222222',
+     'actionTypeCd': 'M1',
+     'oldBoId':'11111'
+     },
+     {
+     'boId': '222222',
+     'actionTypeCd': 'C1',
+     'oldBoId':'11111'
+     }
+     ]
+     }
+     * @param datasTmp {C1={'data':[{}]}}
+     */
+    private void compensateTransactional(Map<String,JSONArray> datasTmp){
+
+        Set<String> keys = datasTmp.keySet();
+
+        JSONArray compensateDatas = new JSONArray();
+
+        JSONObject compensateBoId = null;
+        for(String key : keys){
+            JSONArray datas = datasTmp.get(key);
+
+            for(int dataIndex = 0 ; dataIndex <datas.size() ; dataIndex++){
+                compensateBoId.put("boId",datas.getJSONObject(dataIndex).getString("boId"));
+                compensateBoId.put("actionTypeCd",key);
+                compensateDatas.add(compensateBoId);
+            }
+        }
+
+        JSONObject compensateData = new JSONObject();
+
+        compensateData.put("data",compensateDatas);
     }
 
     public IPrimaryKeyService getiPrimaryKeyService() {

+ 3 - 1
OrderService/src/main/resources/application.yml

@@ -2,4 +2,6 @@ spring:
   activemq:
     broker-url: tcp://localhost:61616
     in-memory: true
-    enabled: false
+    enabled: false
+  jms:
+    pub-sub-domain: true

+ 81 - 0
OrderService/src/test/java/com/java110/order/executor/ExecutorTest.java

@@ -0,0 +1,81 @@
+package com.java110.order.executor;
+
+import com.java110.order.AppTest;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * Created by wuxw on 2017/4/25.
+ */
+public class ExecutorTest  extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public ExecutorTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( ExecutorTest.class );
+    }
+
+    public void testThrowException(){
+        ExecutorService executorService = Executors.newFixedThreadPool(100);
+
+        int i = 0;
+        List<Future<Integer>> futureList = new ArrayList<Future<Integer>>();
+        while(i < 5) {
+            Future<Integer> sum = executorService.submit(new PrintInt());
+            i++;
+            futureList.add(sum);
+        }
+
+        for(Future<Integer> sum : futureList) {
+            try{
+
+                    System.out.println(sum.get());
+
+            }catch (Exception e){
+                System.out.println("异常了");
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public void testThrowException1(){
+        ExecutorService executorService = Executors.newFixedThreadPool(100);
+
+        int i = 0;
+        while(i < 5) {
+            Future<Integer> sum = executorService.submit(new PrintInt());
+            i++;
+
+            try{
+
+                System.out.println(sum.get());
+
+            }catch (Exception e){
+                System.out.println("异常了");
+                e.printStackTrace();
+            }
+
+        }
+
+    }
+
+}

+ 23 - 0
OrderService/src/test/java/com/java110/order/executor/PrintInt.java

@@ -0,0 +1,23 @@
+package com.java110.order.executor;
+
+import java.util.concurrent.Callable;
+
+/**
+ * Created by wuxw on 2017/4/25.
+ */
+public class PrintInt implements Callable<Integer> {
+    @Override
+    public Integer call() throws Exception {
+
+        System.out.println("1234567");
+
+        Thread.sleep(10000);
+        throwException();
+
+        return 1111;
+    }
+
+    private void throwException(){
+        throw new IllegalArgumentException("异常了,报出来。。。");
+    }
+}

BIN
OrderService/target/classes/com/java110/order/listener/CustDispatchListener.class


BIN
OrderService/target/classes/com/java110/order/listener/DeleteCustDispatchListener.class


BIN
OrderService/target/classes/com/java110/order/smo/impl/OrderServiceSMOImpl.class


BIN
OrderService/target/test-classes/com/java110/order/executor/ExecutorTest.class


BIN
OrderService/target/test-classes/com/java110/order/executor/PrintInt.class


+ 5 - 11
Readme.md

@@ -82,31 +82,25 @@ Java + spring cloud + mybatis + mysql + activemq + redis
 }
 
 
-3、作废订单消息消费者(目前是activemq)
+3、补偿事物(目前是activemq)
 
-请求报文 这里data下为所有要作废的订单boId 和需要恢复的订单oldBoId
+请求报文 这里data下为所有要作废的订单boId 
 
 { 
     'data':
 [
     
     {
-        'olId': '123456',
         'boId': '222222',
-        'actionTypeCd': 'C1',
-        'oldBoId':'11111'
+        'actionTypeCd': 'C1'
     },
     {
-        'olId': '123456',
         'boId': '222222',
-        'actionTypeCd': 'M1',
-        'oldBoId':'11111'
+        'actionTypeCd': 'M1'
     },
     {
-        'olId': '123456',
         'boId': '222222',
-        'actionTypeCd': 'C1',
-         'oldBoId':'11111'
+        'actionTypeCd': 'C1'
     }
 ]
 }

BIN
common/target/classes/com/java110/common/constant/ActionTypeConstant.class


BIN
common/target/classes/com/java110/common/constant/AttrCdConstant.class


BIN
common/target/classes/com/java110/common/constant/CommonConstant.class


BIN
common/target/classes/com/java110/common/constant/DomainContant.class


BIN
common/target/classes/com/java110/common/constant/ItemSpecCdConstant.class


BIN
common/target/classes/com/java110/common/constant/StatusConstant.class


+ 25 - 11
config/target/classes/META-INF/spring-configuration-metadata.json

@@ -1,14 +1,28 @@
 {
-  "groups": [{
-    "name": "java110.event.properties",
-    "type": "com.java110.config.properties.EventProperties",
-    "sourceType": "com.java110.config.properties.EventProperties"
-  }],
-  "properties": [{
-    "name": "java110.event.properties.order-dispatch-listener",
-    "type": "java.lang.String",
-    "description": "订单调度 侦听",
-    "sourceType": "com.java110.config.properties.EventProperties"
-  }],
+  "groups": [
+    {
+      "name": "java110.event.properties",
+      "type": "com.java110.config.properties.EventProperties",
+      "sourceType": "com.java110.config.properties.EventProperties"
+    },
+    {
+      "name": "java110.order",
+      "type": "com.java110.config.properties.OrderProperties",
+      "sourceType": "com.java110.config.properties.OrderProperties"
+    }
+  ],
+  "properties": [
+    {
+      "name": "java110.event.properties.order-dispatch-listener",
+      "type": "java.lang.String",
+      "description": "订单调度 侦听",
+      "sourceType": "com.java110.config.properties.EventProperties"
+    },
+    {
+      "name": "java110.order.delete-order-asyn",
+      "type": "java.lang.String",
+      "sourceType": "com.java110.config.properties.OrderProperties"
+    }
+  ],
   "hints": []
 }

BIN
config/target/classes/com/java110/config/properties/CustProperties.class


BIN
config/target/classes/com/java110/config/properties/OrderProperties.class


+ 3 - 1
config/target/classes/config/event.properties

@@ -1,7 +1,9 @@
 java110.event.properties.orderDispatchListener=\
   com.java110.order.listener.CustDispatchListener,\
+  com.java110.order.listener.DeleteCustDispatchListener,\
   com.java110.order.listener.MerchantDispatchListener
 
 java110.event.properties.orderDispatchEvent=\
   C1::com.java110.order.type.AppCustEvent,\
-  C2::com.java110.order.type.AppCustEvent
+  C2::com.java110.order.type.AppCustEvent,\
+  C1D::com.java110.order.type.AppDeleteCustEvent

+ 2 - 0
config/target/classes/config/order.properties

@@ -0,0 +1,2 @@
+# asyn S Synchronous  A asynchronous,activemq
+java110.order.deleteOrderAsyn=A

BIN
core/target/classes/com/java110/core/SystemStartUpInit.class


BIN
core/target/classes/com/java110/core/event/AppCustEvent.class


BIN
core/target/classes/com/java110/core/event/AppDeleteCustEvent.class


BIN
core/target/classes/com/java110/core/event/AppEvent.class


BIN
core/target/classes/com/java110/core/event/AppEventPublishing$1.class


BIN
core/target/classes/com/java110/core/event/AppEventPublishing.class


BIN
core/target/classes/com/java110/core/factory/AppFactory.class