1 Star 0 Fork 47

zhangchaoltt / lamp

forked from 郑大侠 / lamp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

#lamp

基于netty&spring容器封装的json通讯协议组件

##modules Alt text ##protocol

现仅支持私有JSONP协议 TODO 自定义协议扩展,开放解包封包实现

###JSONP实现 RequestJSON

{
	"id": 0,
	"uri": "/lamp/test",
	"data": {
		"name": "dempe"
	}
}
  • id: 消息序列号,用户标志消息
  • uri:消息uri,用户路由到对应业务
  • data: 请求参数json

ResponseJSON

{
	"id": 0,
	"uri": "/lamp/test",
	"data": {
		"data": "6666"
	}

}
  • id: 消息序列号,用户标志消息
  • uri:消息uri,对应请求uri
  • data: 返回结果

##example ###服务端的打开方式 ####基于spring注解的打开方式

@Configuration
@ComponentScan
public class LampServer {

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(LampServer.class);
        BaseServer baseServer = new BaseServer(DefConfigFactory.createDEVConfig(), context);
        baseServer.start();
    }
}

####基于spring xml的打开方式

 ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
        BaseServer baseServer = new BaseServer(DefConfigFactory.createDEVConfig(), context);
        baseServer.start();

application.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config/>
    <!-- 主动搜索以下目录 -->
    <context:component-scan base-package="com.dempe.lamp"/>

</beans>

###业务逻辑的编写方式

@Controller("lamp")
public class LampController {

    @Resource
    LampService lampService;

    @Path
    public JSONObject test(@Param String name) {
        System.out.println("name===>" + name);
        lampService.say();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 6666);
        return jsonObject;
    }
}

###客户端的使用方式

public class LampClient {
    public static void main(String[] args) {
        ReplyClient client = new ReplyClient("localhost", 8888);
        JSONObject data = new JSONObject();
        data.put("name", "dempe");
        JSONRequest request = new JSONRequest("/lamp/test", data);
        Response response = client.sendAndWait(request);
        client.sendOnly(request);
        System.out.println(response);
    }
}

空文件

简介

[netty+spring ioc]基于netty&spring ioc实现自定义协议通讯框架 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zhangchaoltt/lamp.git
git@gitee.com:zhangchaoltt/lamp.git
zhangchaoltt
lamp
lamp
master

搜索帮助

14c37bed 8189591 565d56ea 8189591