├── docs
├── Ref.md
├── aio.md
├── bio.md
├── ipc.md
├── jmx.md
├── nio.md
├── jax-ws.md
├── mq-other.md
├── overview.md
├── mas-overview.md
├── monitor-overview.md
├── rest.md
├── web-overview.md
├── zookeeper.md
├── actiovemq.md
├── spring-boot.md
├── 一个“超市”发展的例子.md
├── jersey.md
├── appendix.md
├── rmi-example.md
├── 分层.md
├── 草稿.md
├── architecture.md
├── api.md
├── mq-overview.md
├── basic.md
├── jms.md
├── rmi-overview.md
├── net-overview.md
└── socket.md
├── samples
├── cxf-rest
│ ├── .gitignore
│ ├── .settings
│ │ ├── org.eclipse.wst.jsdt.ui.superType.name
│ │ ├── org.eclipse.wst.validation.prefs
│ │ ├── org.eclipse.wst.jsdt.ui.superType.container
│ │ ├── org.eclipse.m2e.core.prefs
│ │ ├── org.eclipse.wst.common.project.facet.core.prefs.xml
│ │ ├── org.eclipse.wst.common.project.facet.core.xml
│ │ ├── org.eclipse.wst.common.component
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── .jsdtscope
│ ├── src
│ │ ├── main
│ │ │ ├── webapp
│ │ │ │ ├── META-INF
│ │ │ │ │ └── context.xml
│ │ │ │ └── WEB-INF
│ │ │ │ │ ├── web.xml
│ │ │ │ │ └── beans.xml
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── cxf
│ │ │ │ ├── JsonBean.java
│ │ │ │ └── HelloWorld.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── cxf
│ │ │ └── HelloWorldIT.java
│ └── .classpath
├── jersey-rest
│ ├── .gitignore
│ ├── .settings
│ │ ├── org.eclipse.m2e.core.prefs
│ │ ├── org.eclipse.core.resources.prefs
│ │ └── org.eclipse.jdt.core.prefs
│ ├── src
│ │ ├── main
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── jersey
│ │ │ │ ├── MyResource.java
│ │ │ │ └── Main.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── jersey
│ │ │ └── MyResourceTest.java
│ ├── .classpath
│ └── pom.xml
├── hello-world-docker
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ └── application.properties
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── spring
│ │ │ │ └── cloud
│ │ │ │ └── weather
│ │ │ │ ├── Application.java
│ │ │ │ └── controller
│ │ │ │ └── HelloController.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── cloud
│ │ │ └── weather
│ │ │ ├── ApplicationTests.java
│ │ │ └── controller
│ │ │ └── HelloControllerTest.java
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── Dockerfile
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradlew.bat
│ └── gradlew
├── spring-boot-rest
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ └── application.properties
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── spring
│ │ │ │ └── cloud
│ │ │ │ └── weather
│ │ │ │ ├── Application.java
│ │ │ │ ├── controller
│ │ │ │ ├── HelloController.java
│ │ │ │ └── UserController.java
│ │ │ │ ├── repository
│ │ │ │ ├── UserRepository.java
│ │ │ │ └── UserRepositoryImpl.java
│ │ │ │ └── domain
│ │ │ │ └── User.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── cloud
│ │ │ └── weather
│ │ │ ├── ApplicationTests.java
│ │ │ └── controller
│ │ │ └── HelloControllerTest.java
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── .gitignore
│ └── gradlew.bat
├── java-rmi
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── java
│ │ │ └── demo
│ │ │ └── rmi
│ │ │ ├── ServerConstant.java
│ │ │ ├── Message.java
│ │ │ ├── RmiEchoClient.java
│ │ │ └── RmiEchoServer.java
│ └── pom.xml
├── java-ws
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── java
│ │ │ └── ws
│ │ │ ├── HelloService.java
│ │ │ ├── HelloPublisher.java
│ │ │ ├── HelloServiceImpl.java
│ │ │ └── HelloClient.java
│ └── pom.xml
├── java-io-mode
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── waylau
│ │ └── java
│ │ └── demo
│ │ ├── net
│ │ ├── BlockingEchoServer.java
│ │ └── BlockingEchoClient.java
│ │ ├── nio
│ │ ├── NonBlockingEchoClient.java
│ │ └── NonBlokingEchoServer.java
│ │ └── aio
│ │ ├── AsyncEchoClient.java
│ │ └── AsyncEchoServer.java
├── javase-rest
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── rest
│ │ │ ├── bean
│ │ │ └── MyBean.java
│ │ │ ├── RestApplication.java
│ │ │ ├── App.java
│ │ │ └── resource
│ │ │ └── MyResource.java
│ └── pom.xml
├── java-concurrency
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── waylau
│ │ └── java
│ │ └── demo
│ │ └── concurrency
│ │ └── Deadlock.java
├── eureka-client
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ ├── application.properties
│ │ │ │ └── static
│ │ │ │ │ └── favicon.ico
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── spring
│ │ │ │ └── cloud
│ │ │ │ ├── controller
│ │ │ │ └── HelloController.java
│ │ │ │ └── Application.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── cloud
│ │ │ ├── ApplicationTests.java
│ │ │ └── controller
│ │ │ └── HelloControllerTest.java
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradlew.bat
│ └── gradlew
├── eureka-server
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ ├── static
│ │ │ │ │ └── favicon.ico
│ │ │ │ └── application.properties
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── spring
│ │ │ │ └── cloud
│ │ │ │ ├── controller
│ │ │ │ └── HelloController.java
│ │ │ │ └── Application.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── cloud
│ │ │ ├── ApplicationTests.java
│ │ │ └── controller
│ │ │ └── HelloControllerTest.java
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradlew.bat
│ └── gradlew
├── jms-msg
│ ├── src
│ │ ├── main
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── spring
│ │ │ │ └── jms
│ │ │ │ ├── queue
│ │ │ │ ├── ConsumerService.java
│ │ │ │ ├── ConsumerListener.java
│ │ │ │ ├── QueueMessageListener.java
│ │ │ │ ├── ConsumerServiceImpl.java
│ │ │ │ ├── ProducerService.java
│ │ │ │ ├── ConsumerSessionAwareMessageListener.java
│ │ │ │ └── ProducerServiceImpl.java
│ │ │ │ └── topic
│ │ │ │ ├── TopicMessageListener.java
│ │ │ │ ├── TopicMessageListener2.java
│ │ │ │ └── TopicProvider.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── jms
│ │ │ └── SpringJmsTest.java
│ ├── .gitignore
│ └── pom.xml
├── axon-cqrs
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ └── log4j2.xml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── axon
│ │ │ └── cqrs
│ │ │ ├── common
│ │ │ ├── events
│ │ │ │ ├── WithdrawMoneyEvent.java
│ │ │ │ └── CreateAccountEvent.java
│ │ │ └── domain
│ │ │ │ └── AccountId.java
│ │ │ ├── command
│ │ │ ├── commands
│ │ │ │ ├── WithdrawMoneyCommand.java
│ │ │ │ └── CreateAccountCommand.java
│ │ │ └── aggregates
│ │ │ │ └── BankAccount.java
│ │ │ └── Application.java
│ └── pom.xml
├── spring-rest
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── mvc
│ │ │ ├── Application.java
│ │ │ ├── configuration
│ │ │ ├── AppConfiguration.java
│ │ │ └── MvcConfiguration.java
│ │ │ ├── controller
│ │ │ └── HelloController.java
│ │ │ ├── vo
│ │ │ └── User.java
│ │ │ └── JettyServer.java
│ └── pom.xml
├── security-basic
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── spring
│ │ │ └── mvc
│ │ │ ├── Application.java
│ │ │ ├── configuration
│ │ │ ├── AppConfiguration.java
│ │ │ ├── MvcConfiguration.java
│ │ │ └── WebSecurityConfig.java
│ │ │ ├── controller
│ │ │ └── HelloController.java
│ │ │ ├── vo
│ │ │ └── User.java
│ │ │ └── JettyServer.java
│ ├── dependency-reduced-pom.xml
│ └── pom.xml
├── spark-word-count
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── waylau
│ │ └── spark
│ │ └── JavaWordCount.java
├── zk-registry-discovery
│ ├── .gitignore
│ ├── src
│ │ ├── main
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── waylau
│ │ │ │ └── zk
│ │ │ │ ├── discovery
│ │ │ │ ├── ServiceDiscovery.java
│ │ │ │ └── ZkServiceDiscovery.java
│ │ │ │ ├── Constant.java
│ │ │ │ └── registry
│ │ │ │ ├── ServiceRegistry.java
│ │ │ │ └── ZkServiceRegistry.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── waylau
│ │ │ └── zk
│ │ │ └── ApplicationTests.java
│ └── pom.xml
└── game-server
│ └── aws_game_server.js
├── images
├── net-2tcp.gif
├── net-1netw.gif
├── net-3tcpudp.gif
├── rpc-rmi_flow.png
├── rpc-rmi_logical.png
├── socket-5connect.gif
├── socket-6connect.gif
└── distributed-object.jpg
├── .gitignore
├── LICENSE
├── SUMMARY.md
└── README.md
/docs/Ref.md:
--------------------------------------------------------------------------------
1 | # 参考文献
2 |
3 |
--------------------------------------------------------------------------------
/docs/aio.md:
--------------------------------------------------------------------------------
1 | # AIO
2 |
3 |
--------------------------------------------------------------------------------
/docs/bio.md:
--------------------------------------------------------------------------------
1 | # BIO
2 |
3 |
--------------------------------------------------------------------------------
/docs/ipc.md:
--------------------------------------------------------------------------------
1 | # IPC
2 |
3 |
--------------------------------------------------------------------------------
/docs/jmx.md:
--------------------------------------------------------------------------------
1 | # JMX
2 |
3 |
--------------------------------------------------------------------------------
/docs/nio.md:
--------------------------------------------------------------------------------
1 | # NIO
2 |
3 |
--------------------------------------------------------------------------------
/docs/jax-ws.md:
--------------------------------------------------------------------------------
1 | # JAX-WS
2 |
3 |
--------------------------------------------------------------------------------
/docs/mq-other.md:
--------------------------------------------------------------------------------
1 | # 其他
2 |
3 |
--------------------------------------------------------------------------------
/docs/overview.md:
--------------------------------------------------------------------------------
1 | # 概述
2 |
3 |
--------------------------------------------------------------------------------
/docs/mas-overview.md:
--------------------------------------------------------------------------------
1 | # 概述
2 |
3 |
--------------------------------------------------------------------------------
/docs/monitor-overview.md:
--------------------------------------------------------------------------------
1 | # 概述
2 |
3 |
--------------------------------------------------------------------------------
/docs/rest.md:
--------------------------------------------------------------------------------
1 | # RESTful 概述
2 |
3 |
--------------------------------------------------------------------------------
/docs/web-overview.md:
--------------------------------------------------------------------------------
1 | # 概述
2 |
3 |
--------------------------------------------------------------------------------
/docs/zookeeper.md:
--------------------------------------------------------------------------------
1 | # ZooKeeper
2 |
3 |
--------------------------------------------------------------------------------
/docs/actiovemq.md:
--------------------------------------------------------------------------------
1 | # ActiveMQ 示例
2 |
3 |
--------------------------------------------------------------------------------
/docs/spring-boot.md:
--------------------------------------------------------------------------------
1 | # Spring Boot
2 |
3 |
--------------------------------------------------------------------------------
/docs/一个“超市”发展的例子.md:
--------------------------------------------------------------------------------
1 | # 一个“超市”发展的例子
2 |
3 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/samples/jersey-rest/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/docs/jersey.md:
--------------------------------------------------------------------------------
1 | # 基于 Jersey 的 JAX-RS 示例
2 |
3 |
--------------------------------------------------------------------------------
/docs/appendix.md:
--------------------------------------------------------------------------------
1 | # 附录
2 |
3 | * 《分布式系统原理与范型(第二版)》
--------------------------------------------------------------------------------
/docs/rmi-example.md:
--------------------------------------------------------------------------------
1 | # 示例
2 |
3 |
4 |
5 | 本节示例,可以在`java-rmi`项目下找到。
--------------------------------------------------------------------------------
/samples/hello-world-docker/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/samples/java-rmi/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.idea/
3 | /.settings/
4 | .classpath
5 | .project
--------------------------------------------------------------------------------
/samples/java-ws/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.idea/
3 | /.settings/
4 | .classpath
5 | .project
--------------------------------------------------------------------------------
/images/net-2tcp.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/net-2tcp.gif
--------------------------------------------------------------------------------
/samples/java-io-mode/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.idea/
3 | /.settings/
4 | .classpath
5 | .project
--------------------------------------------------------------------------------
/samples/javase-rest/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.idea/
3 | /.settings/
4 | .classpath
5 | .project
--------------------------------------------------------------------------------
/images/net-1netw.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/net-1netw.gif
--------------------------------------------------------------------------------
/images/net-3tcpudp.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/net-3tcpudp.gif
--------------------------------------------------------------------------------
/samples/java-concurrency/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.idea/
3 | /.settings/
4 | .classpath
5 | .project
--------------------------------------------------------------------------------
/docs/分层.md:
--------------------------------------------------------------------------------
1 | # 分层
2 |
3 | * 试图层
4 | * 业务逻辑层
5 | * 数据层
6 |
7 | SQL 与领域模型分离
8 |
9 | 数据映射器
10 | JDO
--------------------------------------------------------------------------------
/images/rpc-rmi_flow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/rpc-rmi_flow.png
--------------------------------------------------------------------------------
/images/rpc-rmi_logical.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/rpc-rmi_logical.png
--------------------------------------------------------------------------------
/images/socket-5connect.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/socket-5connect.gif
--------------------------------------------------------------------------------
/images/socket-6connect.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/socket-6connect.gif
--------------------------------------------------------------------------------
/samples/cxf-rest/src/main/webapp/META-INF/context.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/images/distributed-object.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/images/distributed-object.jpg
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.wst.validation.prefs:
--------------------------------------------------------------------------------
1 | disabled=06target
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/samples/spring-boot-rest/build.gradle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/spring-boot-rest/build.gradle
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/samples/jersey-rest/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/samples/eureka-client/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/eureka-client/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/samples/eureka-server/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/eureka-server/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/samples/eureka-client/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name: eureka-client
2 |
3 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/
--------------------------------------------------------------------------------
/samples/eureka-client/src/main/resources/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/eureka-client/src/main/resources/static/favicon.ico
--------------------------------------------------------------------------------
/samples/eureka-server/src/main/resources/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/eureka-server/src/main/resources/static/favicon.ico
--------------------------------------------------------------------------------
/samples/spring-boot-rest/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/spring-boot-rest/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/samples/hello-world-docker/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waylau/distributed-java/HEAD/samples/hello-world-docker/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/samples/jersey-rest/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/test/java=UTF-8
4 | encoding/=UTF-8
5 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jdk-alpine
2 | VOLUME /tmp
3 | ARG JAR_FILE
4 | ADD ${JAR_FILE} app.jar
5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/samples/eureka-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port: 8761
2 |
3 | eureka.instance.hostname: localhost
4 | eureka.client.registerWithEureka: false
5 | eureka.client.fetchRegistry: false
6 | eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
--------------------------------------------------------------------------------
/samples/eureka-client/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 06 12:27:20 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
7 |
--------------------------------------------------------------------------------
/samples/eureka-server/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 06 12:27:20 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
7 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jul 28 13:37:07 BST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | #distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-bin.zip
7 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip
--------------------------------------------------------------------------------
/samples/hello-world-docker/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jul 28 13:37:07 BST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | #distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-bin.zip
7 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/queue/ConsumerService.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.queue;
2 |
3 | import javax.jms.Destination;
4 |
5 | /**
6 | * Consumer Service.
7 | *
8 | * @since 1.0.0 2018年4月15日
9 | * @author Way Lau
10 | */
11 | public interface ConsumerService {
12 | public void receive(Destination queueDestination);
13 | }
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/eureka-client/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 |
--------------------------------------------------------------------------------
/samples/eureka-server/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 |
--------------------------------------------------------------------------------
/samples/java-ws/src/main/java/com/waylau/java/ws/HelloService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.ws;
5 |
6 | import javax.jws.WebService;
7 |
8 | /**
9 | * Hello Service.
10 | *
11 | * @since 1.0.0 2020年1月25日
12 | * @author Way Lau
13 | */
14 | @WebService
15 | public interface HelloService {
16 | String getHelloworld();
17 | }
18 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 |
--------------------------------------------------------------------------------
/samples/jms-msg/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/spring-rest/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/security-basic/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/spark-word-count/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 | /bin/
27 | /target/
28 |
--------------------------------------------------------------------------------
/samples/security-basic/src/main/java/com/waylau/spring/mvc/Application.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.spring.mvc;
5 |
6 | /**
7 | * Application Main.
8 | *
9 | * @since 1.0.0 2018年3月21日
10 | * @author Way Lau
11 | */
12 | public class Application {
13 |
14 | public static void main(String[] args) throws Exception {
15 | new JettyServer().run();
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/samples/spring-rest/src/main/java/com/waylau/spring/mvc/Application.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.spring.mvc;
5 |
6 | /**
7 | * Application Main.
8 | *
9 | * @since 1.0.0 2018年3月21日
10 | * @author Way Lau
11 | */
12 | public class Application {
13 |
14 | public static void main(String[] args) throws Exception {
15 | new JettyServer().run();;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/src/main/java/com/waylau/zk/discovery/ServiceDiscovery.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.zk.discovery;
5 |
6 | /**
7 | * Service Discovery.
8 | *
9 | * @since 1.0.0 2018年5月16日
10 | * @author Way Lau
11 | */
12 | public interface ServiceDiscovery {
13 |
14 | /**
15 | * 服务发现.
16 | *
17 | * @param name
18 | * @return
19 | */
20 | String discover(String name);
21 | }
22 |
--------------------------------------------------------------------------------
/samples/jersey-rest/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
3 | org.eclipse.jdt.core.compiler.compliance=1.7
4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7 | org.eclipse.jdt.core.compiler.release=disabled
8 | org.eclipse.jdt.core.compiler.source=1.7
9 |
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/src/main/java/com/waylau/zk/Constant.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.zk;
5 |
6 | /**
7 | * Constant.
8 | *
9 | * @since 1.0.0 2018年5月16日
10 | * @author Way Lau
11 | */
12 | public interface Constant {
13 |
14 | /**会话超时时间*/
15 | int ZK_SESSION_TIMEOUT = 5000;
16 |
17 | /**连接超时时间*/
18 | int ZK_CONNECTION_TIMEOUT = 1000;
19 |
20 | String ZK_REGISTRY = "/registry";
21 | }
22 |
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/src/main/java/com/waylau/zk/registry/ServiceRegistry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.zk.registry;
5 |
6 | /**
7 | *
8 | * @since 1.0.0 2018年5月16日
9 | * @author Way Lau
10 | */
11 | public interface ServiceRegistry {
12 |
13 | /**
14 | * 注册服务.
15 | *
16 | * @param serviceName
17 | * @param serviceAddress
18 | */
19 | void registry(String serviceName, String serviceAddress);
20 | }
21 |
--------------------------------------------------------------------------------
/samples/cxf-rest/src/main/java/com/waylau/cxf/JsonBean.java:
--------------------------------------------------------------------------------
1 | package com.waylau.cxf;
2 |
3 |
4 | public class JsonBean {
5 | private String val1;
6 | private String val2;
7 |
8 | public String getVal1() {
9 | return val1;
10 | }
11 |
12 | public void setVal1(String val1) {
13 | this.val1 = val1;
14 | }
15 |
16 | public String getVal2() {
17 | return val2;
18 | }
19 |
20 | public void setVal2(String val2) {
21 | this.val2 = val2;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/samples/javase-rest/src/main/java/com/waylau/rest/bean/MyBean.java:
--------------------------------------------------------------------------------
1 | package com.waylau.rest.bean;
2 |
3 | import javax.xml.bind.annotation.XmlRootElement;
4 |
5 | @XmlRootElement
6 | public class MyBean {
7 |
8 | private String name;
9 | private int age;
10 |
11 | public String getName() {
12 | return name;
13 | }
14 | public void setName(String name) {
15 | this.name = name;
16 | }
17 | public int getAge() {
18 | return age;
19 | }
20 | public void setAge(int age) {
21 | this.age = age;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/samples/java-ws/src/main/java/com/waylau/java/ws/HelloPublisher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.ws;
5 |
6 | import javax.xml.ws.Endpoint;
7 |
8 | /**
9 | * Hello Publisher.
10 | *
11 | * @since 1.0.0 2020年1月25日
12 | * @author Way Lau
13 | */
14 | public class HelloPublisher {
15 | public static void main(String[] args) {
16 |
17 | Endpoint.publish("http://localhost:9999/ws/hello",
18 | new HelloServiceImpl());
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/samples/java-rmi/src/main/java/com/waylau/java/demo/rmi/ServerConstant.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.rmi;
5 |
6 | /**
7 | * Server Constant.
8 | *
9 | * @since 1.0.0 2020年1月18日
10 | * @author Way Lau
11 | */
12 | public interface ServerConstant {
13 |
14 | String HOST =
15 | "localhost";
16 |
17 | int PORT = 1099;
18 |
19 | String REGIRTRY_NAME = "Echo Server Message";
20 |
21 | String HELLO_WORLD =
22 | "Hello World! Welcome to waylau.com!";
23 | }
24 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/src/main/java/com/waylau/spring/cloud/weather/Application.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 主应用程序.
8 | *
9 | * @since 1.0.0 2017年9月27日
10 | * @author Way Lau
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(Application.class, args);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/main/java/com/waylau/spring/cloud/weather/Application.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 主应用程序.
8 | *
9 | * @since 1.0.0 2017年9月27日
10 | * @author Way Lau
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(Application.class, args);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/samples/javase-rest/src/main/java/com/waylau/rest/RestApplication.java:
--------------------------------------------------------------------------------
1 | package com.waylau.rest;
2 |
3 |
4 | import org.glassfish.jersey.media.multipart.MultiPartFeature;
5 | import org.glassfish.jersey.server.ResourceConfig;
6 |
7 | /**
8 | * REST 主应用
9 | *
10 | * @author waylau.com
11 | * 2015年3月3日
12 | */
13 | public class RestApplication extends ResourceConfig {
14 |
15 | public RestApplication() {
16 | // 资源类所在的包路径
17 | packages("com.waylau.rest.resource");
18 |
19 | // 注册 MultiPart
20 | register(MultiPartFeature.class);
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/samples/java-ws/src/main/java/com/waylau/java/ws/HelloServiceImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.ws;
5 |
6 | import javax.jws.WebMethod;
7 | import javax.jws.WebService;
8 | /**
9 | *
10 | * @since 1.0.0 2020年1月25日
11 | * @author Way Lau
12 | */
13 | @WebService(endpointInterface = "com.waylau.java.ws.HelloService")
14 | public class HelloServiceImpl implements HelloService {
15 |
16 | @WebMethod
17 | public String getHelloworld() {
18 | return "Hello world!";
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/samples/java-rmi/src/main/java/com/waylau/java/demo/rmi/Message.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.rmi;
5 |
6 | import java.rmi.Remote;
7 | import java.rmi.RemoteException;
8 |
9 | /**
10 | * Message.
11 | *
12 | * @since 1.0.0 2020年1月18日
13 | * @author Way Lau
14 | */
15 | public interface Message extends Remote {
16 |
17 | /**
18 | * 发送消息.
19 | *
20 | * @param msg 消息
21 | * @return 响应内容
22 | * @throws RemoteException
23 | */
24 | String echoMessage(String msg) throws RemoteException;
25 | }
26 |
--------------------------------------------------------------------------------
/samples/eureka-client/src/test/java/com/waylau/spring/cloud/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | /**
9 | * 主应用测试用例.
10 | *
11 | * @since 1.0.0 2017年9月27日
12 | * @author Way Lau
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class ApplicationTests {
17 |
18 | @Test
19 | public void contextLoads() {
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/samples/eureka-server/src/test/java/com/waylau/spring/cloud/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | /**
9 | * 主应用测试用例.
10 | *
11 | * @since 1.0.0 2017年9月27日
12 | * @author Way Lau
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class ApplicationTests {
17 |
18 | @Test
19 | public void contextLoads() {
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/samples/eureka-client/src/main/java/com/waylau/spring/cloud/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Hello Controller.
8 | *
9 | * @since 1.0.0 2017年9月27日
10 | * @author Way Lau
11 | */
12 | @RestController
13 | public class HelloController {
14 |
15 | @RequestMapping("/hello")
16 | public String hello() {
17 | return "Hello World! Welcome to visit waylau.com!";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/samples/eureka-server/src/main/java/com/waylau/spring/cloud/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Hello Controller.
8 | *
9 | * @since 1.0.0 2017年9月27日
10 | * @author Way Lau
11 | */
12 | @RestController
13 | public class HelloController {
14 |
15 | @RequestMapping("/hello")
16 | public String hello() {
17 | return "Hello World! Welcome to visit waylau.com!";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/test/java/com/waylau/spring/cloud/weather/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | /**
9 | * 主应用测试用例.
10 | *
11 | * @since 1.0.0 2017年9月27日
12 | * @author Way Lau
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class ApplicationTests {
17 |
18 | @Test
19 | public void contextLoads() {
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/src/test/java/com/waylau/spring/cloud/weather/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | /**
9 | * 主应用测试用例.
10 | *
11 | * @since 1.0.0 2017年9月27日
12 | * @author Way Lau
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class ApplicationTests {
17 |
18 | @Test
19 | public void contextLoads() {
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/queue/ConsumerListener.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.queue;
2 |
3 | /**
4 | * Consumer Listener.
5 | * 1. MessageListenerAdapter可以把一个普通的java当做MessageListener来处理消息。
6 | * 2. 返回类型不是void的时候,MessageListenerAdapter会自动把返回值封装成Message,并回复。
7 | *
8 | * @since 1.0.0 2018年4月15日
9 | * @author Way Lau
10 | */
11 | public class ConsumerListener {
12 |
13 | public String receiveMessage(String message) {
14 | System.out.println("ConsumerListener接收到一个Text消息:\t" + message);
15 |
16 | return "I am ConsumerListener response";
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/src/main/java/com/waylau/spring/cloud/weather/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Hello Controller.
8 | *
9 | * @since 1.0.0 2017年9月27日
10 | * @author Way Lau
11 | */
12 | @RestController
13 | public class HelloController {
14 |
15 | @RequestMapping("/hello")
16 | public String hello() {
17 | return "Hello World! Welcome to visit waylau.com!";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/main/java/com/waylau/spring/cloud/weather/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Hello Controller.
8 | *
9 | * @since 1.0.0 2017年9月27日
10 | * @author Way Lau
11 | */
12 | @RestController
13 | public class HelloController {
14 |
15 | @RequestMapping("/hello")
16 | public String hello() {
17 | return "Hello World! Welcome to visit waylau.com!";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/samples/spring-rest/src/main/java/com/waylau/spring/mvc/configuration/AppConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.configuration;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.Import;
6 |
7 | /**
8 | * App Configuration.
9 | *
10 | * @since 1.0.0 2018年3月21日
11 | * @author Way Lau
12 | */
13 | @Configuration
14 | @ComponentScan(basePackages = { "com.waylau.spring" })
15 | @Import({ MvcConfiguration.class })
16 | public class AppConfiguration {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/samples/eureka-client/src/main/java/com/waylau/spring/cloud/Application.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | /**
8 | * 主应用程序.
9 | *
10 | * @since 1.0.0 2017年11月01日
11 | * @author Way Lau
12 | */
13 | @SpringBootApplication
14 | @EnableDiscoveryClient
15 | public class Application {
16 |
17 | public static void main(String[] args) {
18 | SpringApplication.run(Application.class, args);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/samples/eureka-server/src/main/java/com/waylau/spring/cloud/Application.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6 |
7 | /**
8 | * 主应用程序.
9 | *
10 | * @since 1.0.0 2017年10月31日
11 | * @author Way Lau
12 | */
13 | @SpringBootApplication
14 | @EnableEurekaServer
15 | public class Application {
16 |
17 | public static void main(String[] args) {
18 | SpringApplication.run(Application.class, args);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/samples/security-basic/src/main/java/com/waylau/spring/mvc/configuration/AppConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.configuration;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.Import;
6 |
7 | /**
8 | * App Configuration.
9 | *
10 | * @since 1.0.0 2018年3月21日
11 | * @author Way Lau
12 | */
13 | @Configuration
14 | @ComponentScan(basePackages = { "com.waylau.spring" })
15 | @Import({ WebSecurityConfig.class, MvcConfiguration.class })
16 | public class AppConfiguration {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4 | org.eclipse.jdt.core.compiler.compliance=1.8
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
7 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
8 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
9 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
10 | org.eclipse.jdt.core.compiler.release=disabled
11 | org.eclipse.jdt.core.compiler.source=1.8
12 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.settings/.jsdtscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/jersey-rest/src/main/java/com/waylau/jersey/MyResource.java:
--------------------------------------------------------------------------------
1 | package com.waylau.jersey;
2 |
3 | import javax.ws.rs.GET;
4 | import javax.ws.rs.Path;
5 | import javax.ws.rs.Produces;
6 | import javax.ws.rs.core.MediaType;
7 |
8 | /**
9 | * Root resource (exposed at "myresource" path)
10 | */
11 | @Path("myresource")
12 | public class MyResource {
13 |
14 | /**
15 | * Method handling HTTP GET requests. The returned object will be sent
16 | * to the client as "text/plain" media type.
17 | *
18 | * @return String that will be returned as a text/plain response.
19 | */
20 | @GET
21 | @Produces(MediaType.TEXT_PLAIN)
22 | public String getIt() {
23 | return "Got it!";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/topic/TopicMessageListener.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.topic;
2 |
3 | import javax.jms.JMSException;
4 | import javax.jms.Message;
5 | import javax.jms.MessageListener;
6 | import javax.jms.TextMessage;
7 |
8 | /**
9 | * Topic Message Listener.
10 | *
11 | * @since 1.0.0 2018年4月15日
12 | * @author Way Lau
13 | */
14 | public class TopicMessageListener implements MessageListener {
15 |
16 | public void onMessage(Message message) {
17 | TextMessage tm = (TextMessage) message;
18 | try {
19 | System.out.println("TopicMessageListener 监听到消息:\t" + tm.getText());
20 | } catch (JMSException e) {
21 | e.printStackTrace();
22 | }
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/queue/QueueMessageListener.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.queue;
2 |
3 | import javax.jms.JMSException;
4 | import javax.jms.Message;
5 | import javax.jms.MessageListener;
6 | import javax.jms.TextMessage;
7 |
8 | /**
9 | * Queue Message Listener.
10 | *
11 | * @since 1.0.0 2018年4月15日
12 | * @author Way Lau
13 | */
14 | public class QueueMessageListener implements MessageListener {
15 |
16 | public void onMessage(Message message) {
17 | TextMessage tm = (TextMessage) message;
18 | try {
19 | System.out.println("ConsumerMessageListener收到了文本消息:\t" + tm.getText());
20 | } catch (JMSException e) {
21 | e.printStackTrace();
22 | }
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/topic/TopicMessageListener2.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.topic;
2 |
3 | import javax.jms.JMSException;
4 |
5 | import javax.jms.Message;
6 | import javax.jms.MessageListener;
7 | import javax.jms.TextMessage;
8 |
9 | /**
10 | * Topic Message Listener 2.
11 | *
12 | * @since 1.0.0 2018年4月15日
13 | * @author Way Lau
14 | */
15 | public class TopicMessageListener2 implements MessageListener {
16 |
17 | public void onMessage(Message message) {
18 | TextMessage tm = (TextMessage) message;
19 | try {
20 | System.out.println("TopicMessageListener2监听到消息 \t" + tm.getText());
21 | } catch (JMSException e) {
22 | e.printStackTrace();
23 | }
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/samples/security-basic/src/main/java/com/waylau/spring/mvc/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | import com.waylau.spring.mvc.vo.User;
7 |
8 |
9 | /**
10 | * Hello 控制器.
11 | *
12 | * @since 1.0.0 2018年3月21日
13 | * @author Way Lau
14 | */
15 | @RestController
16 | public class HelloController {
17 |
18 | @RequestMapping("/hello")
19 | public String hello() {
20 | return "Hello World! Welcome to visit waylau.com!";
21 | }
22 |
23 | @RequestMapping("/hello/way")
24 | public User helloWay() {
25 | return new User("Way Lau", 30);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/samples/spring-rest/src/main/java/com/waylau/spring/mvc/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | import com.waylau.spring.mvc.vo.User;
7 |
8 |
9 | /**
10 | * Hello 控制器.
11 | *
12 | * @since 1.0.0 2018年3月21日
13 | * @author Way Lau
14 | */
15 | @RestController
16 | public class HelloController {
17 |
18 | @RequestMapping("/hello")
19 | public String hello() {
20 | return "Hello World! Welcome to visit waylau.com!";
21 | }
22 |
23 | @RequestMapping("/hello/way")
24 | public User helloWay() {
25 | return new User("Way Lau", 30);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/java/com/waylau/axon/cqrs/common/events/WithdrawMoneyEvent.java:
--------------------------------------------------------------------------------
1 | package com.waylau.axon.cqrs.common.events;
2 |
3 | import com.waylau.axon.cqrs.common.domain.AccountId;
4 |
5 | /**
6 | * Withdraw Money Event.
7 | *
8 | * @since 1.0.0 2020年1月21日
9 | * @author Way Lau
10 | */
11 | public class WithdrawMoneyEvent {
12 | private AccountId accountId;
13 | private long amount;
14 |
15 | public WithdrawMoneyEvent(AccountId accountId, long amount) {
16 | this.accountId = accountId;
17 | this.amount = amount;
18 | }
19 |
20 | public AccountId getAccountId() {
21 | return accountId;
22 | }
23 |
24 | public long getAmount() {
25 | return amount;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/samples/spring-rest/src/main/java/com/waylau/spring/mvc/vo/User.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.spring.mvc.vo;
5 |
6 | /**
7 | * User.
8 | *
9 | * @since 1.0.0 2018年2月10日
10 | * @author Way Lau
11 | */
12 | public class User {
13 | private String username;
14 | private Integer age;
15 |
16 | public User(String username, Integer age) {
17 | this.username = username;
18 | this.age = age;
19 | }
20 |
21 | public String getUsername() {
22 | return username;
23 | }
24 |
25 | public void setUsername(String username) {
26 | this.username = username;
27 | }
28 |
29 | public Integer getAge() {
30 | return age;
31 | }
32 |
33 | public void setAge(Integer age) {
34 | this.age = age;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/samples/security-basic/src/main/java/com/waylau/spring/mvc/vo/User.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.spring.mvc.vo;
5 |
6 | /**
7 | * User.
8 | *
9 | * @since 1.0.0 2018年2月10日
10 | * @author Way Lau
11 | */
12 | public class User {
13 | private String username;
14 | private Integer age;
15 |
16 | public User(String username, Integer age) {
17 | this.username = username;
18 | this.age = age;
19 | }
20 |
21 | public String getUsername() {
22 | return username;
23 | }
24 |
25 | public void setUsername(String username) {
26 | this.username = username;
27 | }
28 |
29 | public Integer getAge() {
30 | return age;
31 | }
32 |
33 | public void setAge(Integer age) {
34 | this.age = age;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/docs/草稿.md:
--------------------------------------------------------------------------------
1 | ## 分布式计算的概念
2 |
3 | 把一个大计算任务拆分成多个小计算任务分布到若干台机器上去计算,然后再进行结果汇总。
4 |
5 | ## 目的
6 |
7 | * 可靠性:系统本身也不可能是完美的,随时可能会出错,为了避免故障,需要将业务分散开保留一定的冗余度,或者将系统部署到多台机器上提供相同的功能,这个也称为“集群”。
8 | * 扩展性:系统负载高,单台机器无法承载,希望通过使用多台机器来提高系统的负载能力
9 |
10 | ## 注意点
11 |
12 | * 系统如何拆分为子系统
13 | * 子系统间如何规划通信协议
14 | * 一致性
15 | * 容错
16 | * 安全
17 |
18 | ## 基础设施
19 |
20 | * 缓存
21 | * 异步
22 | * 持久化存储
23 | * 消息队列
24 | * 搜索
25 | * 集群
26 | * 负载均衡:淘宝是LVS(Linux Virtual Server)、CDN节点、PV(Page View,页面访问量)、个UV(Unique Visitor,用户访问)
27 | * 数据压缩
28 | * 分析和挖掘
29 |
30 | 架构是一开始就能设计完美,需要不断优化
31 |
32 | “火车模型”:一个功能没有测试通过,整个系统都不能发布。即任何一个乘客没有上车,都不许发车。
33 |
34 | 超市的运维的抽象
35 |
36 | Memcache: 分布式缓存
37 | Hadoop:离线分析
38 |
39 | jetty tomcat
40 |
41 | :“I hear and I forget. I see and I remember. I do and I understand”
42 |
43 | 荀子说的“不闻不若闻之,闻之不若见之,见之不若知之,知之不若行之。”
--------------------------------------------------------------------------------
/samples/cxf-rest/src/main/java/com/waylau/cxf/HelloWorld.java:
--------------------------------------------------------------------------------
1 | package com.waylau.cxf;
2 | import javax.ws.rs.Consumes;
3 | import javax.ws.rs.GET;
4 | import javax.ws.rs.POST;
5 | import javax.ws.rs.Path;
6 | import javax.ws.rs.PathParam;
7 | import javax.ws.rs.Produces;
8 | import javax.ws.rs.core.Response;
9 |
10 | @Path("/hello")
11 | public class HelloWorld {
12 |
13 | @GET
14 | @Path("/echo/{input}")
15 | @Produces("text/plain")
16 | public String ping(@PathParam("input") String input) {
17 | return input;
18 | }
19 |
20 | @POST
21 | @Produces("application/json")
22 | @Consumes("application/json")
23 | @Path("/jsonBean")
24 | public Response modifyJson(JsonBean input) {
25 | input.setVal2(input.getVal1());
26 | return Response.ok().entity(input).build();
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/samples/java-ws/src/main/java/com/waylau/java/ws/HelloClient.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.ws;
5 |
6 | import java.net.URL;
7 | import javax.xml.namespace.QName;
8 | import javax.xml.ws.Service;
9 |
10 | /**
11 | * Hello Client.
12 | *
13 | * @since 1.0.0 2020年1月25日
14 | * @author Way Lau
15 | */
16 | public class HelloClient {
17 |
18 | public static void main(String[] args) throws Exception {
19 | URL url = new URL("http://localhost:9999/ws/hello?wsdl");
20 | QName qname = new QName("http://ws.java.waylau.com/",
21 | "HelloServiceImplService");
22 |
23 | Service service = Service.create(url, qname);
24 |
25 | HelloService hello = service.getPort(HelloService.class);
26 | System.out.println(hello.getHelloworld());
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/main/java/com/waylau/spring/cloud/weather/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.repository;
2 |
3 | import java.util.List;
4 |
5 | import com.waylau.spring.cloud.weather.domain.User;
6 |
7 | /**
8 | * 用户仓库.
9 | *
10 | * @since 1.0.0 2017年10月8日
11 | * @author Way Lau
12 | */
13 | public interface UserRepository {
14 |
15 | /**
16 | * 新增或者修改用户
17 | *
18 | * @param user
19 | * @return
20 | */
21 | User saveOrUpateUser(User user);
22 |
23 | /**
24 | * 删除用户
25 | *
26 | * @param id
27 | */
28 | void deleteUser(Long id);
29 |
30 | /**
31 | * 根据用户id获取用户
32 | *
33 | * @param id
34 | * @return
35 | */
36 | User getUserById(Long id);
37 |
38 | /**
39 | * 获取所有用户的列表
40 | *
41 | * @return
42 | */
43 | List listUser();
44 | }
45 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/java/com/waylau/axon/cqrs/command/commands/WithdrawMoneyCommand.java:
--------------------------------------------------------------------------------
1 | package com.waylau.axon.cqrs.command.commands;
2 |
3 | import org.axonframework.commandhandling.TargetAggregateIdentifier;
4 |
5 | import com.waylau.axon.cqrs.common.domain.AccountId;
6 |
7 | /**
8 | * Withdraw Money Command.
9 | *
10 | * @since 1.0.0 2020年1月21日
11 | * @author Way Lau
12 | */
13 | public class WithdrawMoneyCommand {
14 |
15 | @TargetAggregateIdentifier
16 | private AccountId accountId;
17 | private long amount;
18 |
19 |
20 | public WithdrawMoneyCommand(AccountId accountId, long amount) {
21 | this.accountId = accountId;
22 | this.amount = amount;
23 | }
24 |
25 | public AccountId getAccountId() {
26 | return accountId;
27 | }
28 |
29 | public long getAmount() {
30 | return amount;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/samples/spring-rest/src/main/java/com/waylau/spring/mvc/configuration/MvcConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.configuration;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.http.converter.HttpMessageConverter;
7 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
8 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10 |
11 | /**
12 | * MVC Configuration.
13 | *
14 | * @since 1.0.0 2018年3月21日
15 | * @author Way Lau
16 | */
17 | @EnableWebMvc
18 | @Configuration
19 | public class MvcConfiguration implements WebMvcConfigurer {
20 |
21 | public void extendMessageConverters(List> converters) {
22 | converters.add(new MappingJackson2HttpMessageConverter());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/samples/security-basic/src/main/java/com/waylau/spring/mvc/configuration/MvcConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.configuration;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.http.converter.HttpMessageConverter;
7 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
8 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10 |
11 | /**
12 | * MVC Configuration.
13 | *
14 | * @since 1.0.0 2018年3月21日
15 | * @author Way Lau
16 | */
17 | @EnableWebMvc
18 | @Configuration
19 | public class MvcConfiguration implements WebMvcConfigurer {
20 |
21 | @Override
22 | public void extendMessageConverters(List> converters) {
23 | converters.add(new MappingJackson2HttpMessageConverter());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/java/com/waylau/axon/cqrs/common/events/CreateAccountEvent.java:
--------------------------------------------------------------------------------
1 | package com.waylau.axon.cqrs.common.events;
2 |
3 | import com.waylau.axon.cqrs.common.domain.AccountId;
4 |
5 | /**
6 | * Create Account Event.
7 | *
8 | * @since 1.0.0 2020年1月21日
9 | * @author Way Lau
10 | */
11 | public class CreateAccountEvent {
12 | private AccountId accountId;
13 | private String accountName;
14 | private long amount;
15 |
16 | public CreateAccountEvent(AccountId accountId,
17 | String accountName, long amount) {
18 | this.accountId = accountId;
19 | this.accountName = accountName;
20 | this.amount = amount;
21 | }
22 |
23 | public AccountId getAccountId() {
24 | return accountId;
25 | }
26 |
27 | public String getAccountName() {
28 | return accountName;
29 | }
30 |
31 | public long getAmount() {
32 | return amount;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/java/com/waylau/axon/cqrs/command/commands/CreateAccountCommand.java:
--------------------------------------------------------------------------------
1 | package com.waylau.axon.cqrs.command.commands;
2 |
3 | import com.waylau.axon.cqrs.common.domain.AccountId;
4 |
5 | /**
6 | * Create Account Command.
7 | *
8 | * @since 1.0.0 2020年1月21日
9 | * @author Way Lau
10 | */
11 | public class CreateAccountCommand {
12 |
13 | private AccountId accountId;
14 | private String accountName;
15 | private long amount;
16 |
17 | public CreateAccountCommand(AccountId accountId,
18 | String accountName,
19 | long amount) {
20 | this.accountId = accountId;
21 | this.accountName = accountName;
22 | this.amount = amount;
23 | }
24 |
25 | public AccountId getAccountId() {
26 | return accountId;
27 | }
28 |
29 | public String getAccountName() {
30 | return accountName;
31 | }
32 |
33 | public long getAmount() {
34 | return amount;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/queue/ConsumerServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.queue;
2 |
3 |
4 | import javax.jms.Destination;
5 | import javax.jms.JMSException;
6 | import javax.jms.TextMessage;
7 |
8 | import org.springframework.jms.core.JmsTemplate;
9 | /**
10 | * Consumer Service.
11 | *
12 | * @since 1.0.0 2018年4月15日
13 | * @author Way Lau
14 | */
15 | public class ConsumerServiceImpl implements ConsumerService {
16 |
17 | private JmsTemplate jmsTemplate;
18 |
19 | /**
20 | * 接受消息
21 | */
22 | public void receive(Destination destination) {
23 | TextMessage tm = (TextMessage) jmsTemplate.receive(destination);
24 | try {
25 | System.out.println("ConsumerService从队列"
26 | + destination.toString() + "收到了消息:\t" + tm.getText());
27 | } catch (JMSException e) {
28 | e.printStackTrace();
29 | }
30 | }
31 |
32 | public void setJmsTemplate(JmsTemplate jmsTemplate) {
33 | this.jmsTemplate = jmsTemplate;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/samples/java-rmi/src/main/java/com/waylau/java/demo/rmi/RmiEchoClient.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.rmi;
5 |
6 | import java.rmi.registry.LocateRegistry;
7 | import java.rmi.registry.Registry;
8 |
9 | /**
10 | * RMI Echo Client.
11 | *
12 | * @since 1.0.0 2020年1月18日
13 | * @author Way Lau
14 | */
15 | public class RmiEchoClient {
16 |
17 | public static void main(String[] args) {
18 | try {
19 | String host = ServerConstant.HOST;
20 | int port = ServerConstant.PORT;
21 |
22 | Registry registry = LocateRegistry.getRegistry(host, port);
23 | Message stub =
24 | (Message) registry.lookup(ServerConstant.REGIRTRY_NAME);
25 | String response = stub.echoMessage(ServerConstant.HELLO_WORLD);
26 |
27 | System.out.println("Server -> Client: " + response);
28 | } catch (Exception e) {
29 | System.err.println("RmiEchoClient exception: " + e.toString());
30 | e.printStackTrace();
31 | }
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/src/test/java/com/waylau/zk/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.zk;
5 |
6 | import org.junit.Test;
7 |
8 | import com.waylau.zk.discovery.ZkServiceDiscovery;
9 | import com.waylau.zk.registry.ZkServiceRegistry;
10 |
11 |
12 | /**
13 | * Application Tests.
14 | *
15 | * @since 1.0.0 2018年5月15日
16 | * @author Way Lau
17 | */
18 | public class ApplicationTests {
19 |
20 | private static final String SERVER_NAME = "waylau.com";
21 | private static final String SERVER_ADDRESS = "localhost:2181";
22 |
23 | @Test
24 | public void testClient() throws Exception {
25 |
26 | ZkServiceRegistry registry = new ZkServiceRegistry();
27 | registry.init();
28 | registry.registry(SERVER_NAME, SERVER_ADDRESS);
29 |
30 | ZkServiceDiscovery discovery = new ZkServiceDiscovery();
31 | discovery.init();
32 | discovery.discover(SERVER_NAME);
33 |
34 | // 永不停止
35 | while(true) {
36 | }
37 |
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/queue/ProducerService.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.queue;
2 |
3 | import javax.jms.Destination;
4 |
5 | /**
6 | * Producer Service.
7 | *
8 | * @since 1.0.0 2018年4月15日
9 | * @author Way Lau
10 | */
11 | public interface ProducerService {
12 |
13 | /**
14 | * 发消息,向默认的 destination
15 | *
16 | * @param msg
17 | * String 消息内容
18 | */
19 | public void sendMessage(String msg);
20 |
21 | /**
22 | * 发消息,向指定的 destination
23 | *
24 | * @param destination
25 | * 目的地
26 | * @param msg
27 | * String 消息内容
28 | */
29 | public void sendMessage(Destination destination, String msg);
30 |
31 | /**
32 | * 向指定的destination发送消息,消费者接受消息后,把回复的消息写到response队列
33 | *
34 | * @param destination
35 | * 目的地
36 | * @param msg
37 | * String 消息内容
38 | * @param response
39 | * 回复消息的队列
40 | */
41 | public void sendMessage(Destination destination, String msg, Destination response);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/main/java/com/waylau/spring/cloud/weather/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.domain;
2 |
3 | /**
4 | * User.
5 | *
6 | * @since 1.0.0 2017年10月8日
7 | * @author Way Lau
8 | */
9 | public class User {
10 |
11 | private Long id;
12 |
13 | private String name;
14 |
15 | private String email;
16 |
17 | public User() {
18 | }
19 |
20 | public User(String name, String email) {
21 | this.name = name;
22 | this.email = email;
23 | }
24 |
25 | public Long getId() {
26 | return id;
27 | }
28 |
29 | public void setId(Long id) {
30 | this.id = id;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | public String getEmail() {
42 | return email;
43 | }
44 |
45 | public void setEmail(String email) {
46 | this.email = email;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return String.format("User[id=%d, name='%s', email='%s']", id, name, email);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/docs/architecture.md:
--------------------------------------------------------------------------------
1 | # 架构
2 |
3 | ### RMI 架构
4 |
5 | RMI 是一个三层架构(见图)。最上面是 Stub/Skeleton layer(存根/骨架层)。方法调用从 Stub、Remote Reference Layer (远程引用层)和 Transport Layer(传输层)向下,传递给主机,然后再次经传 Transport Layer 层,向上穿过 Remote Reference Layer 和 Skeleton ,到达服务器对象。 Stub 扮演着远程服务器对象的代理的角色,使该对象可被客户激活。Remote Reference Layer 处理语义、管理单一或多重对象的通信,决定调用是应发往一个服务器还是多个。Transport Layer 管理实际的连接,并且追踪可以接受方法调用的远程对象。服务器端的 Skeleton 完成对服务器对象实际的方法调用,并获取返回值。返回值向下经 Remote Reference Layer 、服务器端的 Transport Layer 传递回客户端,再向上经 Transport Layer 和 Remote Reference Layer 返回。最后,Stub 程序获得返回值。
6 |
7 | 要完成以上步骤需要有以下几个步骤:
8 |
9 | * 生成一个远程接口;
10 | * 实现远程对象(服务器端程序);
11 | * 生成 Stub 和 Skeleton(服务器端程序);
12 | * 编写服务器程序 ;
13 | * 编写客户程序 ;
14 | * 注册远程对象;
15 | * 启动远程对象
16 |
17 | 
18 |
19 |
20 |
21 | ### RMI 分布式垃圾回收
22 |
23 | 根据 Java 虚拟机的垃圾回收机制原理,在分布式环境下,服务器进程需要知道哪些对象不再由客户端引用,从而可以被删除(垃圾回收)。在 JVM 中,Java 使用引用计数。当引用计数归零时,对象将会垃圾回收。在RMI,Java 支持两种操作 dirty 和 clean。本地 JVM 定期发送一个 dirty 到服务器来说明该对象仍在使用。定期重发 dirty 的周期是由服务器租赁时间来决定的。当客户端没有需要更多的本地引用远程对象时,它发送一个 clean 调用给服务器。不像 DCOM,服务器不需要计算每个客户机使用的对象,只是简单的做下通知。如果它租赁时间到期之前没有接收到任何 dirty 或者 clean 的消息,则可以安排将对象删除。
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Way Lau
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/samples/spark-word-count/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.waylau.spark
5 | spark-word-count
6 | 1.0.0
7 | spark-word-count
8 | jar
9 |
10 | waylau.com
11 | https://waylau.com
12 |
13 |
14 |
15 | UTF-8
16 | 2.4.4
17 |
18 |
19 |
20 |
21 | org.apache.spark
22 | spark-core_2.11
23 | ${spark.version}
24 |
25 |
26 | org.apache.spark
27 | spark-sql_2.11
28 | ${spark.version}
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/samples/jersey-rest/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/topic/TopicProvider.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.topic;
2 |
3 | import javax.jms.Destination;
4 | import javax.jms.JMSException;
5 | import javax.jms.Message;
6 | import javax.jms.Session;
7 |
8 | import org.springframework.jms.core.JmsTemplate;
9 | import org.springframework.jms.core.MessageCreator;
10 |
11 | /**
12 | * Topic Provider.
13 | *
14 | * @since 1.0.0 2018年4月15日
15 | * @author Way Lau
16 | */
17 | public class TopicProvider {
18 |
19 | private JmsTemplate topicJmsTemplate;
20 |
21 | /**
22 | * 向指定的topic发布消息
23 | *
24 | * @param topic
25 | * @param msg
26 | */
27 | public void publish(final Destination topic, final String msg) {
28 |
29 | topicJmsTemplate.send(topic, new MessageCreator() {
30 | public Message createMessage(Session session) throws JMSException {
31 | System.out.println("TopicProvider 发布了主题:\t"
32 | + topic.toString() + ",发布消息内容为:\t" + msg);
33 | return session.createTextMessage(msg);
34 | }
35 | });
36 | }
37 |
38 | public void setTopicJmsTemplate(JmsTemplate topicJmsTemplate) {
39 | this.topicJmsTemplate = topicJmsTemplate;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/SUMMARY.md:
--------------------------------------------------------------------------------
1 | # Summary
2 |
3 | * [Introduction](README.md)
4 | * [基础概念](docs/basic.md)
5 | * 划分子系统
6 | * 一个“超市”发展的例子
7 | * 分层
8 | * 通信原理
9 | * [IPC](docs/ipc.md)
10 | * [RPC](https://waylau.com/remote-procedure-calls)
11 | * 网络通信基础
12 | * [概述](docs/net-overview.md)
13 | * [Socket](docs/socket.md)
14 | * [BIO](docs/bio.md)
15 | * [NIO](docs/nio.md)
16 | * [AIO](docs/aio.md)
17 | * 分布式对象 Java RMI
18 | * [概述](docs/rmi-overview.md)
19 | * [架构](docs/architecture.md)
20 | * [常用接口](docs/api.md)
21 | * [示例](docs/rmi-example.md)
22 | * 基于消息的通信
23 | * [概述](docs/mq-overview.md)
24 | * [JMS](docs/jms.md)
25 | * [ActiveMQ 示例](docs/actiovemq.md)
26 | * [其他](docs/mq-other.md)
27 | * Web Services
28 | * [概述](docs/web-overview.md)
29 | * [JAX-WS](docs/jax-ws.md)
30 | * [RESTful 概述](docs/rest.md)
31 | * [基于 Jersey 的 JAX-RS 示例 ](docs/jersey.md)
32 | * 微服务
33 | * [概述](docs/mas-overview.md)
34 | * [Spring Boot](docs/spring-boot.md)
35 | * 监控
36 | * [概述](docs/monitor-overview.md)
37 | * [JMX](docs/jmx.md)
38 | * [ZooKeeper](docs/zookeeper.md)
39 | * To be continued ...未完待续...
40 | * [参考文献](docs/Ref.md)
41 |
42 |
--------------------------------------------------------------------------------
/docs/api.md:
--------------------------------------------------------------------------------
1 | # 常用接口
2 |
3 | ### 接口和类
4 |
5 | 所有的远程接口都继承自 `java.rmi.Remote` 接口。例如:
6 |
7 | ```java
8 | public interface bankaccount extends Remote
9 | {
10 | public void deposit(float amount)
11 | throws java.rmi.RemoteException;
12 |
13 | public void withdraw(float amount)
14 | throws OverdrawnException,
15 | java.rmi.RemoteException;
16 | }
17 | ```
18 |
19 | 注意,每个方法必须在 throws 里面声明 `java.rmi.RemoteException` 。 只要客户端调用远程方法出现失败,这个异常就会抛出。
20 |
21 | ### 远程对象类
22 |
23 | `Java.rmi.server.RemoteObject` 类提供了远程对象实现的语义包括hashCode、equals 和 toString。 `java.rmi.server.RemoteServer` 及其子类提供让对象实现远程可见。`java.rmi.server.UnicastRemoteObject` 类定义了客户机与服务器对象实例建立一对一的连接.
24 |
25 | ### 存根
26 |
27 | Java RMI 通过创建存根函数来工作。存根由 rmic 编译器生成。自 Java 1.5 以来,Java 支持在运行时动态生成存根类。编译器 rmic 会提供各种编译选项。
28 |
29 | ### 定位对象
30 |
31 | 引导名称服务提供了用于存储对远程对象的命名引用。一个远程对象引用可以存储使用类 `java.rmi.Naming` 提供的基于 URL 的方法。例如,
32 |
33 | ```
34 | BankAccount acct = new BankAcctImpl();
35 | String url = "rmi://java.sun.com/account";
36 | // bind url to remote object
37 | java.rmi.Naming.bind(url, acct);
38 |
39 | // look up account
40 | acct = (BankAccount)java.rmi.Naming.lookup(url);
41 | ```
42 |
43 | 
44 |
--------------------------------------------------------------------------------
/samples/cxf-rest/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | JAX-RS Simple Service
7 | JAX-RS Simple Service
8 |
9 | contextConfigLocation
10 | WEB-INF/beans.xml
11 |
12 |
13 |
14 | org.springframework.web.context.ContextLoaderListener
15 |
16 |
17 |
18 | CXFServlet
19 |
20 | org.apache.cxf.transport.servlet.CXFServlet
21 |
22 | 1
23 |
24 |
25 | CXFServlet
26 | /*
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/cxf-rest/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/java-rmi/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.waylau
7 | java-rmi
8 | 1.0.0
9 | jar
10 |
11 | java-rmi
12 | https://waylau.com
13 |
14 |
15 | UTF-8
16 | 1.8
17 | ${maven.compiler.source}
18 | 5.5.2
19 |
20 |
21 |
22 |
23 | maven-compiler-plugin
24 | 3.8.1
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.junit.jupiter
32 | junit-jupiter
33 | ${junit.jupiter.version}
34 | test
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/samples/java-io-mode/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.waylau
7 | java-io-mode
8 | 1.0.0
9 | jar
10 |
11 | java-io-mode
12 | https://waylau.com
13 |
14 |
15 | UTF-8
16 | 1.8
17 | ${maven.compiler.source}
18 | 5.5.2
19 |
20 |
21 |
22 |
23 | maven-compiler-plugin
24 | 3.8.1
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.junit.jupiter
32 | junit-jupiter
33 | ${junit.jupiter.version}
34 | test
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/samples/java-concurrency/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.waylau
7 | java-concurrency
8 | 1.0.0
9 | jar
10 |
11 | java-concurrency
12 | https://waylau.com
13 |
14 |
15 | UTF-8
16 | 1.8
17 | ${maven.compiler.source}
18 | 5.5.2
19 |
20 |
21 |
22 |
23 | maven-compiler-plugin
24 | 3.8.1
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.junit.jupiter
32 | junit-jupiter
33 | ${junit.jupiter.version}
34 | test
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/docs/mq-overview.md:
--------------------------------------------------------------------------------
1 | # 概述
2 |
3 | 面向消息的中间件(MOM)或者消息队列(MQ),提供了以松散耦合的灵活方式集成应用程序的一种机制。它们提供了基于存储和转发的应用程序之间的异步数据发送,即应用程序彼此不直接通信,而是与作为中介的 MOM 通信。MOM 提供了有保证的消息发送,应用程序开发人员无需了解远程过程调用(PRC)和网络/通信协议的细节。
4 |
5 | ## 消息中间件简介
6 |
7 | 远程过程调用有助于隐藏分布式系统中的通信细节,也就是说增强了访问透明性。但这种机制并不一定适合所有场景。特别是当无法保证发出请求时接收端一定正在执行的情况下,就必须有其他的通信服务。同时 RPC 的同步特性也会造成客户在发出请求得到处理之前被阻塞了,因而有时也需要采取其他的办法。而面向消息的通信就是解决了上面提到的种种问题。
8 |
9 | 面向消息的通信一般是由消息队列系统(Message-Queuing System,MQ)或者面向消息中间件( Message-Oriented Middleware,MOM)来提供高效可靠的消息传递机制进行平台无关的数据交流,并可基于数据通信进行分布系统的集成。通过提供消息传递和消息排队模型,可在分布环境下扩展进程间的通信,并支持多种通讽协议、语言、应用程序、硬件和软件平台。
10 |
11 | 通过使用 MQ 或者 MOM,通信双方的程序(称其为消息客户程序)可以在不同的时间运行,程序不在网络上直接通话,而是间接地将消息放入 MQ 或者 MOM 服务器的消息机制中。因为程序间没有直接的联系,所以它们不必同时运行:消息放入适当的队列时,目标程序不需要正在运行;即使目标程序在运行,也不意味着要立即处理该消息。
12 |
13 | 消息客户程序之间通过将消息放入消息队列或从消息队列中取出消息来进行通讯。客户程序不直接与其他程序通信,避免了网络通讯的复杂性。消息队列和网络通信的维护工作由 MQ 或者 MOM 完成。
14 |
15 | 常见的 MQ 或者 MOM 产品有 Java Message Service、Apache ActiveMQ、RocketMQ、RabbitMQ、Apache Kafka 等。
16 |
17 | ## 消息中间件优点
18 |
19 | 消息中间件作为一个中间层软件,它为分布式系统中创建、发送、接收消息提供了一套可靠通用的方法,实现了分布式系统中可靠的、高效的、实时的跨平台数据传输。消息中间件减少了开发跨平台和网络协议软件的复杂性,它屏蔽了不同操作系统和网络协议的具体细节,面对规模和复杂度都越来越高的分布式系统,消息中间件技术显示出了它的优越性:
20 |
21 | 1. 采用异步通信模式:发送消息者可以在发送消息后进行其它的工作,不用等待接收者的回应,而接收者也不必在接到消息后立即对发送者的请求进行处理;
22 | 2. 客户和服务对象生命周期的松耦合关系:客户进程和服务对象进程不要求都正常运行,如果由于服务对象崩溃或者网络故障导致客户的请求不可达,客户不会接收到异常,消息中间件能保证消息不会丢失。
--------------------------------------------------------------------------------
/samples/cxf-rest/src/main/webapp/WEB-INF/beans.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/samples/jms-msg/src/main/java/com/waylau/spring/jms/queue/ConsumerSessionAwareMessageListener.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.jms.queue;
2 |
3 | import javax.jms.Destination;
4 | import javax.jms.JMSException;
5 | import javax.jms.MessageProducer;
6 | import javax.jms.Session;
7 | import javax.jms.TextMessage;
8 |
9 | import org.springframework.jms.listener.SessionAwareMessageListener;
10 |
11 | /**
12 | * Consumer SessionAwareMessageListener.
13 | * SessionAwareMessageListener提供了一个快捷的方法,方便我们在接受消息以后,发送一条回复消息 *
14 | * onMessage()有2个参数,一个是收到的消息,另一个Session可以用于发送回复消息。
15 | *
16 | * @since 1.0.0 2018年4月15日
17 | * @author Way Lau
18 | */
19 | public class ConsumerSessionAwareMessageListener
20 | implements SessionAwareMessageListener {
21 |
22 | private Destination destination;
23 |
24 | public void onMessage(TextMessage message, Session session) throws JMSException {
25 | // 接受消息
26 | System.out.println("SessionAwareMessageListener收到一条消息:\t" + message.getText());
27 |
28 | // 发送消息
29 | MessageProducer producer = session.createProducer(destination);
30 | TextMessage tm =
31 | session.createTextMessage("I am ConsumerSessionAwareMessageListener");
32 | producer.send(tm);
33 |
34 | }
35 |
36 | public void setDestination(Destination destination) {
37 | this.destination = destination;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/samples/java-rmi/src/main/java/com/waylau/java/demo/rmi/RmiEchoServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.rmi;
5 |
6 | import java.rmi.RemoteException;
7 | import java.rmi.registry.LocateRegistry;
8 | import java.rmi.registry.Registry;
9 | import java.rmi.server.UnicastRemoteObject;
10 |
11 | /**
12 | * RMI Echo Server.
13 | *
14 | * @since 1.0.0 2020年1月18日
15 | * @author Way Lau
16 | */
17 | public class RmiEchoServer implements Message {
18 |
19 | @Override
20 | public String echoMessage(String msg) throws RemoteException {
21 | System.out.println("Client -> Server: " + msg);
22 | return msg;
23 | }
24 |
25 | public static void main(String args[]) {
26 |
27 | try {
28 | int port = ServerConstant.PORT;
29 |
30 | RmiEchoServer obj = new RmiEchoServer();
31 | Message stub = (Message) UnicastRemoteObject.exportObject(obj, 0);
32 |
33 | // 绑定远程对象的stub到注册中心
34 | Registry registry =
35 | LocateRegistry.getRegistry(port); // 如不指定端口,默认使用1099
36 | registry.rebind(ServerConstant.REGIRTRY_NAME, stub);
37 |
38 | System.err.println("RmiEchoServer started on port: " + port);
39 | } catch (Exception e) {
40 | System.err.println("RmiEchoServer exception: " + e.toString());
41 | e.printStackTrace();
42 | }
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/samples/javase-rest/src/main/java/com/waylau/rest/App.java:
--------------------------------------------------------------------------------
1 | package com.waylau.rest;
2 |
3 | //import org.glassfish.grizzly.http.server.HttpServer;
4 | //import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
5 | //import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
6 | //import org.glassfish.jersey.simple.SimpleContainerFactory;
7 |
8 | import java.io.IOException;
9 | import java.net.URI;
10 |
11 | import org.glassfish.jersey.jetty.JettyHttpContainerFactory;
12 |
13 | /**
14 | * 主应用
15 | *
16 | */
17 | public class App {
18 | // HTTP server 所要监听的 uri
19 | public static final String BASE_URI = "http://192.168.11.125:8081/";
20 |
21 | /**
22 | * Main 方法.
23 | *
24 | * @param args
25 | * @throws IOException
26 | */
27 | public static void main(String[] args) throws IOException {
28 |
29 | // 若使用 Jdk Http Server请去掉下面的注释
30 | // JdkHttpServerFactory.createHttpServer(URI.create(BASE_URI), new
31 | // RestApplication());
32 |
33 | // 若使用 Grizzly Http Server请去掉下面的注释
34 | // GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), new
35 | // RestApplication());
36 |
37 | // 若使用 Simple Http Server请去掉下面的注释
38 | // SimpleContainerFactory.create(URI.create(BASE_URI), new
39 | // RestApplication());
40 | // 若使用 Jetty Http Server请去掉下面的注释
41 | JettyHttpContainerFactory.createServer(URI.create(BASE_URI),
42 | new RestApplication());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/docs/basic.md:
--------------------------------------------------------------------------------
1 | # 基础概念
2 |
3 | ## 概述
4 |
5 | 本书主要讲解的是关于 Java 在分布式系统中的应用。本书的读者假设都具备了 Java 的基础知识。
6 | 如果你需要了解有关 Java 基础知识,可以参阅笔者的另外一本开源书[《Java 编程要点》](https://github.com/waylau/essential-java)。
7 |
8 | ## 分布式系统的概念
9 |
10 | 《分布式系统原理与范型》一书中是这样定义分布式系统的:
11 |
12 | >分布式系统是若干独立计算机的集合,这些计算机对于用户来说就像是单个相关系统。
13 |
14 | 这里面包含了2个含义:
15 |
16 | * 硬件独立:计算机机器本身是独立的
17 | * 软件统一:对于用户来说,他们就像是跟单个系统打交道
18 |
19 | 分布式系统的扩展和升级都比较容易。分布式系统某些节点故障,不影响整理可用。用户和应用程序交互时,不会察觉哪些部分正在替换或者维修,也不会感知到新部分的加入。
20 |
21 | 万维网就是一个分布式文档模型的简单例子。要查看某个文档,用户只需要电机相关的链接即可,文档就会呈现在屏幕上。用户无需关心文档是位于哪个位置,是由什么服务器处理。概念上讲 Web 看起来就是一个单独的服务器。而实际上,Web 在物理上是分布到非常多的服务器上的。
22 |
23 | ## 如何设计分布式系统
24 |
25 | 设计分布式系统的本质就是
26 |
27 | **“如何合理将一个系统拆分成多个子系统部署到不同机器上”**
28 |
29 | 分布式系统的设计应考虑以下几个问题:
30 |
31 | * 系统如何拆分为子系统?
32 | * 如何规划子系统间的通信?
33 | * 如何让子系统可以扩展?
34 | * 通信过程中的安全如何考虑?
35 | * 子系统的可靠性如何保证?
36 | * 数据的一致性是如何实现的?
37 |
38 | 本书就是针对分布式系统中常见的问题进行探讨。
39 |
40 | ## Java 分布式系统
41 |
42 | 上面讲到的都是分布式系统的通用的概念,那么采用 Java 来实现分布式系统有什么好处呢?
43 |
44 | * Java 编程语言是一种通用的、并行的、基于类的、面向对象的语言。它被设计得非常简单,这样程序员可以在该语言上流畅的交流。Java 编程语言与 C 和 C++ 有关联,但组织却截然不同,其中也省略了其他语言的一些用法,比如指针。它的目的是作为一个生产性语言,而不是一个研究性语言,因此,在设计上避免了包括新的和未经考验的功能。更多可以参考[《Java 编程要点》](https://github.com/waylau/essential-java)。
45 | * Java 天然支持分布式应用。
46 | * Java 分布式系统应用广泛,且久经考验,很多大公司比如 Amazon,Linkedin,阿里巴巴等都提供了很多 Java 分布式系统技术方案。
47 | * Java 拥有丰富的中间件框架,避免了很多底层编码的复杂性,帮助你站在巨人的肩膀上。
48 |
49 |
50 | 本书所讲的示例、代码也是基于 Java 语言或者 Java 框架。
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/samples/spark-word-count/src/main/java/com/waylau/spark/JavaWordCount.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spark;
2 | import scala.Tuple2;
3 |
4 | import org.apache.spark.api.java.JavaPairRDD;
5 | import org.apache.spark.api.java.JavaRDD;
6 | import org.apache.spark.sql.SparkSession;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 | import java.util.regex.Pattern;
11 |
12 | /**
13 | * 词频统计
14 | *
15 | * @since 1.0.0 2018年5月14日
16 | * @author Way Lau
17 | */
18 | public final class JavaWordCount {
19 | private static final Pattern SPACE = Pattern.compile(" ");
20 |
21 | public static void main(String[] args) throws Exception {
22 |
23 | if (args.length < 1) {
24 | System.err.println("Usage: JavaWordCount ");
25 | System.exit(1);
26 | }
27 |
28 | SparkSession spark = SparkSession.builder().appName("JavaWordCount").getOrCreate();
29 |
30 | JavaRDD lines = spark.read().textFile(args[0]).javaRDD();
31 |
32 | JavaRDD words = lines.flatMap(s -> Arrays.asList(SPACE.split(s)).iterator());
33 |
34 | JavaPairRDD ones = words.mapToPair(s -> new Tuple2<>(s, 1));
35 |
36 | JavaPairRDD counts = ones.reduceByKey((i1, i2) -> i1 + i2);
37 |
38 | List> output = counts.collect();
39 | for (Tuple2, ?> tuple : output) {
40 | System.out.println(tuple._1() + ": " + tuple._2());
41 | }
42 | spark.stop();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/main/java/com/waylau/spring/cloud/weather/repository/UserRepositoryImpl.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.repository;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.concurrent.ConcurrentHashMap;
6 | import java.util.concurrent.ConcurrentMap;
7 | import java.util.concurrent.atomic.AtomicLong;
8 |
9 | import org.springframework.stereotype.Repository;
10 |
11 | import com.waylau.spring.cloud.weather.domain.User;
12 |
13 | /**
14 | * 用户资源库.
15 | *
16 | * @version 1.0.0 2017年10月8日
17 | * @author Way Lau
18 | */
19 | @Repository
20 | public class UserRepositoryImpl implements UserRepository {
21 |
22 | private static AtomicLong counter = new AtomicLong();
23 |
24 | private final ConcurrentMap userMap = new ConcurrentHashMap();
25 |
26 | @Override
27 | public User saveOrUpateUser(User user) {
28 | Long id = user.getId();
29 | if (id == null || id <= 0) {
30 | id = counter.incrementAndGet();
31 | user.setId(id);
32 | }
33 | this.userMap.put(id, user);
34 | return this.getUserById(id);
35 | }
36 |
37 | @Override
38 | public void deleteUser(Long id) {
39 | this.userMap.remove(id);
40 | }
41 |
42 | @Override
43 | public User getUserById(Long id) {
44 | return this.userMap.get(id);
45 | }
46 |
47 | @Override
48 | public List listUser() {
49 | return new ArrayList(this.userMap.values());
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/samples/eureka-client/src/test/java/com/waylau/spring/cloud/controller/HelloControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.controller;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.http.MediaType;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import org.springframework.test.web.servlet.MockMvc;
11 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
12 | import static org.hamcrest.Matchers.equalTo;
13 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
15 |
16 | /**
17 | * HelloController Test.
18 | *
19 | * @since 1.0.0 2017年9月27日
20 | * @author Way Lau
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | @AutoConfigureMockMvc
25 | public class HelloControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mockMvc;
29 |
30 | @Test
31 | public void testHello() throws Exception {
32 | mockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
33 | .andExpect(status().isOk())
34 | .andExpect(content().string(equalTo("Hello World! Welcome to visit waylau.com!")));
35 | }
36 | }
--------------------------------------------------------------------------------
/samples/eureka-server/src/test/java/com/waylau/spring/cloud/controller/HelloControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.controller;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.http.MediaType;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import org.springframework.test.web.servlet.MockMvc;
11 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
12 | import static org.hamcrest.Matchers.equalTo;
13 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
15 |
16 | /**
17 | * HelloController Test.
18 | *
19 | * @since 1.0.0 2017年9月27日
20 | * @author Way Lau
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | @AutoConfigureMockMvc
25 | public class HelloControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mockMvc;
29 |
30 | @Test
31 | public void testHello() throws Exception {
32 | mockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
33 | .andExpect(status().isOk())
34 | .andExpect(content().string(equalTo("Hello World! Welcome to visit waylau.com!")));
35 | }
36 | }
--------------------------------------------------------------------------------
/samples/java-ws/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.waylau
7 | java-ws
8 | 1.0.0
9 | jar
10 |
11 | java-ws
12 | https://waylau.com
13 |
14 |
15 | UTF-8
16 | 1.8
17 | ${maven.compiler.source}
18 | 2.3.1
19 | 5.5.2
20 |
21 |
22 |
23 |
24 | maven-compiler-plugin
25 | 3.8.1
26 |
27 |
28 |
29 |
30 |
31 |
32 | javax.xml.ws
33 | jaxws-api
34 | ${jaxws-api.version}
35 | runtime
36 |
37 |
38 |
39 | org.junit.jupiter
40 | junit-jupiter
41 | ${junit.jupiter.version}
42 | test
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/src/test/java/com/waylau/spring/cloud/weather/controller/HelloControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.controller;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.http.MediaType;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import org.springframework.test.web.servlet.MockMvc;
11 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
12 | import static org.hamcrest.Matchers.equalTo;
13 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
15 |
16 | /**
17 | * HelloController Test.
18 | *
19 | * @since 1.0.0 2017年9月27日
20 | * @author Way Lau
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | @AutoConfigureMockMvc
25 | public class HelloControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mockMvc;
29 |
30 | @Test
31 | public void testHello() throws Exception {
32 | mockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
33 | .andExpect(status().isOk())
34 | .andExpect(content().string(equalTo("Hello World! Welcome to visit waylau.com!")));
35 | }
36 | }
--------------------------------------------------------------------------------
/samples/spring-boot-rest/src/test/java/com/waylau/spring/cloud/weather/controller/HelloControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.cloud.weather.controller;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.http.MediaType;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import org.springframework.test.web.servlet.MockMvc;
11 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
12 | import static org.hamcrest.Matchers.equalTo;
13 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
15 |
16 | /**
17 | * HelloController Test.
18 | *
19 | * @since 1.0.0 2017年9月27日
20 | * @author Way Lau
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | @AutoConfigureMockMvc
25 | public class HelloControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mockMvc;
29 |
30 | @Test
31 | public void testHello() throws Exception {
32 | mockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
33 | .andExpect(status().isOk())
34 | .andExpect(content().string(equalTo("Hello World! Welcome to visit waylau.com!")));
35 | }
36 | }
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.waylau.spring5
5 | zk-registry-discovery
6 | 1.0.0
7 | zk-registry-discovery
8 | jar
9 |
10 | waylau.com
11 | https://waylau.com
12 |
13 |
14 |
15 | UTF-8
16 | UTF-8
17 | 1.8
18 |
19 |
20 |
21 |
22 | com.101tec
23 | zkclient
24 | 0.10
25 |
26 |
27 | org.springframework
28 | spring-context
29 | 5.0.6.RELEASE
30 |
31 |
32 | com.google.guava
33 | guava
34 | 25.0-jre
35 |
36 |
37 | junit
38 | junit
39 | 4.13.1
40 | test
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/java/com/waylau/axon/cqrs/common/domain/AccountId.java:
--------------------------------------------------------------------------------
1 | package com.waylau.axon.cqrs.common.domain;
2 |
3 | import org.axonframework.common.Assert;
4 | import org.axonframework.common.IdentifierFactory;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * Account Id.
10 | *
11 | * @since 1.0.0 2020年1月21日
12 | * @author Way Lau
13 | */
14 | public class AccountId implements Serializable {
15 |
16 | private static final long serialVersionUID = 7119961474083133148L;
17 | private final String identifier;
18 |
19 | private final int hashCode;
20 |
21 | public AccountId() {
22 | this.identifier =
23 | IdentifierFactory.getInstance().generateIdentifier();
24 | this.hashCode = identifier.hashCode();
25 | }
26 |
27 | public AccountId(String identifier) {
28 | Assert.notNull(identifier, ()->"Identifier may not be null");
29 | this.identifier = identifier;
30 | this.hashCode = identifier.hashCode();
31 | }
32 |
33 | @Override
34 | public boolean equals(Object o) {
35 | if (this == o) return true;
36 | if (o == null || getClass() != o.getClass()) return false;
37 |
38 | AccountId accountId = (AccountId) o;
39 |
40 | return identifier.equals(accountId.identifier);
41 |
42 | }
43 |
44 | @Override
45 | public int hashCode() {
46 | return hashCode;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return identifier;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/samples/java-concurrency/src/main/java/com/waylau/java/demo/concurrency/Deadlock.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.concurrency;
5 |
6 | /**
7 | * Deadlock.
8 | *
9 | * @since 1.0.0 2020年1月17日
10 | * @author Way Lau
11 | */
12 | public class Deadlock {
13 |
14 | public static void main(String[] args) {
15 | final Friend alphonse = new Friend("Alphonse");
16 | final Friend gaston = new Friend("Gaston");
17 | new Thread(new Runnable() {
18 | public void run() {
19 | alphonse.bow(gaston);
20 | }
21 | }).start();
22 |
23 | new Thread(new Runnable() {
24 | public void run() {
25 | gaston.bow(alphonse);
26 | }
27 | }).start();
28 | }
29 |
30 | static class Friend {
31 | private final String name;
32 |
33 | public Friend(String name) {
34 | this.name = name;
35 | }
36 |
37 | public String getName() {
38 | return this.name;
39 | }
40 |
41 | public synchronized void bow(Friend bower) {
42 | System.out.format("%s: %s" + " has bowed to me!%n",
43 | this.name, bower.getName());
44 | bower.bowBack(this);
45 | }
46 |
47 | public synchronized void bowBack(Friend bower) {
48 | System.out.format("%s: %s" + " has bowed back to me!%n",
49 | this.name, bower.getName());
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/samples/jersey-rest/src/test/java/com/waylau/jersey/MyResourceTest.java:
--------------------------------------------------------------------------------
1 | package com.waylau.jersey;
2 |
3 | import javax.ws.rs.client.Client;
4 | import javax.ws.rs.client.ClientBuilder;
5 | import javax.ws.rs.client.WebTarget;
6 |
7 | import org.glassfish.grizzly.http.server.HttpServer;
8 |
9 | import org.junit.After;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 | import static org.junit.Assert.assertEquals;
13 |
14 | public class MyResourceTest {
15 |
16 | private HttpServer server;
17 | private WebTarget target;
18 |
19 | @Before
20 | public void setUp() throws Exception {
21 | // start the server
22 | server = Main.startServer();
23 | // create the client
24 | Client c = ClientBuilder.newClient();
25 |
26 | // uncomment the following line if you want to enable
27 | // support for JSON in the client (you also have to uncomment
28 | // dependency on jersey-media-json module in pom.xml and Main.startServer())
29 | // --
30 | // c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
31 |
32 | target = c.target(Main.BASE_URI);
33 | }
34 |
35 | @After
36 | public void tearDown() throws Exception {
37 | server.stop();
38 | }
39 |
40 | /**
41 | * Test to see that the message "Got it!" is sent in the response.
42 | */
43 | @Test
44 | public void testGetIt() {
45 | String responseMsg = target.path("myresource").request().get(String.class);
46 | assertEquals("Got it!", responseMsg);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/samples/jersey-rest/src/main/java/com/waylau/jersey/Main.java:
--------------------------------------------------------------------------------
1 | package com.waylau.jersey;
2 |
3 | import org.glassfish.grizzly.http.server.HttpServer;
4 | import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
5 | import org.glassfish.jersey.server.ResourceConfig;
6 |
7 | import java.io.IOException;
8 | import java.net.URI;
9 |
10 | /**
11 | * Main class.
12 | *
13 | */
14 | public class Main {
15 | // Base URI the Grizzly HTTP server will listen on
16 | public static final String BASE_URI = "http://localhost:8080/myapp/";
17 |
18 | /**
19 | * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
20 | * @return Grizzly HTTP server.
21 | */
22 | public static HttpServer startServer() {
23 | // create a resource config that scans for JAX-RS resources and providers
24 | // in com.waylau.jersey package
25 | final ResourceConfig rc = new ResourceConfig().packages("com.waylau.jersey");
26 |
27 | // create and start a new instance of grizzly http server
28 | // exposing the Jersey application at BASE_URI
29 | return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
30 | }
31 |
32 | /**
33 | * Main method.
34 | * @param args
35 | * @throws IOException
36 | */
37 | public static void main(String[] args) throws IOException {
38 | final HttpServer server = startServer();
39 | System.out.println(String.format("Jersey app started with WADL available at "
40 | + "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
41 | System.in.read();
42 | server.stop();
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/samples/eureka-server/build.gradle:
--------------------------------------------------------------------------------
1 | // buildscript 代码块中脚本优先执行
2 | buildscript {
3 |
4 | // ext 用于定义动态属性
5 | ext {
6 | springBootVersion = '2.0.0.RELEASE'
7 | }
8 |
9 | // 使用了Maven的中央仓库及Spring自己的仓库(也可以指定其他仓库)
10 | repositories {
11 | //mavenCentral()
12 | maven { url "https://repo.spring.io/snapshot" }
13 | maven { url "https://repo.spring.io/milestone" }
14 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
15 | }
16 |
17 | // 依赖关系
18 | dependencies {
19 |
20 | // classpath 声明了在执行其余的脚本时,ClassLoader 可以使用这些依赖项
21 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
22 | }
23 | }
24 |
25 | // 使用插件
26 | apply plugin: 'java'
27 | apply plugin: 'eclipse'
28 | apply plugin: 'org.springframework.boot'
29 | apply plugin: 'io.spring.dependency-management'
30 |
31 | // 指定了生成的编译文件的版本,默认是打成了 jar 包
32 | group = 'com.waylau.spring.cloud'
33 | version = '1.0.0'
34 |
35 | // 指定编译 .java 文件的 JDK 版本
36 | sourceCompatibility = 1.8
37 |
38 | // 使用了Maven的中央仓库及Spring自己的仓库(也可以指定其他仓库)
39 | repositories {
40 | //mavenCentral()
41 | maven { url "https://repo.spring.io/snapshot" }
42 | maven { url "https://repo.spring.io/milestone" }
43 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
44 | }
45 |
46 | ext {
47 | springCloudVersion = 'Finchley.M9'
48 | }
49 |
50 | dependencies {
51 |
52 | // 添加 Spring Cloud Netflix Eureka Server 依赖
53 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
54 |
55 | // 该依赖用于测试阶段
56 | testCompile('org.springframework.boot:spring-boot-starter-test')
57 | }
58 |
59 | dependencyManagement {
60 | imports {
61 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/samples/hello-world-docker/build.gradle:
--------------------------------------------------------------------------------
1 | // buildscript 代码块中脚本优先执行
2 | buildscript {
3 |
4 | // ext 用于定义动态属性
5 | ext {
6 | springBootVersion = '2.0.0.M4'
7 | }
8 |
9 | // 使用了Maven的中央仓库及Spring自己的仓库(也可以指定其他仓库)
10 | repositories {
11 | //mavenCentral()
12 | maven { url "https://repo.spring.io/snapshot" }
13 | maven { url "https://repo.spring.io/milestone" }
14 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
15 | }
16 |
17 | // 依赖关系
18 | dependencies {
19 |
20 | // classpath 声明了在执行其余的脚本时,ClassLoader 可以使用这些依赖项
21 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
22 |
23 | classpath('gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.17.2')
24 | }
25 | }
26 |
27 | // 使用插件
28 | apply plugin: 'java'
29 | apply plugin: 'eclipse'
30 | apply plugin: 'org.springframework.boot'
31 | apply plugin: 'io.spring.dependency-management'
32 |
33 | apply plugin: 'com.palantir.docker'
34 |
35 | // 指定了生成的编译文件的版本,默认是打成了 jar 包
36 | group = 'com.waylau.spring.cloud'
37 | version = '1.0.0'
38 |
39 | // 指定编译 .java 文件的 JDK 版本
40 | sourceCompatibility = 1.8
41 |
42 | docker {
43 | name "${project.group}/${jar.baseName}"
44 | files jar.archivePath
45 | buildArgs(['JAR_FILE': "${jar.archiveName}"])
46 | }
47 |
48 | // 使用了Maven的中央仓库及Spring自己的仓库(也可以指定其他仓库)
49 | repositories {
50 | //mavenCentral()
51 | maven { url "https://repo.spring.io/snapshot" }
52 | maven { url "https://repo.spring.io/milestone" }
53 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
54 | }
55 |
56 | // 依赖关系
57 | dependencies {
58 |
59 | // 该依赖用于编译阶段
60 | compile('org.springframework.boot:spring-boot-starter-web')
61 |
62 | // 该依赖用于测试阶段
63 | testCompile('org.springframework.boot:spring-boot-starter-test')
64 | }
65 |
--------------------------------------------------------------------------------
/samples/security-basic/dependency-reduced-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.waylau.spring
5 | security-basic
6 | security-basic
7 | 1.0.0
8 |
9 | waylau.com
10 | https://waylau.com
11 |
12 |
13 |
14 |
15 | maven-shade-plugin
16 | 3.6.0
17 |
18 |
19 | package
20 |
21 | shade
22 |
23 |
24 |
25 |
26 | com.waylau.spring.mvc.Application
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | spring-snapshots
38 | Spring Snapshots
39 | https://repo.spring.io/snapshot
40 |
41 |
42 |
43 | 5.2.15.RELEASE
44 | 5.1.5.RELEASE
45 | 9.4.14.v20181114
46 | 2.9.7
47 |
48 |
49 |
--------------------------------------------------------------------------------
/samples/eureka-client/build.gradle:
--------------------------------------------------------------------------------
1 | // buildscript 代码块中脚本优先执行
2 | buildscript {
3 |
4 | // ext 用于定义动态属性
5 | ext {
6 | springBootVersion = '2.0.0.RELEASE'
7 | }
8 |
9 | // 使用了Maven的中央仓库及Spring自己的仓库(也可以指定其他仓库)
10 | repositories {
11 | //mavenCentral()
12 | maven { url "https://repo.spring.io/snapshot" }
13 | maven { url "https://repo.spring.io/milestone" }
14 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
15 | }
16 |
17 | // 依赖关系
18 | dependencies {
19 |
20 | // classpath 声明了在执行其余的脚本时,ClassLoader 可以使用这些依赖项
21 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
22 | }
23 | }
24 |
25 | // 使用插件
26 | apply plugin: 'java'
27 | apply plugin: 'eclipse'
28 | apply plugin: 'org.springframework.boot'
29 | apply plugin: 'io.spring.dependency-management'
30 |
31 | // 指定了生成的编译文件的版本,默认是打成了 jar 包
32 | group = 'com.waylau.spring.cloud'
33 | version = '1.0.0'
34 |
35 | // 指定编译 .java 文件的 JDK 版本
36 | sourceCompatibility = 1.8
37 |
38 | // 使用了Maven的中央仓库及Spring自己的仓库(也可以指定其他仓库)
39 | repositories {
40 | //mavenCentral()
41 | maven { url "https://repo.spring.io/snapshot" }
42 | maven { url "https://repo.spring.io/milestone" }
43 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
44 | }
45 |
46 | ext {
47 | springCloudVersion = 'Finchley.M9'
48 | }
49 |
50 | dependencies {
51 |
52 | // 添加 Spring Cloud Starter Netflix Eureka Client 依赖
53 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
54 |
55 | compile('org.springframework.boot:spring-boot-starter-web')
56 |
57 | // 该依赖用于测试阶段
58 | testCompile('org.springframework.boot:spring-boot-starter-test')
59 | }
60 |
61 | dependencyManagement {
62 | imports {
63 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/samples/zk-registry-discovery/src/main/java/com/waylau/zk/registry/ZkServiceRegistry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.zk.registry;
5 |
6 | import org.I0Itec.zkclient.ZkClient;
7 |
8 | import com.waylau.zk.Constant;
9 |
10 | /**
11 | * ZK Service Registry.
12 | *
13 | * @since 1.0.0 2018年5月16日
14 | * @author Way Lau
15 | */
16 | public class ZkServiceRegistry implements ServiceRegistry {
17 |
18 | /**
19 | * ZK 地址.
20 | */
21 | private String zkAddress = "localhost";
22 |
23 | /**
24 | * ZK 客户端.
25 | */
26 | private ZkClient zkClient;
27 |
28 | public void init() {
29 | zkClient = new ZkClient(zkAddress,
30 | Constant.ZK_SESSION_TIMEOUT,
31 | Constant.ZK_CONNECTION_TIMEOUT);
32 |
33 | System.out.println(">>>connect to zookeeper");
34 | }
35 |
36 | @Override
37 | public void registry(String serviceName, String serviceAddress) {
38 | // 创建registry节点(持久)
39 | String registryPath = Constant.ZK_REGISTRY;
40 | if (!zkClient.exists(registryPath)) {
41 | zkClient.createPersistent(registryPath);
42 |
43 | System.out.println(">>>create registry node:" + registryPath);
44 | }
45 |
46 | // 创建service节点(持久)
47 | String servicePath = registryPath + "/" + serviceName;
48 | if (!zkClient.exists(servicePath)) {
49 | zkClient.createPersistent(servicePath);
50 | System.out.println(">>>create service node:" + servicePath);
51 | }
52 |
53 | // 创建address节点(临时)
54 | String addressPath = servicePath + "/address-";
55 | String addressNode = zkClient.createEphemeralSequential(addressPath, serviceAddress);
56 |
57 | System.out.println(">>>create address node:" + addressNode);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/samples/axon-cqrs/src/main/java/com/waylau/axon/cqrs/Application.java:
--------------------------------------------------------------------------------
1 | package com.waylau.axon.cqrs;
2 |
3 |
4 | import static org.slf4j.LoggerFactory.getLogger;
5 |
6 | import org.axonframework.config.Configuration;
7 | import org.axonframework.config.DefaultConfigurer;
8 | import org.axonframework.eventsourcing.eventstore.inmemory.InMemoryEventStorageEngine;
9 | import org.slf4j.Logger;
10 |
11 | import com.waylau.axon.cqrs.command.aggregates.BankAccount;
12 | import com.waylau.axon.cqrs.command.commands.CreateAccountCommand;
13 | import com.waylau.axon.cqrs.command.commands.WithdrawMoneyCommand;
14 | import com.waylau.axon.cqrs.common.domain.AccountId;
15 |
16 | /**
17 | * 主应用入口.
18 | *
19 | * @since 1.0.0 2020年1月21日
20 | * @author Way Lau
21 | */
22 | public class Application {
23 | private static final Logger LOGGER = getLogger(Application.class);
24 |
25 | public static void main(String args[]) throws InterruptedException{
26 | LOGGER.info("Application is start.");
27 | Configuration config = DefaultConfigurer.defaultConfiguration()
28 | .configureAggregate(BankAccount.class)
29 | .configureEmbeddedEventStore(c ->
30 | new InMemoryEventStorageEngine())
31 | .buildConfiguration();
32 | config.start();
33 | AccountId id = new AccountId();
34 | config.commandGateway().send(new CreateAccountCommand(id,
35 | "MyAccount",1000));
36 | config.commandGateway().send(new WithdrawMoneyCommand(id, 500));
37 | config.commandGateway().send(new WithdrawMoneyCommand(id, 500));
38 | config.commandGateway().send(new WithdrawMoneyCommand(id, 500));
39 |
40 | // 线程先睡五秒,等事件处理完
41 | Thread.sleep(5000L);
42 |
43 | LOGGER.info("Application is shutdown.");
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/samples/spring-rest/src/main/java/com/waylau/spring/mvc/JettyServer.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc;
2 |
3 | import org.eclipse.jetty.server.Server;
4 | import org.eclipse.jetty.servlet.ServletContextHandler;
5 | import org.eclipse.jetty.servlet.ServletHolder;
6 | import org.springframework.web.context.ContextLoaderListener;
7 | import org.springframework.web.context.WebApplicationContext;
8 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
9 | import org.springframework.web.servlet.DispatcherServlet;
10 |
11 | import com.waylau.spring.mvc.configuration.AppConfiguration;
12 |
13 | /**
14 | * Jetty Server.
15 | *
16 | * @since 1.0.0 2018年3月21日
17 | * @author Way Lau
18 | */
19 | public class JettyServer {
20 | private static final int DEFAULT_PORT = 8080;
21 | private static final String CONTEXT_PATH = "/";
22 | private static final String MAPPING_URL = "/*";
23 |
24 | public void run() throws Exception {
25 | Server server = new Server(DEFAULT_PORT);
26 | server.setHandler(servletContextHandler(webApplicationContext()));
27 | server.start();
28 | server.join();
29 | }
30 |
31 | private ServletContextHandler servletContextHandler(WebApplicationContext context) {
32 | ServletContextHandler handler = new ServletContextHandler();
33 | handler.setContextPath(CONTEXT_PATH);
34 | handler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
35 | handler.addEventListener(new ContextLoaderListener(context));
36 | return handler;
37 | }
38 |
39 | private WebApplicationContext webApplicationContext() {
40 | AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
41 | context.register(AppConfiguration.class);
42 | return context;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/samples/security-basic/src/main/java/com/waylau/spring/mvc/configuration/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.waylau.spring.mvc.configuration;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7 | import org.springframework.security.core.userdetails.User;
8 | import org.springframework.security.core.userdetails.UserDetailsService;
9 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
10 |
11 | /**
12 | * Web Security Configuration.
13 | *
14 | * @since 1.0.0 2018年3月21日
15 | * @author Way Lau
16 | */
17 | @EnableWebSecurity // 启用Spring Security功能
18 | public class WebSecurityConfig
19 | extends WebSecurityConfigurerAdapter {
20 |
21 | /**
22 | * 自定义配置
23 | */
24 | @Override
25 | protected void configure(HttpSecurity http) throws Exception {
26 | http.authorizeRequests().anyRequest().authenticated()//所有请求都需认证
27 | .and()
28 | .formLogin() // 使用form表单登录
29 | .and()
30 | .httpBasic(); // HTTP基本认证
31 | }
32 |
33 | @SuppressWarnings("deprecation")
34 | @Bean
35 | @Override
36 | public UserDetailsService userDetailsService() {
37 | InMemoryUserDetailsManager manager =
38 | new InMemoryUserDetailsManager();
39 |
40 | manager.createUser(
41 | User.withDefaultPasswordEncoder() // 密码编码器
42 | .username("waylau") // 用户名
43 | .password("123") // 密码
44 | .roles("USER") // 角色
45 | .build()
46 | );
47 | return manager;
48 | }
49 | }
--------------------------------------------------------------------------------
/samples/jms-msg/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.waylau.spring5
5 | jms-msg
6 | 1.0.0
7 | jms-msg
8 | jar
9 |
10 | waylau.com
11 | https://waylau.com
12 |
13 |
14 |
15 | UTF-8
16 | 5.2.3.RELEASE
17 | 4.13.1
18 | 5.15.11
19 |
20 |
21 |
22 |
23 | junit
24 | junit
25 | ${junit.version}
26 | test
27 |
28 |
29 | org.apache.activemq
30 | activemq-all
31 | ${activemq.version}
32 |
33 |
34 | org.springframework
35 | spring-core
36 | ${spring.version}
37 |
38 |
39 | org.springframework
40 | spring-aop
41 | ${spring.version}
42 |
43 |
44 | org.springframework
45 | spring-jms
46 | ${spring.version}
47 |
48 |
49 | org.springframework
50 | spring-test
51 | ${spring.version}
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/samples/java-io-mode/src/main/java/com/waylau/java/demo/net/BlockingEchoServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.net;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.io.InputStreamReader;
9 | import java.io.PrintWriter;
10 | import java.net.ServerSocket;
11 | import java.net.Socket;
12 |
13 | /**
14 | * Blocking Echo Server.
15 | *
16 | * @since 1.0.0 2019年9月28日
17 | * @author Way Lau
18 | */
19 | public class BlockingEchoServer {
20 |
21 | public static int DEFAULT_PORT = 7;
22 |
23 | /**
24 | * @param args
25 | */
26 | public static void main(String[] args) {
27 |
28 | int port;
29 |
30 | try {
31 | port = Integer.parseInt(args[0]);
32 | } catch (RuntimeException ex) {
33 | port = DEFAULT_PORT;
34 | }
35 |
36 | ServerSocket serverSocket = null;
37 | try {
38 | // 服务器监听
39 | serverSocket = new ServerSocket(port);
40 | System.out.println(
41 | "BlockingEchoServer已启动,端口:" + port);
42 |
43 | } catch (IOException e) {
44 | System.out.println(
45 | "BlockingEchoServer启动异常,端口:" + port);
46 | System.out.println(e.getMessage());
47 | }
48 |
49 | // Java 7 try-with-resource语句
50 | try (
51 | // 接受客户端建立链接,生成Socket实例
52 | Socket clientSocket = serverSocket.accept();
53 | PrintWriter out =
54 | new PrintWriter(clientSocket.getOutputStream(), true);
55 |
56 | // 接收客户端的信息
57 | BufferedReader in =
58 | new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));) {
59 | String inputLine;
60 | while ((inputLine = in.readLine()) != null) {
61 |
62 | // 发送信息给客户端
63 | out.println(inputLine);
64 | System.out.println(
65 | "BlockingEchoServer -> " + clientSocket.getRemoteSocketAddress() + ":" + inputLine);
66 | }
67 | } catch (IOException e) {
68 | System.out.println(
69 | "BlockingEchoServer异常!" + e.getMessage());
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/samples/java-io-mode/src/main/java/com/waylau/java/demo/net/BlockingEchoClient.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Welcome to https://waylau.com
3 | */
4 | package com.waylau.java.demo.net;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.io.InputStreamReader;
9 | import java.io.PrintWriter;
10 | import java.net.Socket;
11 | import java.net.UnknownHostException;
12 |
13 | /**
14 | * Blocking Echo Client.
15 | *
16 | * @since 1.0.0 2019年9月28日
17 | * @author Way Lau
18 | */
19 | public class BlockingEchoClient {
20 |
21 | /**
22 | * @param args
23 | */
24 | public static void main(String[] args) {
25 | if (args.length != 2) {
26 | System.err.println(
27 | "用法: java BlockingEchoClient ");
28 | System.exit(1);
29 | }
30 |
31 | String hostName = args[0];
32 | int portNumber = Integer.parseInt(args[1]);
33 |
34 | try (
35 | Socket echoSocket = new Socket(hostName, portNumber);
36 | PrintWriter out =
37 | new PrintWriter(echoSocket.getOutputStream(), true);
38 | BufferedReader in =
39 | new BufferedReader(
40 | new InputStreamReader(echoSocket.getInputStream()));
41 | BufferedReader stdIn =
42 | new BufferedReader(
43 | new InputStreamReader(System.in))
44 | ) {
45 | String userInput;
46 | while ((userInput = stdIn.readLine()) != null) {
47 | out.println(userInput);
48 | System.out.println("echo: " + in.readLine());
49 | }
50 | } catch (UnknownHostException e) {
51 | System.err.println("不明主机,主机名为: " + hostName);
52 | System.exit(1);
53 | } catch (IOException e) {
54 | System.err.println("不能从主机中获取I/O,主机名为:" +
55 | hostName);
56 | System.exit(1);
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/samples/cxf-rest/src/test/java/com/waylau/cxf/HelloWorldIT.java:
--------------------------------------------------------------------------------
1 | package com.waylau.cxf;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.InputStream;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import javax.ws.rs.core.Response;
10 |
11 | import org.apache.cxf.helpers.IOUtils;
12 | import org.apache.cxf.jaxrs.client.WebClient;
13 | import org.codehaus.jackson.JsonParser;
14 | import org.codehaus.jackson.map.MappingJsonFactory;
15 | import org.junit.BeforeClass;
16 | import org.junit.Test;
17 |
18 | public class HelloWorldIT {
19 | private static String endpointUrl;
20 |
21 | @BeforeClass
22 | public static void beforeClass() {
23 | endpointUrl = System.getProperty("service.url");
24 | }
25 |
26 | @Test
27 | public void testPing() throws Exception {
28 | WebClient client =
29 | WebClient.create(endpointUrl + "/hello/echo/SierraTangoNevada");
30 | Response r = client.accept("text/plain").get();
31 | assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
32 | String value = IOUtils.toString((InputStream)r.getEntity());
33 | assertEquals("SierraTangoNevada", value);
34 | }
35 |
36 | @Test
37 | public void testJsonRoundtrip() throws Exception {
38 | List