dubbo.apache.org/dubbo-go/v3@v3.1.1/registry/registry.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package registry
    19  
    20  import (
    21  	"dubbo.apache.org/dubbo-go/v3/common"
    22  )
    23  
    24  // Registry is the interface that wraps Register、UnRegister、Subscribe and UnSubscribe method.
    25  type Registry interface {
    26  	common.Node
    27  
    28  	// Register is used for service provider calling, register services
    29  	// to registry. And it is also used for service consumer calling, register
    30  	// services cared about, for dubbo's admin monitoring.
    31  	Register(url *common.URL) error
    32  
    33  	// UnRegister is required to support the contract:
    34  	// 1. If it is the persistent stored data of dynamic=false, the
    35  	//    registration data can not be found, then the IllegalStateException
    36  	//    is thrown, otherwise it is ignored.
    37  	// 2. Unregister according to the full url match.
    38  	// url Registration information, is not allowed to be empty, e.g:
    39  	// dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylin
    40  	UnRegister(url *common.URL) error
    41  
    42  	// Subscribe is required to support the contract:
    43  	// When creating new registry extension, pls select one of the
    44  	// following modes.
    45  	// Will remove in dubbogo version v1.1.0
    46  	// mode1: return Listener with Next function which can return
    47  	//        subscribe service event from registry
    48  	// Deprecated!
    49  	// subscribe(event.URL) (Listener, error)
    50  	// Will replace mode1 in dubbogo version v1.1.0
    51  	// mode2: callback mode, subscribe with notify(notify listener).
    52  	Subscribe(*common.URL, NotifyListener) error
    53  
    54  	// UnSubscribe is required to support the contract:
    55  	// 1. If don't subscribe, ignore it directly.
    56  	// 2. Unsubscribe by full URL match.
    57  	// url Subscription condition, not allowed to be empty, e.g.
    58  	// consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylin
    59  	// listener A listener of the change event, not allowed to be empty
    60  	UnSubscribe(*common.URL, NotifyListener) error
    61  
    62  	// LoadSubscribeInstances Because the subscription is asynchronous,
    63  	// it may cause the consumer to fail to obtain the provider.
    64  	// so sync load the instance of the preparing to subscribe service before
    65  	// formally subscribing.
    66  	LoadSubscribeInstances(*common.URL, NotifyListener) error
    67  }
    68  
    69  // nolint
    70  type NotifyListener interface {
    71  	// Notify supports notifications on the service interface and the dimension of the data type. When a list of
    72  	// events are passed in, it's considered as a complete list, on the other side, if one single event is
    73  	// passed in, then it's a incremental event. Pls. note when a list (instead of single event) comes,
    74  	// the impl of NotifyListener may abandon the accumulated result from previous notifications.
    75  	Notify(*ServiceEvent)
    76  	// NotifyAll the events are complete Service Event List.
    77  	// The argument of events []*ServiceEvent is equal to urls []*URL, The Action of serviceEvent should be EventTypeUpdate.
    78  	// If your registry center can only get all urls but can't get individual event, you should use this one.
    79  	// After notify the address, the callback func will be invoked.
    80  	NotifyAll([]*ServiceEvent, func())
    81  }
    82  
    83  // Listener Deprecated!
    84  type Listener interface {
    85  	// Next returns next service event once received
    86  	Next() (*ServiceEvent, error)
    87  	// Close closes this listener
    88  	Close()
    89  }