An open API service indexing awesome lists of open source software.

https://github.com/ollls/qh2grpc-zio


https://github.com/ollls/qh2grpc-zio

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# qh2grpc-zio

A lightweight gRPC-over-HTTP/2 framework for Scala 3 that implements native gRPC protocol support directly within a ZIO Quartz H2 HTTP/2 server--**without** using Google's standard `ServerBuilder` infrastructure.

## Key Features

- **Native gRPC-over-HTTP/2**: Implements gRPC as HTTP/2 request handlers rather than a separate server stack
- **Unified Endpoints**: Serve both HTTP/2 and gRPC endpoints with minimal overhead
- **Compile-Time Safety**: Method discovery using Scala 3 macros for zero runtime reflection
- **ZIO-Native**: Full integration with ZIO effects and streams
- **Flexible Backends**: Supports both Java NIO and Linux IO-Uring (kernel 5.1+)
- **All 4 gRPC Patterns**: Unary, server streaming, client streaming, and bidirectional streaming

## Technology Stack

- **Scala 3.3.3**
- **ZIO 2.1.16** (functional effect system)
- **zio-quartz-h2 0.7.1** (HTTP/2 server)
- **ScalaPB & zio-grpc 0.6.3** (Protocol Buffers)
- **SBT 1.10.0** (build tool)

## Quick Start

### Prerequisites

- JDK 11+
- SBT 1.10.0+
- `keystore.jks` file with password "password" (included in project)

### Running the Server

```bash
# Start the server (default: HTTPS on localhost:8443)
sbt run

# Run with different log levels
sbt "run --debug" # DEBUG level
sbt "run --error" # ERROR level
sbt "run --trace" # TRACE level
sbt "run --off" # Logging OFF
```

The server will start on `https://localhost:8443` and serve both HTTP/2 and gRPC endpoints.

### Testing the Server

#### Automated Testing

Run the comprehensive test script that validates all 4 gRPC communication patterns:

```bash
# In a separate terminal (with server running)
./test-grpc.sh
```

This tests:
- **Unary to Unary** (`SayHello`)
- **Unary to Stream** (`LotsOfReplies`)
- **Stream to Unary** (`LotsOfGreetings`)
- **Stream to Stream** (`BidiHello`)

#### Manual Testing with grpcurl

**Unary to Unary:**
```bash
grpcurl -v -insecure -proto src/main/protobuf/orders.proto \
-d '{"name": "John", "number": 101}' \
localhost:8443 com.example.protos.Greeter/SayHello
```

**Server Streaming:**
```bash
grpcurl -v -insecure -proto src/main/protobuf/orders.proto \
-d '{"name": "Alice", "number": 42}' \
localhost:8443 com.example.protos.Greeter/LotsOfReplies
```

**Client Streaming:**
```bash
grpcurl -v -insecure -proto src/main/protobuf/orders.proto \
-d @ localhost:8443 com.example.protos.Greeter/LotsOfGreetings <