Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports Interface Exposure Mode #182

Open
kwsc98 opened this issue Mar 15, 2024 · 0 comments
Open

Supports Interface Exposure Mode #182

kwsc98 opened this issue Mar 15, 2024 · 0 comments

Comments

@kwsc98
Copy link

kwsc98 commented Mar 15, 2024

Supports Interface Exposure Mode, make a webServer ? httpClient like fegin ?

For Example

Interface Definition

#[fusen_trait(package = "org.apache.dubbo.springboot.demo",version = "1.0.0")]
#[resource(method = POST)]
pub trait DemoService {
    #[resource(path="/sayHello11",method = POST)]
    async fn sayHello(&self, name: String) -> String;

    #[resource(path="/sayHelloV22",method = POST)]
    async fn sayHelloV2(&self, name: ReqDto) -> ResDto;
}

Server

#[derive(Clone)]
struct TestServerImpl {
    _db: String,
}

#[fusen_server(version="1.0.0")]
#[resource(path="/TestServer",method = POST)]
impl TestServer for TestServerImpl {
    
    #[resource(path="/doRun1",method = POST)]
    async fn do_run1(&self, req1: ReqDto, req2: ReqDto) -> FusenResult<ResDto> {
        info!("req1 : {:?} , req1 : {:?}", req1, req2);
        return Ok(ResDto {
            str: "Hello ".to_owned() + &req1.str + " " + &req2.str + " V1",
        });
    }
    
    #[resource(path="/doRun2",method = POST)]
    async fn doRun2(&self, req: ReqDto) -> FusenResult<ResDto> {
        info!("res : {:?}", req);
        return Ok(ResDto {
            str: "Hello ".to_owned() + &req.str + " V2",
        });
    }
}

#[tokio::main(worker_threads = 512)]
async fn main() {
    fusen_common::init_log();
    let server: TestServerImpl = TestServerImpl {
        _db: "我是一个DB数据库".to_string(),
    };
    FusenServer::build()
        .add_register_builder(RegisterBuilder::new(
            &format!("127.0.0.1:{}", "2181"),
            "default",
            RegisterType::ZooKeeper,
        ))
        .add_protocol(Protocol::HTTP("8082".to_owned()))
        .add_protocol(Protocol::HTTP2("8081".to_owned()))
        .add_fusen_server(Box::new(server))
        .run()
        .await;
}

Client

#[tokio::main(worker_threads = 512)]
async fn main() {
    let de = TestServerClient::new(&CLI);
    println!("{:?}",de.get_info());
    fusen_common::init_log();
    let client = de;
    let res = client
        .do_run1(
            ReqDto {
                str: "client say hello 1".to_string(),
            },
            ReqDto {
                str: "client say hello 2".to_string(),
            },
        )
        .await;
    info!("{:?}", res);
    let res = client
        .doRun2(ReqDto {
            str: "client say hello 2".to_string(),
        })
        .await;
    info!("{:?}", res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant