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 1
1
plugins {
2
2
id ' org.springframework.boot' version ' 2.2.7.RELEASE'
3
3
id ' io.spring.dependency-management' version ' 1.0.9.RELEASE'
4
+ id " io.freefair.lombok" version " 5.0.1"
4
5
id ' java'
5
6
}
6
7
Original file line number Diff line number Diff line change 1
1
package com .example .consumer ;
2
2
3
+ import org .redisson .api .RScoredSortedSet ;
4
+ import org .redisson .api .RedissonClient ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
3
6
import org .springframework .web .bind .annotation .GetMapping ;
7
+ import org .springframework .web .bind .annotation .PathVariable ;
8
+ import org .springframework .web .bind .annotation .PostMapping ;
4
9
import org .springframework .web .bind .annotation .RestController ;
5
10
6
11
@ RestController
7
12
public class ConsumerController {
13
+ @ Autowired
14
+ RedissonClient redisson ;
15
+
8
16
@ GetMapping ("/hello" )
9
17
public String hello () {
10
18
return "Hello Consumer" ;
11
19
}
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
+ }
12
27
}
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:
16
16
17
17
redis :
18
18
image : " redis:alpine"
19
+ ports :
20
+ - 9379:6379
Original file line number Diff line number Diff line change 1
1
plugins {
2
2
id ' org.springframework.boot' version ' 2.2.7.RELEASE'
3
3
id ' io.spring.dependency-management' version ' 1.0.9.RELEASE'
4
+ id " io.freefair.lombok" version " 5.0.1"
4
5
id ' java'
5
6
}
6
7
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 1
1
package com .example .producer ;
2
2
3
+ import org .redisson .api .RScoredSortedSet ;
4
+ import org .redisson .api .RedissonClient ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
3
6
import org .springframework .web .bind .annotation .GetMapping ;
7
+ import org .springframework .web .bind .annotation .PostMapping ;
8
+ import org .springframework .web .bind .annotation .RequestBody ;
4
9
import org .springframework .web .bind .annotation .RestController ;
5
10
6
11
@ RestController
7
12
public class ProducerController {
13
+ @ Autowired
14
+ RedissonClient redisson ;
15
+
8
16
@ GetMapping ("/hello" )
9
17
public String hello () {
10
18
return "Hello Producer" ;
11
19
}
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
+ }
12
26
}
You can’t perform that action at this time.
0 commit comments