SOFARPC
Service publishing
The process of service publishing involves three classes RegistryConfig, ServerConfig, ProviderConfig.
RegistryConfig
RegistryConfig registryConfig = new RegistryConfig() .setProtocol("zookeeper") .setAddress("127.0.0.1:2181")RegistryConfigrepresents the registry center. As above, the address and port of the service registry center is 127.0.0.1:2181, and the protocol is Zookeeper.- ServerConfig
java ServerConfig serverConfig = new ServerConfig() .setPort(8803) .setProtocol("bolt");
- ServerConfig
ServerConfig represents the container where service runs. The above declares a server using the 8803 port and the bolt protocol.
ProviderConfig
ProviderConfig<HelloWorldService> providerConfig = new ProviderConfig<HelloWorldService>() .setInterfaceId(HelloWorldService.class.getName()) .setRef(new HelloWorldServiceImpl()) .setServer(serverConfig) .setRegistry(registryConfig); providerConfig.export();ProviderConfigrepresents service publishing. The above declares the interface of the service, implements the server running the service, and eventually publishes the service by theexportmethod.Service reference
Service reference involves two classes, namely
RegistryConfigandConsumerConfig.ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setRegistry(registryConfig); 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.