Running on your local machine
Prerequisite:
- JDK 1.8.0+
- Maven 3.5.x
- Node 10+
For a quick start, check out the source code from git, then run:
mvn -DskipTests clean package
Go to alibaba-broker-server > target folder.
3
Execute the jar file to get Alibaba RSocket Broker running.
java -jar target/alibaba-rsocket-broker.jar
And you will see this in the console.
Browse to http://localhost:9998 and you will see the web console.
Register a Service
Next, we are going to register a service to the broker. To do this we look at the example projects included in the source code.
When I first look at the rsocket-responder project, you will see that it is complaining about the com.alibaba.user.Account class not found.
The required class is located in user-service-api project and it is a ProtoBuf file. It needs to be manually generated.
For the purpose of the experiment, we just run 'mvn -DskipTest package' on the example folder. This will solve the dependency problem and generates the jar file that can be used.
Then we go to rsocket-responder folder and run:
java -jar target/rsocket-responder-1.0.0-SNAPSHOT.jar
We can see a Spring Boot application started and all services published to the Broker.
Now let's go back to the Broker web console.
We can see our app is listed here now.
We can also see it in App Instances List. Click on the app will show us more detail.
The Service Testing is also very cool. I can use it to test the methods in the service.
This is the method implementation.And the response return from the service.
Integrate 2 Services
Go to example/rsocket-requester. Run the jar file to start the service.
java -jar target/rsocket-requester-1.0.0-SNAPSHOT.jar
This will starts a Spring Boot application with a few endpoints available. For a quick test run:
curl http://localhost:8181/user/2
And here is the formatted response:
Here is what happened.
In rsocket-requester > UserController there is a GET endpoint that will call userService.findById(id).
The UserService is autowired.
In the Bean configuration, we can see that the UserService instance is constructed using RSocketRemoteServiceBuilder.
This setting tells the rsocket-requester to call the remote service from the broker.
At the rsocket-responder, there is an implementation class of the UserService interface. The class needs to be annotated with @RScoketService. This will register the service to the broker when the application is deployed and running.
-------------------------------------------------------------------------------------------------------------------------
Alibaba RSocket Broker seems to be well designed and it makes it easy for a developer to use. Compared to using the auto-generated stubs from gRPC, I think it is more cleaner and less cognitive burden. (yes, I don't like those stubs. :p)
Hope to see better documentation in the future, (I might try to write some). That will make more people adopting the system.