Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created March 4, 2022 07:29
Show Gist options
  • Save percybolmer/9d4fea5b2724e19ab50559a8cb74f441 to your computer and use it in GitHub Desktop.
Save percybolmer/9d4fea5b2724e19ab50559a8cb74f441 to your computer and use it in GitHub Desktop.
// SetupCadenceClient is used to create the client we can use
func SetupCadenceClient() (*CadenceClient, error) {
// Create a dispatcher used to communicate with server
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: cadenceClientName,
Outbounds: yarpc.Outbounds{
// This shouldnt be hard coded in real app
// This is a map, so we store this communication channel on "cadence-frontend"
cadenceService: {Unary: grpc.NewTransport().NewSingleOutbound("localhost:7833")},
},
})
// Start dispatcher
if err := dispatcher.Start(); err != nil {
return nil, err
}
// Grab the Configurations from the Dispatcher based on cadenceService name
yarpConfig := dispatcher.ClientConfig(cadenceService)
// Build the workflowserviceClient that handles the workflows
wfClient := workflowserviceclient.New(yarpConfig)
// clientoptions used to control metrics etc
config := zap.NewDevelopmentConfig()
config.Level.SetLevel(zapcore.InfoLevel)
var err error
logger, err := config.Build()
if err != nil {
return nil, fmt.Errorf("failed to build logger: %v", err)
}
// Start prom scope
reporter, err := localprom.NewPrometheusReporter("127.0.0.1:9099", logger)
if err != nil {
return nil, err
}
// use WorkerScope
metricsScope := localprom.NewWorkerScope(reporter)
opts := &client.Options{
MetricsScope: metricsScope,
}
// Build the Cadence Client
cadenceClient := client.NewClient(wfClient, "tavern", opts)
return &CadenceClient{
dispatcher: dispatcher,
wfClient: wfClient,
client: cadenceClient,
}, nil
}// SetupCadenceClient is used to create the client we can use
func SetupCadenceClient() (*CadenceClient, error) {
// Create a dispatcher used to communicate with server
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: cadenceClientName,
Outbounds: yarpc.Outbounds{
// This shouldnt be hard coded in real app
// This is a map, so we store this communication channel on "cadence-frontend"
cadenceService: {Unary: grpc.NewTransport().NewSingleOutbound("localhost:7833")},
},
})
// Start dispatcher
if err := dispatcher.Start(); err != nil {
return nil, err
}
// Grab the Configurations from the Dispatcher based on cadenceService name
yarpConfig := dispatcher.ClientConfig(cadenceService)
// Build the workflowserviceClient that handles the workflows
wfClient := workflowserviceclient.New(yarpConfig)
// clientoptions used to control metrics etc
config := zap.NewDevelopmentConfig()
config.Level.SetLevel(zapcore.InfoLevel)
var err error
logger, err := config.Build()
if err != nil {
return nil, fmt.Errorf("failed to build logger: %v", err)
}
// Start prom scope
reporter, err := localprom.NewPrometheusReporter("127.0.0.1:9099", logger)
if err != nil {
return nil, err
}
// use WorkerScope
metricsScope := localprom.NewWorkerScope(reporter)
opts := &client.Options{
MetricsScope: metricsScope,
}
// Build the Cadence Client
cadenceClient := client.NewClient(wfClient, "tavern", opts)
return &CadenceClient{
dispatcher: dispatcher,
wfClient: wfClient,
client: cadenceClient,
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment