Skip to content

Commit

Permalink
NettyRPC 2.0 pojo rpc demo by tangjie
Browse files Browse the repository at this point in the history
NettyRPC 2.0 pojo rpc demo by tangjie
  • Loading branch information
tang-jie committed Nov 7, 2016
1 parent 9eaf20e commit 0e91a55
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NettyRPC 2.0/NettyRPC Version 2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NettyRPC 2.0 Build 2016/10/7 by tangjie
* RPC服务启动、注册、卸载支持通过Spring中的nettyrpc标签进行统一管理。
* 在原来编码解码器:JDK原生的对象序列化方式、kryo、hessian,新增了:protostuff。
* 优化了NettyRPC服务端的线程池模型,支持LinkedBlockingQueue、ArrayBlockingQueue、SynchronousQueue,并扩展了多个线程池任务处理策略。
* NettyRPC服务端加入JMX监控支持。



Expand All @@ -13,4 +14,5 @@ NettyRPC 2.0 Build 2016/10/7 by tangjie
* RPC service startup, registration, uninstall support through the nettyrpc Spring tags for unified management.
* in the original codec: JDK native object serialization mode, kryo, hessian, added: protostuff.
* optimize the NettyRPC server's thread pool model, support LinkedBlockingQueue, ArrayBlockingQueue, SynchronousQueue, and expand the various thread pool task processing strategy.
* NettyRPC JMX monitoring support.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.services;

import com.newlandframework.rpc.services.pojo.Person;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:PersonManage.java
* @description:PersonManage功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/11/7
*/
public interface PersonManage {
int save(Person p);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.services.impl;

import com.newlandframework.rpc.services.PersonManage;
import com.newlandframework.rpc.services.pojo.Person;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:PersonManageImpl.java
* @description:PersonManageImpl功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/11/7
*/
public class PersonManageImpl implements PersonManage {
public int save(Person p) {
//your business logic code here!
System.out.println("person data[" + p + "] has save!");
return 0;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.services.pojo;

import java.io.Serializable;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:Person.java
* @description:Person功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/11/7
*/
public class Person implements Serializable {
private int id;
private String name;
private int age;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String toString() {
return String.format("Person <<id:%d name:%s age:%d>>", id, name, age);
}
}

3 changes: 3 additions & 0 deletions NettyRPC 2.0/main/resources/rpc-invoke-config-server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
ref="calcAddService"></nettyrpc:service>
<nettyrpc:service id="demoMultiService" interfaceName="com.newlandframework.rpc.services.MultiCalculate"
ref="calcMultiService"></nettyrpc:service>
<nettyrpc:service id="demoPersonManage" interfaceName="com.newlandframework.rpc.services.PersonManage"
ref="personManageService"></nettyrpc:service>
<nettyrpc:registry id="rpcRegistry" ipAddr="${rpc.server.addr}" protocol="PROTOSTUFFSERIALIZE"></nettyrpc:registry>
<bean id="calcAddService" class="com.newlandframework.rpc.services.impl.AddCalculateImpl"></bean>
<bean id="calcMultiService" class="com.newlandframework.rpc.services.impl.MultiCalculateImpl"></bean>
<bean id="personManageService" class="com.newlandframework.rpc.services.impl.PersonManageImpl"></bean>
</beans>
47 changes: 47 additions & 0 deletions NettyRPC 2.0/test/java/com/newlandframework/test/PojoCallTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.test;

import com.newlandframework.rpc.services.PersonManage;
import com.newlandframework.rpc.services.pojo.Person;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:PojoCallTest.java
* @description:PojoCallTest功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/11/7
*/
public class PojoCallTest {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:rpc-invoke-config-client.xml");

PersonManage manage = (PersonManage) context.getBean("personManage");

Person p = new Person();
p.setId(20150811);
p.setName("XiaoHaoBaby");
p.setAge(1);

int result = manage.save(p);

System.out.println("call pojo rpc result:" + result);

context.destroy();
}
}

2 changes: 2 additions & 0 deletions NettyRPC 2.0/test/resources/rpc-invoke-config-client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
protocol="PROTOSTUFFSERIALIZE" ipAddr="${rpc.server.addr}"/>
<nettyrpc:reference id="multiCalc" interfaceName="com.newlandframework.rpc.services.MultiCalculate"
protocol="PROTOSTUFFSERIALIZE" ipAddr="${rpc.server.addr}"/>
<nettyrpc:reference id="personManage" interfaceName="com.newlandframework.rpc.services.PersonManage"
protocol="PROTOSTUFFSERIALIZE" ipAddr="${rpc.server.addr}"/>
</beans>

0 comments on commit 0e91a55

Please sign in to comment.