go-micro.dev/v5@v5.12.0/internal/website/docs/transport.md (about) 1 --- 2 layout: default 3 --- 4 5 # Transport 6 7 The transport layer is responsible for communication between services. 8 9 ## Features 10 - Pluggable transport implementations 11 - Secure and efficient communication 12 13 ## Implementations 14 Supported transports include: 15 - HTTP (default) 16 - NATS (`go-micro.dev/v5/transport/nats`) 17 - gRPC (`go-micro.dev/v5/transport/grpc`) 18 - Memory (`go-micro.dev/v5/transport/memory`) 19 20 ## Important: Transport vs Native gRPC 21 22 The gRPC **transport** uses gRPC as an underlying communication protocol, similar to how NATS or RabbitMQ might be used. It does **not** provide native gRPC compatibility with tools like `grpcurl` or standard gRPC clients generated by `protoc`. 23 24 If you need native gRPC compatibility (to use `grpcurl`, polyglot gRPC clients, etc.), you must use the gRPC **server** and **client** packages instead: 25 26 ```go 27 import ( 28 grpcServer "go-micro.dev/v5/server/grpc" 29 grpcClient "go-micro.dev/v5/client/grpc" 30 ) 31 32 // Important: Server must be specified before Name 33 service := micro.NewService( 34 micro.Server(grpcServer.NewServer()), 35 micro.Client(grpcClient.NewClient()), 36 micro.Name("myservice"), 37 ) 38 ``` 39 40 See [Native gRPC Compatibility](guides/grpc-compatibility.md) for a complete guide. 41 42 Plugins are scoped under `go-micro.dev/v5/transport/<plugin>`. 43 44 You can specify the transport when initializing your service or via env vars. 45 46 ## Example Usage 47 48 Here's how to use a custom transport (e.g., gRPC) in your Go Micro service: 49 50 ```go 51 package main 52 53 import ( 54 "go-micro.dev/v5" 55 "go-micro.dev/v5/transport/grpc" 56 ) 57 58 func main() { 59 t := grpc.NewTransport() 60 service := micro.NewService( 61 micro.Transport(t), 62 ) 63 service.Init() 64 service.Run() 65 } 66 ``` 67 68 NATS transport: 69 ```go 70 import ( 71 "go-micro.dev/v5" 72 tnats "go-micro.dev/v5/transport/nats" 73 ) 74 75 func main() { 76 t := tnats.NewTransport() 77 service := micro.NewService(micro.Transport(t)) 78 service.Init() 79 service.Run() 80 } 81 ``` 82 83 ## Configure via environment 84 85 ```bash 86 MICRO_TRANSPORT=nats MICRO_TRANSPORT_ADDRESS=nats://127.0.0.1:4222 go run main.go 87 ``` 88 89 Common variables: 90 - `MICRO_TRANSPORT`: selects the transport implementation (`http`, `nats`, `grpc`, `memory`). 91 - `MICRO_TRANSPORT_ADDRESS`: comma-separated list of transport addresses.