hunt-service 0.0.1

Distributed RPC framework for DLang based on neton.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Getting started

The following code snippet comes from Hunt-service examples. You may clone the sample project.

# git clone https://github.com/huntlabs/hunt-service.git
# cd examples

Define rpc service

syntax = "proto3";

package example.api;



service Hello {
 
  rpc sayHello(HelloRequest) returns (HelloResponse) {

  }

}

message HelloRequest{
  string name = 1;
}

message HelloResponse{
  string echo = 1;
}

See [example/proto/example.proto](https://github.com/huntlabs/hunt-service/blob/master/examples/proto/example.proto) on GitHub.

Implement service interface for the provider

module HelloService;

import example.api.examplerpc;
import example.api.example;
import grpc;

class HelloService : HelloBase
{
	override Status sayHello(HelloRequest req, ref HelloResponse resp)
    { 
        resp.echo = "hello ," ~ req.name;
        return Status.OK; 
    }

}

See [provider/source/HelloService.d](https://github.com/huntlabs/hunt-service/blob/master/examples/provider/source/HelloService.d) on GitHub.

Start service provider

NetUtil.startEventLoop();

auto providerFactory = new RpcProviderFactory("127.0.0.1",7788);

// If you use a registry, use the following options
// RegistryConfig conf = {"127.0.0.1",50051,"example.provider"};
// providerFactory.setRegistry(conf);

providerFactory.addService(new HelloService());
providerFactory.start();

See [provider/source/app.d](https://github.com/huntlabs/hunt-service/blob/master/examples/provider/source/app.d) on GitHub.

Build and run the provider

# cd provide
# dub run

Call remote service in consumer

NetUtil.startEventLoop();

auto invokerFactory = new RpcInvokerFactory();

// If you use a registry, use the following options
// RegistryConfig conf = {"127.0.0.1",50051,"example.provider"};
// invokerFactory.setRegistry(conf);

invokerFactory.setDirectUrl("tcp://127.0.0.1:7788");
auto client = invokerFactory.createClient!(HelloClient)();
assert(client !is null);

HelloRequest req = new HelloRequest();
foreach(num; 1 .. 10) {
	req.name = to!string(num);
	auto respon = client.sayHello(req);
	writeln("response : ",respon.echo);
}

Build and run the consumer

# cd consumer
# dub run

See [consumer/source/app.d](https://github.com/huntlabs/hunt-service/blob/master/examples/consumer/source/app.d) on GitHub.

Dependencies:
neton-client, grpc
Versions:
0.0.1 2019-Mar-19
0.0.0 2019-Mar-18
~master 2019-Jun-25
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 17 downloads total

Score:
1.1
Short URL:
hunt-service.dub.pm