Skip to content

feat: support GRPC metadata#768

Merged
anthony-swirldslabs merged 1 commit intomainfrom
765-grpcMetadata
Mar 31, 2026
Merged

feat: support GRPC metadata#768
anthony-swirldslabs merged 1 commit intomainfrom
765-grpcMetadata

Conversation

@anthony-swirldslabs
Copy link
Copy Markdown
Contributor

Description:
Adding support for passing GRPC metadata from a PBJ GRPC Client to a service and accessing the metadata in a PBJ GRPC Service implementation. Key changes:

  • Map<String, String> ServiceInterface.RequestOptions.metadata() to hold the metadata
  • ServiceInterface.* service methods have overridden versions with the additional RequestOptions argument added. Their default implementations delegate to the versions of the methods w/o the RequestOptions argument. While the latter legacy methods also have default implementations that throw UnsupportedOperationException. This way, the interface change is backward-compatible and existing services don't need to change, until/unless they want to start accessing the metadata.
  • Client stub uses its instance RequestOptions object, and also supports the newly introduced overridden versions that accept per-request RequestOptions objects. So the client is free to either create new stubs for new metadata, or simply pass a new RequestOptions instance to a service call method.
  • A new integration test is added to demonstrate and verify the behavior.

Excerpts from the generated GreeterInterface.java for the unary method (streaming methods have similar changes):

public interface GreeterInterface extends ServiceInterface {
    /** sayHello */
    @NonNull
    default HelloReply sayHello(@NonNull final HelloRequest request, @NonNull final RequestOptions requestOptions) {
        return sayHello(request);
    }
    
    /** sayHello */
    @NonNull
    default HelloReply sayHello(@NonNull final HelloRequest request) {
        throw new UnsupportedOperationException("unimplemented");
    }

    public class GreeterClient implements GreeterInterface {
        private final RequestOptions requestOptions;

        @Override
        @NonNull
        public HelloReply sayHello(@NonNull final HelloRequest request) {
            return sayHello(request, this.requestOptions);
        }
        
        @Override
        @NonNull
        public HelloReply sayHello(@NonNull final HelloRequest request, @NonNull final RequestOptions requestOptions) {
            // ...
        }
    }
}

See the new integration test for usage example.

Related issue(s):

Fixes #765

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
@github-actions
Copy link
Copy Markdown

JUnit Test Report

   78 files  ±0     78 suites  ±0   4m 27s ⏱️ + 1m 39s
1 352 tests ±0  1 348 ✅ ±0   4 💤 ±0  0 ❌ ±0 
7 234 runs  ±0  7 214 ✅ ±0  20 💤 ±0  0 ❌ ±0 

Results for commit 6baabdd. ± Comparison against base commit 5152c9d.

@github-actions
Copy link
Copy Markdown

Integration Test Report

    419 files  +1      419 suites  +1   18m 7s ⏱️ + 2m 26s
114 982 tests +5  114 982 ✅ +5  0 💤 ±0  0 ❌ ±0 
115 224 runs  +5  115 224 ✅ +5  0 💤 ±0  0 ❌ ±0 

Results for commit 6baabdd. ± Comparison against base commit 5152c9d.

Copy link
Copy Markdown
Member

@jsync-swirlds jsync-swirlds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for completing this quickly.

@anthony-swirldslabs anthony-swirldslabs merged commit 470ec7e into main Mar 31, 2026
16 checks passed
@anthony-swirldslabs anthony-swirldslabs deleted the 765-grpcMetadata branch March 31, 2026 17:05
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

Successfully merging this pull request may close these issues.

Access GRPC headers

4 participants