springCloud 분포식 사무 실전 (8) 마이크로서비스 개조 BlockMicroService 지원 분포식 사무

BlockMicroService 프로젝트에 가입 (1) jar 가입
    
    
            com.codingapi
            transaction-springcloud
            ${lcn.last.version}
            
                
                    org.slf4j
                    *
                
            
        
        
            com.codingapi
            tx-plugins-db
            ${lcn.last.version}
            
                
                    org.slf4j
                    *
                
            
        

(2) 프로필 응용 프로그램을 수정합니다.properties
   
   2
tm.manager.url=http://127.0.0.1:7000/tx/manager/

(3) 코드 파일 2개 추가
1 http TxManagerHttpRequestServiceImpl.java
package com.jh.service.impl;

import com.codingapi.tx.netty.service.TxManagerHttpRequestService;
import com.lorne.core.framework.utils.http.HttpUtils;
import org.springframework.stereotype.Service;

/**
 * http   // 3
 * 
 */

@Service
public class TxManagerHttpRequestServiceImpl implements TxManagerHttpRequestService{

    @Override
    public String httpGet(String url) {
        System.out.println("httpGet-start");
        String res = HttpUtils.get(url);
        System.out.println("httpGet-end");
        return res;
    }

    @Override
    public String httpPost(String url, String params) {
        System.out.println("httpPost-start");
        String res = HttpUtils.post(url,params);
        System.out.println("httpPost-end");
        return res;
    }
}

2 url TxManagerTxUrlServiceImpl을 가져옵니다.java
package com.jh.service.impl;

import com.codingapi.tx.config.service.TxManagerTxUrlService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 *  url
 */
@Service
public class TxManagerTxUrlServiceImpl implements TxManagerTxUrlService{

    @Value("${tm.manager.url}")
    private String url;

    @Override
    public String getTxUrl() {
        System.out.println("load tm.manager.url ");
        return url;
    }
}

(4) 통합 서비스 개선
@TxTransaction(isStart=true) //  4

    @Override
    @Transactional
    public int saveBlockTheme(Block block, Theme theme) {

        int rs1 = blockDao.saveBlock("jwg1", "111");// 3  1
        int rs2 = themeClient.saveTheme("jwg2", "111", 1);// 4  2
         int v = 100/0; // 

        return rs1 + rs2;
            }

좋은 웹페이지 즐겨찾기