RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

    • Extension Components Overview
    • filter

    • transform

    • external

      • redisClient
      • kafkaProducer
      • natsClient
      • rabbitmqClient
      • opengeminiWrite
      • opengeminiQuery
      • MongoDB Client
      • Redis Publisher
      • grpcClient
        • Configuration
        • Relation Type
        • Execution Result
        • Example
      • OpenTelemetry
      • BeanstalkdWorker
      • BeanstalkdTube
      • WukongimSender
    • ai

    • ci

    • IoT

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

目录

grpcClient

x/grpcClient Component: v0.25.0+ gRPC client. Allows dynamic invocation of gRPC services.

The gRPC server must register the gRPC reflection service. This allows clients to query the services and methods supported by the server at runtime.

# Configuration

This component allows reusing shared connection clients through the server field. Refer to Component Connection Reuse.

Field Type Description Default
server string gRPC service address, format: hostname:port None
service string gRPC service name, can use Component Configuration Variables None
method string gRPC method name, can use Component Configuration Variables None
request string Request parameters, if empty, use the current message payload. Use JSON encoded, structure must match the requirements of service/method None
headers map Request header, can using Component Configuration Variables.

# Relation Type

  • Success: Execution successful, send the message to the Success chain
  • Failure: Execution failed, send the message to the Failure chain

# Execution Result

The query result is assigned to the message payload and passed to the next node.

# Example

  1. Define a gRPC service as follows:
syntax = "proto3";

package helloworld;

option go_package = ".;helloworld";

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  1. Generate protobuf code
protoc --go_out=. --go-grpc_out=. helloworld.proto
1
  1. Run the server
package main

import (
	"context"
	pb "github.com/rulego/rulego-components/external/grpc/testdata/helloworld"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
	"log"
	"net"
)

// server is the server implementation of the Greeter service
type server struct {
	pb.UnimplementedGreeterServer
}

// SayHello implements the SayHello method of the Greeter service
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
	log.Printf("Received: %v", in.GetName())
	return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil
}

func main() {
	listen, err := net.Listen("tcp", ":50051")
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	pb.RegisterGreeterServer(s, &server{})
	// Register gRPC reflection service
	reflection.Register(s)
	// Start the server
	if err := s.Serve(listen); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  1. Call the server through the grpcClient component
{
    "id": "s1",
    "type": "x/grpcClient",
    "name": "call grpc service",
    "configuration": {
      "server":  "127.0.0.1:50051",
      "service": "helloworld.Greeter",
      "method":  "SayHello",
      "request": "{\"name\": \"lulu\"}"
    }
}
1
2
3
4
5
6
7
8
9
10
11
Edit this page on GitHub (opens new window)
Last Updated: 2025/04/02, 01:29:50
Redis Publisher
OpenTelemetry

← Redis Publisher OpenTelemetry→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式