Skip to content

A library of interceptors for ConnectRPC that I've found handy

License

Notifications You must be signed in to change notification settings

ericvolp12/connect-interceptors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConnectRPC Interceptors

A library of interceptors for ConnectRPC that I've found handy

Interceptors

  • pkg/retry - An interceptor that allows you to retry RPCs that fail with specific error conditions.
    • Supports custom backoff strategies and custom functions for parsing errors to determine if you should retry.
    • Defaults to a 1 second backoff, 10 retry maximum, and automatic retries on connection errors.
  • pkg/prom - An interceptor that adds some prometheus metrics to your RPCs to track latencies and request throughput.
    • Make sure to call RegisterMetrics(registry) with your prometheus registerer if you're not using the default registerer (if you are, promauto will take care of it).
    • Feel free to fork this one and tune the buckets or add additional metrics for your service.

Using an Interceptor

Read more about ConnectRPC Interceptors here

To plug any of these interceptors into your ConnectRPC Client or Server, you can initialize your server or client as follows:

import (
    "github.com/ericvolp12/connect-interceptors/pkg/retry"
)

interceptors := connect.WithInterceptors(retry.NewRetryInterceptor(nil, nil))

// For handlers:
mux := http.NewServeMux()
mux.Handle(greetv1connect.NewGreetServiceHandler(
  &greetServer{},
  interceptors,
))

// For clients:
client := greetv1connect.NewGreetServiceClient(
  http.DefaultClient,
  "https://api.acme.com",
  interceptors,
)

About

A library of interceptors for ConnectRPC that I've found handy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages