-
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
Showing
6 changed files
with
99 additions
and
2 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
26 changes: 26 additions & 0 deletions
26
...nd/src/main/java/com/thutasann/project_management_backend/controller/RedisController.java
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,26 @@ | ||
package com.thutasann.project_management_backend.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.thutasann.project_management_backend.utilities.redis.RedisPublisher; | ||
|
||
/** | ||
* Redis Testing Purpose | ||
*/ | ||
@RestController | ||
@RequestMapping("/redis") | ||
public class RedisController { | ||
|
||
@Autowired | ||
private RedisPublisher redisPublisher; | ||
|
||
@GetMapping("/publish") | ||
public String publishMessage(@RequestParam String message) { | ||
redisPublisher.publish(message); | ||
return "Message published: " + message; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...rc/main/java/com/thutasann/project_management_backend/utilities/redis/RedisPublisher.java
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,19 @@ | ||
package com.thutasann.project_management_backend.utilities.redis; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.listener.ChannelTopic; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class RedisPublisher { | ||
@Autowired | ||
private RedisTemplate<String, Object> redisTemplate; | ||
|
||
@Autowired | ||
private ChannelTopic topic; | ||
|
||
public void publish(String message) { | ||
redisTemplate.convertAndSend(topic.getTopic(), message); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ement_backend/utilities/RedisService.java → ...backend/utilities/redis/RedisService.java
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
15 changes: 15 additions & 0 deletions
15
...c/main/java/com/thutasann/project_management_backend/utilities/redis/RedisSubscriber.java
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,15 @@ | ||
package com.thutasann.project_management_backend.utilities.redis; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class RedisSubscriber { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(RedisSubscriber.class); | ||
|
||
public void onMessage(String message, String channel) { | ||
logger.info("Received message '{}' from channel '{}'", message, channel); | ||
} | ||
} |