c# (.net框架) 与eclipse rcp 中 java通过thrift通信例子(eclipse rcp端部署)

文章介绍了使用Thrift框架在Java中创建用户服务接口、实现服务端和客户端的方法,以及如何配置项目构建和运行环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

整体架构

在这里插入图片描述

源码—user.thrift

namespace java com.tuliing
struct User{
1:i32 id
2:string name
3:i32 age=0
}
service UserService{
User getById(1:i32 id),
bool isExist(1:string name)
}
编译
thrift -r -gen java user.thrift
生成gen-java文件夹

源码–实现

package com.tuliing;

import org.apache.thrift.TException;



public class UserServiceImpl implements UserService.Iface{
	
	@Override
	public User getById(int id) throws TException {
		// TODO Auto-generated method stub
		System.out.print("getById....");
		
		User user = new User();
		user.setId(11);
		user.setName("this is name");
		user.setAge(10);
		
		return user;
	}
	
	@Override
	public boolean isExist(String name) throws TException {
		// TODO Auto-generated method stub
		System.out.print("isExist ....");
		
		return false;
	}

}

源码—启动客户端

package com.tuliing;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TSimpleFileTransport;
import org.apache.thrift.transport.TTransportException;

public class simpleService {
	public static void main(String [] args) throws TTransportException {
		TServerTransport serverTransport = new TServerSocket(9090);
		UserService.Processor processor = new UserService.Processor(new UserServiceImpl());
		
		TBinaryProtocol.Factory protocolFactory = new TBinaryProtocol.Factory();
		
		TSimpleServer.Args targs = new TSimpleServer.Args(serverTransport);
		
		targs.processor(processor);
		
		targs.protocolFactory(protocolFactory);
		
		TServer server = new TSimpleServer(targs);
		
		System.out.println("start simple server....");
	
		server.serve();
		
	}
}

配置—build path

在这里插入图片描述

配置–runtime

如果只是通过启动客户端的main启动,不需要这个配置,如果是多个插件项目,需要这个配置
在这里插入图片描述

配置–pruduct

如果你的项目是插件1,插件2,插件…
且插件1被打包成product,插件2是上述的内容,
且插件2希望被自动加载以启动服务器
此时需要配置product
打开product配置,右侧的最下面选项卡第二个contents,添加你的插件2

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值