grpc-generator

Jackstaff gRPC framework, Smooth and friendly use of gRPC, Code Generator

License

License

Categories

Categories

gRPC Net Networking
GroupId

GroupId

org.jackstaff.grpc
ArtifactId

ArtifactId

grpc-generator
Last Version

Last Version

2.0.13
Release Date

Release Date

Type

Type

jar
Description

Description

grpc-generator
Jackstaff gRPC framework, Smooth and friendly use of gRPC, Code Generator
Project URL

Project URL

https://github.com/jackstaff/grpc
Source Code Management

Source Code Management

https://github.com/jackstaff/grpc

Download grpc-generator

How to add to project

<!-- https://jarcasting.com/artifacts/org.jackstaff.grpc/grpc-generator/ -->
<dependency>
    <groupId>org.jackstaff.grpc</groupId>
    <artifactId>grpc-generator</artifactId>
    <version>2.0.13</version>
</dependency>
// https://jarcasting.com/artifacts/org.jackstaff.grpc/grpc-generator/
implementation 'org.jackstaff.grpc:grpc-generator:2.0.13'
// https://jarcasting.com/artifacts/org.jackstaff.grpc/grpc-generator/
implementation ("org.jackstaff.grpc:grpc-generator:2.0.13")
'org.jackstaff.grpc:grpc-generator:jar:2.0.13'
<dependency org="org.jackstaff.grpc" name="grpc-generator" rev="2.0.13">
  <artifact name="grpc-generator" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.jackstaff.grpc', module='grpc-generator', version='2.0.13')
)
libraryDependencies += "org.jackstaff.grpc" % "grpc-generator" % "2.0.13"
[org.jackstaff.grpc/grpc-generator "2.0.13"]

Dependencies

compile (3)

Group / Artifact Type Version
org.jackstaff.grpc : grpc-core jar 2.0.13
com.google.auto.service : auto-service jar 1.0-rc6
com.squareup : javapoet jar 1.12.1

Project Modules

There are no modules declared in this project.

Jackstaff gRPC framework

Quick Starts / Advance Usage / Smooth and friendly use of gRPC / Origin

Quick Starts:

Step 0: Import grpc-spring-boot-starter in pom.xml. jdk1.8

<!-- https://mvnrepository.com/artifact/org.jackstaff.grpc/grpc-spring-boot-starter -->
<dependency>
    <groupId>org.jackstaff.grpc</groupId>
    <artifactId>grpc-spring-boot-starter</artifactId>
    <version>2.0.13</version>
</dependency>

Step 1: Define protocol interface:

import java.util.function.Consumer;

public interface HelloService {

    String sayHello(String greeting); //Unary RPCs

    void lotsOfReplies(String greeting, Consumer<String> replies);//Server streaming RPCs

    Consumer<String> lotsOfGreetings(List<String> friends); //Client streaming RPCs

    Consumer<String> bidiHello(List<String> friends, Consumer<String> replies); //Bidirectional streaming RPCs

}

Step 2: Implements protocol interface(at "server side micro service" project):

import org.jackstaff.grpc.annotation.Server;
@Server(HelloService.class)
public class MyHelloService implements HelloService {

    @Override
    public String sayHello(String greeting) {
        //todo
        return "reply " + greeting;
    }

    @Override
    public void lotsOfReplies(String greeting, Consumer<String> replies) {
        //todo
        replies.accept("hi "+ greeting);
        replies.accept(":)");
    }

    @Override
    public Consumer<String> lotsOfGreetings(List<String> friends) {
        //todo
        return s-> System.out.println(s);
    }

    @Override
    public Consumer<String> bidiHello(List<String> friends, Consumer<String> replies) {
        //todo
        CompletableFuture.runAsync(()-> friends.forEach(friend->replies.accept("hi "+ friend)));
        return s-> System.out.println(s);
    }

}

Step 3: Use protocol interface (at "client side micro service" project):

import org.jackstaff.grpc.annotation.Client;

@Service
public class MyClientService {

    @Client("my-server") 
    private HelloService helloService;

    public String sayHello(String greeting){
        return helloService.sayHello(greeting);
    }
    
}

Step 4: Config "client side " application.yml:

spring:
  grpc:
    client:
      my-server:
        host: localhost
        port: 9000

Step 5: Config "server side " application.yml:

spring:
  grpc:
    server:
      port: 9000

done.

Versions

Version
2.0.13
2.0.12
2.0.11
2.0.10
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0