sequence

This paper mainly studies the availableCluster of Dubo-Go

NewAvailableCluster

Dubbo – go – v1.4.2 / cluster/cluster_impl available_cluster. Go

type availableCluster struct{}

const available = "available"

func init() {
	extension.SetCluster(available, NewAvailableCluster)
}

// NewAvailableCluster ...
func NewAvailableCluster() cluster.Cluster {
	return &availableCluster{}
}
Copy the code
  • The NewAvailableCluster method instantiates availableCluster

Join

Dubbo – go – v1.4.2 / cluster/cluster_impl available_cluster. Go

func (cluser *availableCluster) Join(directory cluster.Directory) protocol.Invoker {
	return NewAvailableClusterInvoker(directory)
}
Copy the code
  • The Join method performs NewAvailableClusterInvoker

NewAvailableClusterInvoker

Dubbo – go – v1.4.2 / cluster/cluster_impl available_cluster_invoker. Go

type availableClusterInvoker struct {
	baseClusterInvoker
}

// NewAvailableClusterInvoker ...
func NewAvailableClusterInvoker(directory cluster.Directory) protocol.Invoker {
	return &availableClusterInvoker{
		baseClusterInvoker: newBaseClusterInvoker(directory),
	}
}
Copy the code
  • Instantiation availableClusterInvoker NewAvailableClusterInvoker method

Invoke

Dubbo – go – v1.4.2 / cluster/cluster_impl available_cluster_invoker. Go

func (invoker *availableClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { invokers := invoker.directory.List(invocation) err := invoker.checkInvokers(invokers, invocation) if err ! = nil { return &protocol.RPCResult{Err: err} } err = invoker.checkWhetherDestroyed() if err ! = nil { return &protocol.RPCResult{Err: err} } for _, ivk := range invokers { if ivk.IsAvailable() { return ivk.Invoke(ctx, invocation) } } return &protocol.RPCResult{Err: errors.New(fmt.Sprintf("no provider available in %v", invokers))} }Copy the code
  • Invocation invocation Invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation invocation Invocation IVk. Invoke(CTX, Invocation) for IVK. IsAvailable() is true

summary

NewAvailableClusterInvoker availableCluster Join method of implementation, The Invoke method availableClusterInvoker invokes invokers via invoker.directory.List(Invocation) and then invocation invokers. Invocation IVk. Invoke(CTX, Invocation) for IVK. IsAvailable() is true

doc

  • available_cluster