【zbus】framework-rpc 使用用例

1.引入pom文件:

<dependency>
    <groupId>cn.bidlink.nbl</groupId>
    <artifactId>framework-rpc</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>


2.引入spring文件:

framework-zbus jar文件中classpath:spring/applicationContext-framework-rpc-zbus.xml

配置classpath:framework-rpc-zbus.properties


3.对外提供服务:结合spring在service层代码类上添加注解@ZbusService

model

public class Project implements Serializable{

	private String id;

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
}



service interface

public interface ProjectService {

	public Project getOne();
}



service interface impl

@Service
@RpcService
public class ProjectServiceImpl implements ProjectService{

	@Override
	public Project getOne() {
		Project project = new Project();
		project.setId("1");
		return project;
	}
}


4.client端调用:

引入spring文件 framework-zbus jar文件中classpath:spring/applicationContext-framework-rpc-zbus.xml

配置classpath:framework-rpc-zbus.properties

@Controller
public class ProjectAction {
	
	private ProjectService projectService;
	
	@RpcService
	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}

	@RequestMapping("getOne")
	public Project getOne(){
		return projectService.getOne();
	}
}

原理:拦截所有spring对象的创建过程,判断方法上的注解,如果有@RpcService则从Zbus RpcFactory中取出对象,反射给bean参数。

注:如有更好的方法,请告知,不胜感激。


你可能感兴趣的:(【zbus】framework-rpc 使用用例)