Use API in non-Spring environment

Update time: 2019-06-21


Service publishing

The process of service publishing involves three classes RegistryConfig, ServerConfig, ProviderConfig.

  1. RegistryConfig

    RegistryConfig registryConfig = new RegistryConfig()

    RegistryConfig represents the registry center. As above, the address and port of the service registry center is, and the protocol is Zookeeper.

    1. ServerConfig java ServerConfig serverConfig = new ServerConfig() .setPort(8803) .setProtocol("bolt");

ServerConfig represents the container where service runs. The above declares a server using the 8803 port and the bolt protocol.

  1. ProviderConfig

    ProviderConfig<HelloWorldService> providerConfig = new ProviderConfig<HelloWorldService>()
            .setRef(new HelloWorldServiceImpl())    

    ProviderConfig represents service publishing. The above declares the interface of the service, implements the server running the service, and eventually publishes the service by the export method.

    Service reference

    Service reference involves two classes, namely RegistryConfig and ConsumerConfig.

    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>()
    HelloService helloService = consumerConfig.refer();

ConsumerConfig represents service reference. The above declares the interface and service registry center of the referenced service interface, and finally references the service by the refer method to get the proxy for the remote call of the service.