Documentation ¶
Index ¶
- func ClearEndpointCache()
- type Cache
- func (c *Cache) AddServiceEndpoints(serviceName string, eps []*serviceEndpoint)
- func (c *Cache) GetLiveServiceEndpoints(serviceName string, version string, ignoreExpired ...bool) (liveEndpoints []*serviceEndpoint)
- func (c *Cache) PurgeServiceEndpointByHostAndPort(serviceName string, host string, port uint)
- func (c *Cache) PurgeServiceEndpoints(serviceName string)
- type Client
- func (c *Client) ClientConnection() grpc.ClientConnInterface
- func (c *Client) Close()
- func (c *Client) ConfiguredDialMinConnectTimeoutSeconds() uint
- func (c *Client) ConfiguredForClientDial() bool
- func (c *Client) ConfiguredForSNSDiscoveryTopicArn() bool
- func (c *Client) ConfiguredSNSDiscoveryTopicArn() string
- func (c *Client) Dial(ctx context.Context) error
- func (c *Client) DoNotifierAlertService() (err error)
- func (c *Client) GetState() connectivity.State
- func (c *Client) HealthProbe(serviceName string, timeoutDuration ...time.Duration) (grpc_health_v1.HealthCheckResponse_ServingStatus, error)
- func (c *Client) PreloadConfigData() error
- func (c *Client) Ready() bool
- func (c *Client) RemoteAddress() string
- func (c *Client) UpdateLoadBalanceResolver() error
- func (c *Client) ZLog() *data.ZapLog
- type HostDiscoveryNotification
- type NotifierClient
- func (n *NotifierClient) Close()
- func (n *NotifierClient) ConfiguredForNotifierClientDial() bool
- func (n *NotifierClient) ConfiguredSNSDiscoveryTopicArn() string
- func (n *NotifierClient) Dial() error
- func (n *NotifierClient) NotifierClientAlertServicesStarted() bool
- func (n *NotifierClient) PurgeEndpointCache()
- func (n *NotifierClient) Subscribe(topicArn string) (err error)
- func (n *NotifierClient) Unsubscribe() (err error)
- type WebServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearEndpointCache ¶ added in v1.0.8
func ClearEndpointCache()
Types ¶
type Cache ¶
type Cache struct { ServiceEndpoints map[string][]*serviceEndpoint DisableLogging bool // contains filtered or unexported fields }
func (*Cache) AddServiceEndpoints ¶
AddServiceEndpoints will append slice of service endpoints associated with the given serviceName within map
serviceName = lowercase of servicename.namespacename
func (*Cache) GetLiveServiceEndpoints ¶
func (c *Cache) GetLiveServiceEndpoints(serviceName string, version string, ignoreExpired ...bool) (liveEndpoints []*serviceEndpoint)
GetLiveServiceEndpoints will retrieve currently non-expired service endpoints and remove any expired service endpoints from map, for a given serviceName
serviceName = lowercase of servicename.namespacename
func (*Cache) PurgeServiceEndpointByHostAndPort ¶ added in v1.0.8
PurgeServiceEndpointByHostAndPort will remove a specific endpoint for a service based on host and port info
serviceName = lowercase of servicename.namespacename
func (*Cache) PurgeServiceEndpoints ¶
PurgeServiceEndpoints will remove all endpoints associated with the given serviceName within map
serviceName = lowercase of servicename.namespacename
type Client ¶
type Client struct { // client properties AppName string ConfigFileName string CustomConfigPath string // web server config - for optional gin web server to be launched upon grpc client dial WebServerConfig *WebServerConfig // indicate if after dial, client will wait for target service health probe success before continuing to allow rpc WaitForServerReady bool // one or more unary client interceptors for handling wrapping actions UnaryClientInterceptors []grpc.UnaryClientInterceptor // one or more stream client interceptors for handling wrapping actions StreamClientInterceptors []grpc.StreamClientInterceptor // typically wrapper action to handle monitoring StatsHandler stats.Handler // handler to invoke before gRPC client dial is to start BeforeClientDial func(cli *Client) // handler to invoke after gRPC client dial performed AfterClientDial func(cli *Client) // handler to invoke before gRPC client connection is to close BeforeClientClose func(cli *Client) // handler to invoke after gRPC client connection has closed AfterClientClose func(cli *Client) // contains filtered or unexported fields }
Client represents a gRPC client's connection and entry point, also provides optional gin based web server upon dial
note:
Using Compressor with RPC a) import "google.golang.org/grpc/encoding/gzip" b) in RPC Call, pass grpc.UseCompressor(gzip.Name)) in the third parameter example: RPCCall(ctx, &pb.Request{...}, grpc.UseCompressor(gzip.Name))
Notifier Client yaml a) xyz-notifier-client.yaml where xyz is the target gRPC service endpoint name
func (*Client) ClientConnection ¶
func (c *Client) ClientConnection() grpc.ClientConnInterface
ClientConnection returns the currently loaded grpc client connection
func (*Client) ConfiguredDialMinConnectTimeoutSeconds ¶ added in v1.0.7
ConfiguredDialMinConnectTimeoutSeconds gets the timeout seconds from config yaml
func (*Client) ConfiguredForClientDial ¶ added in v1.0.7
ConfiguredForClientDial checks if the config yaml is ready for client dial operation
func (*Client) ConfiguredForSNSDiscoveryTopicArn ¶ added in v1.0.7
ConfiguredForSNSDiscoveryTopicArn indicates if the sns topic arn for service discovery is configured within the config yaml
func (*Client) ConfiguredSNSDiscoveryTopicArn ¶ added in v1.0.7
ConfiguredSNSDiscoveryTopicArn returns the sns discovery topic arn as configured in config yaml
func (*Client) DoNotifierAlertService ¶ added in v1.0.8
DoNotifierAlertService should be called from goroutine after the client dial completes, this service is to subscribe and receive callbacks from notifier server of service host online offline statuses
Example:
go func() { svc1Cli.DoNotifierAlertService() }()
func (*Client) GetState ¶
func (c *Client) GetState() connectivity.State
GetState returns the current grpc client connection's state
func (*Client) HealthProbe ¶
func (c *Client) HealthProbe(serviceName string, timeoutDuration ...time.Duration) (grpc_health_v1.HealthCheckResponse_ServingStatus, error)
HealthProbe manually checks service serving health status
func (*Client) PreloadConfigData ¶ added in v1.0.7
PreloadConfigData will load the config data before Dial()
func (*Client) Ready ¶ added in v1.0.8
Ready indicates client connection is ready to invoke grpc methods
func (*Client) RemoteAddress ¶
RemoteAddress gets the remote endpoint address currently connected to
func (*Client) UpdateLoadBalanceResolver ¶ added in v1.0.8
UpdateLoadBalanceResolves updates client load balancer resolver state with new endpoint addresses
type HostDiscoveryNotification ¶ added in v1.0.8
type HostDiscoveryNotification struct { MsgType string `json:"msg_type"` Action string `json:"action"` Host string `json:"host"` }
HostDiscoveryNotification struct contains the field values for notification discovery payload
`{"msg_type":"host-discovery", "action":"online | offline", "host":"123.123.123.123:9999"}`
func (*HostDiscoveryNotification) Marshal ¶ added in v1.0.8
func (d *HostDiscoveryNotification) Marshal() (string, error)
func (*HostDiscoveryNotification) Unmarshal ¶ added in v1.0.8
func (d *HostDiscoveryNotification) Unmarshal(jsonData string) error
type NotifierClient ¶ added in v1.0.8
type NotifierClient struct { AppName string ConfigFileName string CustomConfigPath string BeforeClientDialHandler func(*Client) AfterClientDialHandler func(*Client) BeforeClientCloseHandler func(*Client) AfterClientCloseHandler func(*Client) UnaryClientInterceptorHandlers []grpc.UnaryClientInterceptor StreamClientInterceptorHandlers []grpc.StreamClientInterceptor ServiceAlertStartedHandler func() ServiceAlertSkippedHandler func(reason string) ServiceAlertStoppedHandler func(reason string) ServiceHostOnlineHandler func(host string, port uint) ServiceHostOfflineHandler func(host string, port uint) // contains filtered or unexported fields }
func NewNotifierClient ¶ added in v1.0.8
func NewNotifierClient(appName string, configFileName string, customConfigPath string, enableLogging ...bool) *NotifierClient
NewNotifierClient creates a new prepared notifier client for use in service discovery notification
func (*NotifierClient) Close ¶ added in v1.0.8
func (n *NotifierClient) Close()
Close will disconnect the notifier client from the notifier server
func (*NotifierClient) ConfiguredForNotifierClientDial ¶ added in v1.0.8
func (n *NotifierClient) ConfiguredForNotifierClientDial() bool
ConfiguredForNotifierClientDial checks if the notifier client is configured for options, where Dial can be attempted to invoke
func (*NotifierClient) ConfiguredSNSDiscoveryTopicArn ¶ added in v1.0.8
func (n *NotifierClient) ConfiguredSNSDiscoveryTopicArn() string
ConfiguredSNSDiscoveryTopicArn gets the topicArn defined for the notifier client service discovery endpoints
func (*NotifierClient) Dial ¶ added in v1.0.8
func (n *NotifierClient) Dial() error
Dial will connect the notifier client to the notifier server
func (*NotifierClient) NotifierClientAlertServicesStarted ¶ added in v1.0.8
func (n *NotifierClient) NotifierClientAlertServicesStarted() bool
NotifierClientAlertServicesStarted indicates notifier client services started via Subscribe() action
func (*NotifierClient) PurgeEndpointCache ¶ added in v1.0.8
func (n *NotifierClient) PurgeEndpointCache()
PurgeEndpointCache removes current client connection's service name ip port from cache, if current service name ip port not found, entire cache will be purged
func (*NotifierClient) Subscribe ¶ added in v1.0.8
func (n *NotifierClient) Subscribe(topicArn string) (err error)
Subscribe will subscribe this notifier client to a specified topicArn with sns, via notifier server; this subscription will also start the recurring loop to wait for notifier server stream data, for receiving service discovery host info; when service discovery host info is received, the appropriate ServiceHostOnlineHandler or ServiceHostOfflineHandler is triggered; calling the Close() or Unsubscribe() or receiving error conditions from notifier server will sever the long running service discovery process.
func (*NotifierClient) Unsubscribe ¶ added in v1.0.8
func (n *NotifierClient) Unsubscribe() (err error)
Unsubscribe will stop notification alert services and disconnect from subscription on notifier server
type WebServerConfig ¶ added in v1.0.7
type WebServerConfig struct { AppName string ConfigFileName string CustomConfigPath string // define web server router info WebServerRoutes map[string]*ginw.RouteDefinition // getter only WebServerLocalAddress string // clean up func CleanUp func() }
WebServerConfig info, note: WebServerLocalAddress = read only getter
note: WebServerRoutes = map[string]*ginw.RouteDefinition{ "base": { Routes: []*ginw.Route{ { Method: ginhttpmethod.GET, RelativePath: "/", Handler: func(c *gin.Context, bindingInputPtr interface{}) { c.String(200, "Connector Client Http Host Up") }, }, }, }, }