sequence

This paper mainly studies the registryAwareCluster of Dubo-Go

registryAwareCluster

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

type registryAwareCluster struct{}

func init() {
	extension.SetCluster("registryAware", NewRegistryAwareCluster)
}

// NewRegistryAwareCluster ...
func NewRegistryAwareCluster() cluster.Cluster {
	return &registryAwareCluster{}
}

func (cluster *registryAwareCluster) Join(directory cluster.Directory) protocol.Invoker {
	return newRegistryAwareClusterInvoker(directory)
}
Copy the code
  • RegistryAwareCluster Join method to execute newRegistryAwareClusterInvoker (directory)

newRegistryAwareClusterInvoker

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

type registryAwareClusterInvoker struct {
	baseClusterInvoker
}

func newRegistryAwareClusterInvoker(directory cluster.Directory) protocol.Invoker {
	return &registryAwareClusterInvoker{
		baseClusterInvoker: newBaseClusterInvoker(directory),
	}
}
Copy the code
  • Create registryAwareClusterInvoker newRegistryAwareClusterInvoker method

Invoke

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

func (invoker *registryAwareClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
	invokers := invoker.directory.List(invocation)
	//First, pick the invoker (XXXClusterInvoker) that comes from the local registry, distinguish by a 'default' key.
	for _, invoker := range invokers {
		if invoker.IsAvailable() && invoker.GetUrl().GetParam(constant.REGISTRY_DEFAULT_KEY, "false") == "true" {
			return invoker.Invoke(ctx, invocation)
		}
	}

	//If none of the invokers has a local signal, pick the first one available.
	for _, invoker := range invokers {
		if invoker.IsAvailable() {
			return invoker.Invoke(ctx, invocation)
		}
	}
	return nil
}
Copy the code
  • The Invoke method gets invokers from invoker.directory.List(Invocation) and then iterates over the Invokers to determine if there is an invoker from the Local Registry. Invocation invoker.Invoke(CTX, Invocation) if yes; Otherwise, retrace invokers and find the first available invocation invoker.Invoke(CTX, Invocation)

summary

RegistryAwareCluster Join method to execute newRegistryAwareClusterInvoker (directory); RegistryAwareClusterInvoker Invoke method, first through the invoker. Directory. The List (invocation) get invokers, Invocation invoker.Invoke(CTX, Invocation); Invocation invoker from The Local Registry is invoked; invocation invoker from the Local Registry is invoked. Invocation find the first available invocation invoker.Invoke(CTX, Invocation)

doc

  • registry_aware_cluster