File tree Expand file tree Collapse file tree 7 files changed +53
-0
lines changed
src/main/java/com/example/consumer
src/main/java/com/example/producer Expand file tree Collapse file tree 7 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 11plugins {
22 id ' org.springframework.boot' version ' 2.2.7.RELEASE'
33 id ' io.spring.dependency-management' version ' 1.0.9.RELEASE'
4+ id " io.freefair.lombok" version " 5.0.1"
45 id ' java'
56}
67
Original file line number Diff line number Diff line change 11package com .example .consumer ;
22
3+ import org .redisson .api .RScoredSortedSet ;
4+ import org .redisson .api .RedissonClient ;
5+ import org .springframework .beans .factory .annotation .Autowired ;
36import org .springframework .web .bind .annotation .GetMapping ;
7+ import org .springframework .web .bind .annotation .PathVariable ;
8+ import org .springframework .web .bind .annotation .PostMapping ;
49import org .springframework .web .bind .annotation .RestController ;
510
611@ RestController
712public class ConsumerController {
13+ @ Autowired
14+ RedissonClient redisson ;
15+
816 @ GetMapping ("/hello" )
917 public String hello () {
1018 return "Hello Consumer" ;
1119 }
20+
21+ @ PostMapping ("/pollJob/{queueId}" )
22+ public String pollJob (@ PathVariable String queueId ) {
23+ RScoredSortedSet <String > set = redisson .getScoredSortedSet (queueId );
24+
25+ return set .pollLast ();
26+ }
1227}
Original file line number Diff line number Diff line change 1+ package com .example .consumer ;
2+
3+ import lombok .Data ;
4+
5+ @ Data
6+ public class Job {
7+ private String queueId ;
8+ private double score ;
9+ private String name ;
10+ }
Original file line number Diff line number Diff line change @@ -16,3 +16,5 @@ services:
1616
1717 redis :
1818 image : " redis:alpine"
19+ ports :
20+ - 9379:6379
Original file line number Diff line number Diff line change 11plugins {
22 id ' org.springframework.boot' version ' 2.2.7.RELEASE'
33 id ' io.spring.dependency-management' version ' 1.0.9.RELEASE'
4+ id " io.freefair.lombok" version " 5.0.1"
45 id ' java'
56}
67
Original file line number Diff line number Diff line change 1+ package com .example .producer ;
2+
3+ import lombok .Data ;
4+
5+ @ Data
6+ public class Job {
7+ private String queueId ;
8+ private double score ;
9+ private String name ;
10+ }
Original file line number Diff line number Diff line change 11package com .example .producer ;
22
3+ import org .redisson .api .RScoredSortedSet ;
4+ import org .redisson .api .RedissonClient ;
5+ import org .springframework .beans .factory .annotation .Autowired ;
36import org .springframework .web .bind .annotation .GetMapping ;
7+ import org .springframework .web .bind .annotation .PostMapping ;
8+ import org .springframework .web .bind .annotation .RequestBody ;
49import org .springframework .web .bind .annotation .RestController ;
510
611@ RestController
712public class ProducerController {
13+ @ Autowired
14+ RedissonClient redisson ;
15+
816 @ GetMapping ("/hello" )
917 public String hello () {
1018 return "Hello Producer" ;
1119 }
20+
21+ @ PostMapping ("/queueJob" )
22+ public void queueJob (@ RequestBody Job job ) {
23+ RScoredSortedSet <String > set = redisson .getScoredSortedSet (job .getQueueId ());
24+ set .add (job .getScore (), job .getName ());
25+ }
1226}
You can’t perform that action at this time.
0 commit comments