Microservice Application Edition
Demonstrates a web application calling an rpc service.
1. Download and Run
Download the sample dawdler-tutorial.zip.
After extracting it, go into the micro-service directory.
Configure dawdler-config.yml under resources in user-service and user-web-api (the sample uses a local consul).
The consul registry configuration must be set in consul.
The data source configuration must be set in consul.
Run the main methods of UserServiceApplication and UserWebApplication.
//server side
@DawdlerBootApplication(serviceName = "user-service")
public class UserServiceApplication {
public static void main(String[] args) throws Exception {
DawdlerServerApplication.run(UserServiceApplication.class, args);
}
}
//client side
@DawdlerBootApplication
public class UserWebApplication {
public static void main(String[] args) throws Throwable {
DawdlerWebApplication.run(UserWebApplication.class, args);
}
}
1.1 Configuration Files
For the consul registry configuration, create the node /consul in consul
with the following content:
host: localhost
port: 8500
For the data source configuration (both services use the same database to keep the demo simple; read-write splitting is supported. For read-write splitting, transactions, sharding, etc., refer to dawdler-db-core), create the nodes /user_readDataSource and /user_writeDataSource in consul. with the following content:
type: com.zaxxer.hikari.HikariDataSource
jdbcUrl: jdbc:mysql://127.0.0.1:3306/user-demo?characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: root
connectionTimeout: 3000
maximumPoolSize: 20
minimumIdle: 2
1.2 Running as a Jar
Run
mvn clean package
to get user-service-0.0.1-jdk25-SNAPSHOT-all.jar and user-web-api-0.0.1-jdk25-SNAPSHOT-all.jar
Then run
java -jar user-service-0.0.1-jdk25-SNAPSHOT-all.jar
java -jar user-web-api-0.0.1-jdk25-SNAPSHOT-all.jar
1.3 Verification
Visit http://localhost:8085/user/info?id=1.