2025-05-21 13:48:03 +01:00
|
|
|
---
|
|
|
|
|
layout: default
|
|
|
|
|
---
|
|
|
|
|
|
2025-05-21 12:03:24 +00:00
|
|
|
# Transport
|
|
|
|
|
|
|
|
|
|
The transport layer is responsible for communication between services.
|
|
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
- Pluggable transport implementations
|
|
|
|
|
- Secure and efficient communication
|
|
|
|
|
|
|
|
|
|
## Implementations
|
|
|
|
|
Supported transports include:
|
|
|
|
|
- TCP (default)
|
|
|
|
|
- gRPC
|
|
|
|
|
|
|
|
|
|
You can specify the transport when initializing your service.
|
|
|
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
|
|
|
|
|
Here's how to use a custom transport (e.g., gRPC) in your Go Micro service:
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"go-micro.dev/v5"
|
|
|
|
|
"go-micro.dev/v5/transport/grpc"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
t := grpc.NewTransport()
|
|
|
|
|
service := micro.NewService(
|
|
|
|
|
micro.Transport(t),
|
|
|
|
|
)
|
|
|
|
|
service.Init()
|
|
|
|
|
service.Run()
|
|
|
|
|
}
|
|
|
|
|
```
|