Skip to content

Commit

Permalink
remove code, fix class name, add ci for chatroom service
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 12, 2023
1 parent a8d2ec1 commit d6e0079
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 42 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/maven_chatroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: (ChatRoom service) Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: rm -rf ~/.m2 && cd springChatRoom && mvn -DskipTests=true package
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yen.springChatRoom.model;
package com.yen.springChatRoom.bean;

public class ChatMessage {
private MessageType type;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.yen.springChatRoom.bean;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class OnlineUser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/topic");
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.yen.springChatRoom.controller;

import com.yen.springChatRoom.model.ChatMessage;
import com.yen.springChatRoom.bean.ChatMessage;
import com.yen.springChatRoom.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Set;

@Controller
public class ChatController {
Expand Down Expand Up @@ -71,9 +67,6 @@ public void addUser(@Payload ChatMessage chatMessage, SimpMessageHeaderAccessor
headerAccessor.getSessionAttributes().put("username", chatMessage.getSender());
redisTemplate.opsForSet().add(onlineUsers, chatMessage.getSender());
redisTemplate.convertAndSend(userStatus, JsonUtil.parseObjToJson(chatMessage));

// show online user

} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.yen.springChatRoom.listener;

import com.yen.springChatRoom.controller.ChatController;
import com.yen.springChatRoom.model.ChatMessage;
import com.yen.springChatRoom.bean.ChatMessage;
import com.yen.springChatRoom.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.yen.springChatRoom.redis;

import com.yen.springChatRoom.model.ChatMessage;
import com.yen.springChatRoom.bean.ChatMessage;
import com.yen.springChatRoom.service.ChatService;
import com.yen.springChatRoom.util.JsonUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -65,31 +65,4 @@ public void onMessage(Message message, byte[] bytes) {
}
}

// @Override
// public void onMessage(Message message, byte[] pattern) {
//
// // super.onMessage(message, pattern);
// byte[] body = message.getBody();
// byte[] channel = message.getChannel();
// String rawMsg;
// String topic;
//
// try{
// rawMsg = redisTemplate.getStringSerializer().deserialize(body);
// topic = redisTemplate.getStringSerializer().deserialize(channel);
// LOGGER.info("Receive raw msg from topic : " + topic + " , raw msg : " + rawMsg);
// }catch (Exception e){
// LOGGER.error("Receive raw msg failed : " + e.getMessage() + e);
// return; // TODO : return custom error msg instead
// }
//
// if (msgToAll.equals(topic)){
// LOGGER.info("Send msg to all users : " + rawMsg + ", topic = " + topic);
// ChatMessage chatMessage = JsonUtil.parseJsonToObj(rawMsg, ChatMessage.class);
// // send msg to all online users
// chatService.sendMsg(chatMessage);
// }else{
// LOGGER.warn("Not sending msg to all user with topic : " + topic);
// }

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.yen.springChatRoom.service;

import com.yen.springChatRoom.controller.ChatController;
import com.yen.springChatRoom.model.ChatMessage;
import com.yen.springChatRoom.bean.ChatMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
import org.springframework.stereotype.Service;

@Service
Expand Down

0 comments on commit d6e0079

Please sign in to comment.