In this chapter, we will implement a simple small requirement and implement a distributed ID generation service through which distributed IDs can be obtained (Assuming a distributed ID, we will not discuss the ID generation scheme and algorithm, here we directly use uuid instead, just to demonstrate the creation of custom services)
First use dubbogo-cli to create IDC service
We edit proto to define our interface
generate code
Let’s tune the service Directory: pkg/service/service.go The modified code is as follows
At the same time, we adjust the provider part in conf/dubbogo.yaml,
We need to pull up a dependent registry, nacos, if you have a ready-made one, this step can be ignored, we use docker to quickly start a nacos,
Finally, we start the server.
Open the nacos console, you can see that the service has been registered
First, we can share the API of our server to the client and generate related codes (here we can share proto according to actual project needs, each consumer generates code by itself, or introduce it to dependent services after unified generation of sdk) The client directory is as follows:
The api directory is the same as the server’s api directory The client.go code is as follows
dubbogo.yml is as follows
Run the client to get the id, as follows:
It can be found that we use nacos for the registration center. Of course, we can also use other registration centers. For more usage methods, you can refer to Registry