go.uber.org/yarpc@v1.72.1/api/transport/outbound.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package transport 22 23 import "context" 24 25 // Outbound is the common interface for all outbounds. 26 // 27 // Outbounds should also implement the Namer interface so that YARPC can 28 // properly update the Request.Transport field. 29 type Outbound interface { 30 Lifecycle 31 32 // Transports returns the transports that used by this outbound, so they 33 // can be collected for lifecycle management, typically by a Dispatcher. 34 // 35 // Though most outbounds only use a single transport, composite outbounds 36 // may use multiple transport protocols, particularly for shadowing traffic 37 // across multiple transport protocols during a transport protocol 38 // migration. 39 Transports() []Transport 40 } 41 42 // Namer is an additional interface that Outbounds may implement in order 43 // properly set the transport.Request#Transport field. 44 // 45 // This interface is not embeded into Outbound to preserve backwards 46 // compatiblity. 47 type Namer interface { 48 TransportName() string 49 } 50 51 // UnaryOutbound is a transport that knows how to send unary requests for procedure 52 // calls. 53 type UnaryOutbound interface { 54 Outbound 55 56 // Call sends the given request through this transport and returns its 57 // response. 58 // 59 // This MUST NOT be called before Start() has been called successfully. This 60 // MAY panic if called without calling Start(). This MUST be safe to call 61 // concurrently. 62 Call(ctx context.Context, request *Request) (*Response, error) 63 } 64 65 // OnewayOutbound is a transport that knows how to send oneway requests for 66 // procedure calls. 67 type OnewayOutbound interface { 68 Outbound 69 70 // CallOneway sends the given request through this transport and returns an 71 // ack. 72 // 73 // This MUST NOT be called before Start() has been called successfully. This 74 // MAY panic if called without calling Start(). This MUST be safe to call 75 // concurrently. 76 CallOneway(ctx context.Context, request *Request) (Ack, error) 77 } 78 79 // StreamOutbound is a transport that knows how to send stream requests for 80 // procedure calls. 81 type StreamOutbound interface { 82 Outbound 83 84 // CallStream creates a stream connection based on the metadata in the 85 // request passed in. If there is a timeout on the context, this timeout 86 // is for establishing a connection, and not for the lifetime of the stream. 87 CallStream(ctx context.Context, request *StreamRequest) (*ClientStream, error) 88 } 89 90 // Outbounds encapsulates the outbound specification for a service. 91 // 92 // This includes the service name that will be used for outbound requests as 93 // well as the Outbound that will be used to transport the request. The 94 // outbound will be one of Unary and Oneway. 95 type Outbounds struct { 96 ServiceName string 97 98 // If set, this is the unary outbound which sends a request and waits for 99 // the response. 100 Unary UnaryOutbound 101 102 // If set, this is the oneway outbound which sends the request and 103 // continues once the message has been delivered. 104 Oneway OnewayOutbound 105 106 // If set, this is the stream outbound which creates a ClientStream that can 107 // be used to continuously send/recv requests over the connection. 108 Stream StreamOutbound 109 }