-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 12b1f61
Showing
68 changed files
with
3,211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM openjdk:11 | ||
COPY ./target/ChatApplication-0.0.1-SNAPSHOT.jar /usr/src/chatapplication/ | ||
WORKDIR /usr/src/chatapplication | ||
EXPOSE 8080 | ||
CMD ["java", "-jar", "ChatApplication-0.0.1-SNAPSHOT.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Week 10-3, Practice | ||
|
||
## Section 1: | ||
|
||
### Task 1: Create Chat Application Using Websocket: | ||
|
||
Overview: | ||
- Oracle Database: store user information | ||
- Websocket: (<a href="">See here</a>) | ||
- RabbitMQ: STOMP broker, keep track of subscriptions and broadcasts messages to subscribed users. (Alternation for default in-memory STOMP broker of Spring) (<a href="src%2Fmain%2Fjava%2Fcom%2Fexample%2Fchatapplication%2Fconfiguration%2FWebSocketConfiguration.java">See here</a>) | ||
- Redis: in-memory database, use for store WebSocket Session, Chat Room information and messages. (<a href="src%2Fmain%2Fjava%2Fcom%2Fexample%2Fchatapplication%2Fchatroom%2Fservice%2Fimplement">See here</a>) | ||
- Apache Zookeeper | ||
- Apache Kafka: (<a href="src%2Fmain%2Fjava%2Fcom%2Fexample%2Fchatapplication%2Fconfiguration%2Fkafka">See here</a>) | ||
|
||
#### Result | ||
- Chat Application with multiple room (multiple WebSocket channel): | ||
|
||
 | ||
 | ||
 | ||
## Section 2: | ||
### Task 1: Add Kafka to project | ||
[ProducerKafkaConfiguration.java](src%2Fmain%2Fjava%2Fcom%2Fexample%2Fchatapplication%2Fconfiguration%2Fkafka%2FProducerKafkaConfiguration.java) | ||
[ConsumerKafkaConfiguration.java](src%2Fmain%2Fjava%2Fcom%2Fexample%2Fchatapplication%2Fconfiguration%2Fkafka%2FConsumerKafkaConfiguration.java) | ||
|
||
- Dynamic create/delete topic, also change Consumer topic at runtime: | ||
|
||
```agsl | ||
@Service | ||
@Slf4j | ||
public class KafkaService { | ||
@Autowired | ||
private AdminClient adminClient; | ||
@Autowired | ||
ConcurrentKafkaListenerContainerFactory<String, Message> listenerContainerFactory; | ||
@Autowired | ||
ConsumerFactory<String, Message> consumerFactory; | ||
ConcurrentMessageListenerContainer<String, Message> listenerContainer; | ||
public void changeTopic(String topic) throws InterruptedException { | ||
log.info("Changing topic to: {}", topic); | ||
if(listenerContainer != null) { | ||
listenerContainer.stop(); | ||
Thread.sleep(2000); | ||
listenerContainer.destroy(); | ||
Thread.sleep(2000); | ||
} | ||
ContainerProperties containerProperties = new ContainerProperties(topic); | ||
containerProperties.setGroupId(RandomStringUtils.randomAlphanumeric(3)); | ||
containerProperties.setMessageListener((MessageListener<String, Message>) message -> { | ||
System.out.println("Kafka listener, topic: " + message.topic().toString() + ", message content: " + message.value().getContent()); | ||
}); | ||
listenerContainer = new ConcurrentMessageListenerContainer<>(consumerFactory, containerProperties); | ||
listenerContainer.start(); | ||
} | ||
public void createTopic(String topic) { | ||
adminClient.createTopics(List.of(TopicBuilder.name(topic).build())); | ||
} | ||
public void deleteTopic(String topic) { | ||
adminClient.deleteTopics(List.of(topic)); | ||
} | ||
} | ||
``` | ||
### Task 2: Run project using Docker | ||
[docker-compose.yml](docker%2Fdocker-compose.yml) | ||
|
||
 | ||
|
||
|
||
### Task 3: Dynamically create/delete Kafka topic | ||
```agsl | ||
public void createTopic(String topic) { | ||
adminClient.createTopics(List.of(TopicBuilder.name(topic).build())); | ||
} | ||
public void deleteTopic(String topic) { | ||
adminClient.deleteTopics(List.of(topic)); | ||
} | ||
``` | ||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
user1:999999999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
version: '3' | ||
|
||
networks: | ||
chat-app: | ||
driver: bridge | ||
|
||
services: | ||
chat-app-zookeeper: | ||
image: 'bitnami/zookeeper:latest' | ||
ports: | ||
- '2181:2181' | ||
environment: | ||
- ALLOW_ANONYMOUS_LOGIN=yes | ||
networks: | ||
- chat-app | ||
chat-app-kafka: | ||
image: 'bitnami/kafka:latest' | ||
ports: | ||
- '9092:9092' | ||
environment: | ||
- KAFKA_CFG_ZOOKEEPER_CONNECT=chat-app-zookeeper:2181 | ||
- ALLOW_ANONYMOUS_LOGIN=yes | ||
- ALLOW_PLAINTEXT_LISTENER=yes | ||
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT | ||
- KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://localhost:9093 | ||
- KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://host.docker.internal:9092,EXTERNAL://localhost:9093 | ||
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT | ||
depends_on: | ||
- chat-app-zookeeper | ||
networks: | ||
- chat-app | ||
chat-app-rabbitmq-stomp: | ||
image: 'pcloud/rabbitmq-stomp:latest' | ||
ports: | ||
- '5672:5672' | ||
- '15672:15672' | ||
- '61613:61613' | ||
networks: | ||
- chat-app | ||
chatApplication: | ||
image: chatapplication:0.0.1 | ||
ports: | ||
- '8080:8080' | ||
environment: | ||
- SPRING_PROFILES_ACTIVE=docker | ||
depends_on: | ||
- chat-app-kafka | ||
- chat-app-rabbitmq-stomp | ||
networks: | ||
- chat-app | ||
chat-app-redis: | ||
image: redis/redis-stack:latest | ||
ports: | ||
- '6381:6379' | ||
- '8003:8001' | ||
networks: | ||
- chat-app |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.