Code Monkey home page Code Monkey logo

fepss-rpc's Introduction

Protocol Buffers RPC Server Implemention based on Tapestry(5.1.0.5) ,Mina(2.0.0-RC1) and Protobuf(2.1.0)

== Usage ==

ses RpcApplicationTest.java

1) define your service ,eg:test.proto

package protobuf.socketrpc;

option java_package = "com.fepss.rpc.test";
option java_outer_classname = "TestProto";

message User{
	optional string userName=1;
}
message Result{
	optional string result=1;
	optional bool success=2;
}

service TestService {
  rpc TestMethod(User) returns(Result);
}

2) generate service code
protoc test.proto --java_out .

3) implement your service.
public class TestServiceImpl extends TestService{

	@Override
	public void testMethod(RpcController controller, User request,
			RpcCallback<Result> done) {
		Builder builder =Result.newBuilder().setResult("get user"+request.getUserName());
		builder.setSuccess(true);
		done.run(builder.build());
	}
}
4) client call,RpcApplicationTest.java
		@Test
	public void testRpc() throws IOException{
		RpcApplication application = new RpcApplication(TestModule.class);
		try{
			application.start();
			// create client to call rpc
			RpcChannelImpl channel = new RpcChannelImpl(RpcConstants.DEFAULT_HOST,RpcConstants.DEFAULT_PORT);
			RpcController controller = channel.newRpcController();
			Stub service = TestService.newStub(channel);
			// request data
			String reqdata = "Request Data";
			User request = User.newBuilder().setUserName(reqdata).build();

			// response callback
			RpcCallback<Result> done = new RpcCallback<Result>() {
				@Override
				public void run(Result result) {
					Assert.assertEquals(result.getResult(),
							"get userRequest Data");
					Assert.assertTrue(result.getSuccess());

				}
			};
			// execute remote method
			service.testMethod(controller, request, done);
			Assert.assertFalse(controller.failed());
			Assert.assertEquals(controller.errorText(), null);
		}finally{
			application.stop();
		}
		
	}
	public static class TestModule{
		public static void contributeIoHandler(MappedConfiguration<String,Service> configruation){
			configruation.add(TestService.getDescriptor().getFullName(),new TestServiceImpl());
		}
	}
		
5)feedback  Jun.Tsai AT gmail.com

fepss-rpc's People

Contributors

jcai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

snifferhu

fepss-rpc's Issues

Handles merges/split tcp messages?

I took a look at your protobus message decoder and it looks like it doesn't handle when two tcp packets are either merged or split up.

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.