Skip to content

Commit

Permalink
Merge pull request #53 from aureamunoz/add-grpc
Browse files Browse the repository at this point in the history
refactor and add grpc getting started
  • Loading branch information
aureamunoz authored Mar 1, 2024
2 parents b7f2349 + 0ee17f0 commit 7086e53
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public String city() {
}
```
2. Update the content of `HelloResource` to become:

```java
package org.acme;

import org.acme.getting.started.GreetingService;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.inject.Inject;
Expand Down Expand Up @@ -218,12 +220,13 @@ public class Book extends PanacheEntity {
### Define the interfaces for generation

REST Data with Panache generates JAX-RS resources based on the interfaces available in your application.
For that, we need to create the following interface:
For that, we need to create the following interface:

````java
package org.acme;

import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource;
import org.acme.orm.rest.data.Book;

public interface BookResource extends PanacheEntityResource<Book, Long> {
}
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.acme;
package org.acme.getting.started;

import org.eclipse.microprofile.config.inject.ConfigProperty;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.acme;
package org.acme.getting.started;

import org.eclipse.microprofile.config.inject.ConfigProperty;

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/acme/grpc/ExampleResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.acme.grpc;

import io.quarkus.example.Greeter;
import io.quarkus.example.HelloRequest;
import io.quarkus.grpc.GrpcClient;
import io.smallrye.mutiny.Uni;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/greeting")
public class ExampleResource {

@GrpcClient
Greeter hello;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}

@GET
@Path("/{name}")
public Uni<String> hello(String name) {
return hello.sayHello(HelloRequest.newBuilder().setName(name).build()).onItem()
.transform(helloReply -> helloReply.getMessage());
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/acme/grpc/HelloService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme;

import io.quarkus.example.Greeter;
import io.quarkus.example.HelloReply;
import io.quarkus.example.HelloRequest;
import io.quarkus.grpc.GrpcService;
import io.smallrye.mutiny.Uni;

@GrpcService
public class HelloService implements Greeter {

@Override
public Uni<HelloReply> sayHello(HelloRequest request) {
return Uni.createFrom().item(() -> HelloReply.newBuilder().setMessage("Hello " + request.getName()).build());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.acme;
package org.acme.orm.rest.data;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.acme;
package org.acme.orm.rest.data;

import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource;
import io.quarkus.rest.data.panache.MethodProperties;
Expand Down
23 changes: 23 additions & 0 deletions src/main/proto/helloworld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.quarkus.example";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ quarkus.datasource.jdbc.max-size=8
%prod.quarkus.hibernate-orm.sql-load-script=import.sql

quarkus.hibernate-orm.database.generation=drop-and-create

quarkus.grpc.clients.hello.host=localhost

0 comments on commit 7086e53

Please sign in to comment.