Coder Social home page Coder Social logo

springboot-hsf-demo's Introduction

springboot-hsf-demo

springboot 整合hsf 分布式框架

Demo入口,detail 工程,启动请参照阿里官网,Ali-Tomcat概述 1、controller 引用的是分布式服务的,引入的是item-api工程.

@RestController
public class HsfTestController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SubjectService subjectService;

    @RequestMapping(value = "/test",method = RequestMethod.POST)
    public PrimitiveSubjectBo test(@RequestBody SubjectVo subjectVo){
        logger.info("测试接口入参:"+subjectVo.toString());
        PrimitiveSubjectBo subjectBo=null;
        try {
            subjectBo= subjectService.getSubject(subjectVo.getId());
        } catch (Exception e) {
           logger.error("查询异常", e);
        }
        return subjectBo;
    }
}

2、item-api工程总的SubjectService, ProxyConsumer注解的会自动注册hsf consumer bean到spring 容器中去

@ProxyConsumer(beanId = "subjectService", version = "${ITEM_VERSION}", group = "${ITEM_GROUP}", clientTimeout = 60000)
public interface SubjectService {
    PrimitiveSubjectBo getSubject(int id);
}

3、item工程,web工程,启动请参照1步。ProxyProvider注解注解的类会自动注册hsf provider bean到spring容器中去,供远程调用。

@Service
@ProxyProvider(version = "${ITEM_VERSION}", group = "${ITEM_GROUP}")
public class SubjectServiceImpl implements SubjectService {
    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public PrimitiveSubjectBo getSubject(int id) {
        PrimitiveSubjectBo primitiveSubjectBo=new PrimitiveSubjectBo();
        PrimitiveSubjectPo subjectPo = subjectMapper.getSubject(id);
        BeanUtils.copyProperties(subjectPo, primitiveSubjectBo);
        return primitiveSubjectBo;
    }
}

ProxyProvider和ProxyConsumer注解,自动注册consumer和provider 到spring 容器的具体功能实现,都在hsf-xml-generate工程实现,所有需要引入这个功能的都需要依赖这个工程。

springboot-hsf-demo's People

Contributors

softwdog avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.