Skip to content

Commit

Permalink
Create distributed queue
Browse files Browse the repository at this point in the history
  • Loading branch information
geekyme committed May 15, 2020
1 parent 01edd76 commit ba646c3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions consumer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id "io.freefair.lombok" version "5.0.1"
id 'java'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package com.example.consumer;

import org.redisson.api.RScoredSortedSet;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerController {
@Autowired
RedissonClient redisson;

@GetMapping("/hello")
public String hello() {
return "Hello Consumer";
}

@PostMapping("/pollJob/{queueId}")
public String pollJob(@PathVariable String queueId) {
RScoredSortedSet<String> set = redisson.getScoredSortedSet(queueId);

return set.pollLast();
}
}
10 changes: 10 additions & 0 deletions consumer/src/main/java/com/example/consumer/Job.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.consumer;

import lombok.Data;

@Data
public class Job {
private String queueId;
private double score;
private String name;
}
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ services:

redis:
image: "redis:alpine"
ports:
- 9379:6379
1 change: 1 addition & 0 deletions producer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id "io.freefair.lombok" version "5.0.1"
id 'java'
}

Expand Down
10 changes: 10 additions & 0 deletions producer/src/main/java/com/example/producer/Job.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.producer;

import lombok.Data;

@Data
public class Job {
private String queueId;
private double score;
private String name;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package com.example.producer;

import org.redisson.api.RScoredSortedSet;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProducerController {
@Autowired
RedissonClient redisson;

@GetMapping("/hello")
public String hello() {
return "Hello Producer";
}

@PostMapping("/queueJob")
public void queueJob(@RequestBody Job job) {
RScoredSortedSet<String> set = redisson.getScoredSortedSet(job.getQueueId());
set.add(job.getScore(), job.getName());
}
}

0 comments on commit ba646c3

Please sign in to comment.