Giter Club home page Giter Club logo

snrpc's Introduction

SNRPC


-- a simple netty RPC framework use protostuff-1.07 for serializer,use netty-3.2.1 for nio.

##How to use

e.g.

1,server class; interface and implementor // define an interface: public interface SnRpcInterface { public String getMessage(String param); }

	// implement interface
	public class SnRpcImpl implements SnRpcInterface {
		public String getMessage(String param) {
			return "hi,it is message from server...param+" + param;
		}
	}

2, start server

	SnRpcInterface inter = new SnRpcImpl();
	SnRpcServer server = new SnNettyRpcServer(new Object[] { inter });
	try {
		server.start();
	} catch (Throwable e) {
		e.printStackTrace();
	}

3,config file

snrpcserver.properties

#tcpNoDelay 
snrpc.tcp.nodelay=true
#call the bind method as many times as you want
snrpc.tcp.reuseAddress=true
#ISDEBUG
snrpc.dev=true
#TCP timeout
snrpc.read.timeout=25000
#server port
snrpc.http.port=8080

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<application>
 <!-- rpc interface services -->	
 <rpcServices>
		<rpcService name="SnRpcInterface" interface="org.stefan.snrpc.server.SnRpcInterface" overload="true">
           <rpcImplementor  class="org.stefan.snrpc.server.SnRpcImpl"/> 
		</rpcService>
	</rpcServices>
</application>	

4, client invoker

	SnRpcConnectionFactory factory = new SnNettyRpcConnectionFactory(
				"localhost", 8080);
	factory = new PoolableRpcConnectionFactory(factory);
	SnRpcClient client = new CommonSnRpcClient(factory);
	try {
		SnRpcInterface clazz = client.proxy(SnRpcInterface.class);
		String message = clazz.getMessage("come on");
		System.out.println("client receive message .... : " + message);
	} catch (Throwable e) {
		e.printStackTrace();
	}

Pre-requirement

  • JDK6+
  • Maven 2

Dependency

  • reflectasm-1.07.jar
  • asm-4.0.jar
  • log4j-1.2.16.jar
  • dom4j-1.6.1.jar
  • xml-apis-1.0.b2.jar
  • slf4j-api-1.6.6.jar
  • netty-3.2.1.Final.jar
  • jaxen-1.1.6.jar
  • protostuff-core-1.0.7.jar
  • protostuff-api-1.0.7.jar
  • protostuff-runtime-1.0.7.jar
  • protostuff-collectionschema-1.0.7.jar
  • commons-pool-1.6.jar

snrpc's People

Contributors

stefzhlg 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.