Skip to content

Commit 22bc73f

Browse files
authored
Middleware and Job-Delay (#57)
* Delay processing of dead letter queue message * Middleware code
1 parent 24c4609 commit 22bc73f

75 files changed

Lines changed: 2718 additions & 1076 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 129 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,90 @@
33
# Check https://circleci.com/docs/2.0/language-java/ for more details
44
#
55
version: 2.1
6+
7+
aliases:
8+
attach_workspace: &attach_workspace
9+
attach_workspace:
10+
at: .
11+
12+
environment: &environment
13+
environment:
14+
SPRING_BOOT_VERSION: 2.2.0.RELEASE
15+
SPRING_VERSION: 5.2.0.RELEASE
16+
SPRING_DATA_VERSION: 2.2.0.RELEASE
17+
MICROMETER_VERSION: 1.3.2
18+
19+
persist_to_workspace: &persist_to_workspace
20+
persist_to_workspace:
21+
root: .
22+
paths:
23+
- .
24+
25+
redis_dep: &redis_dep
26+
run:
27+
name: Install Dependencies
28+
command: |
29+
sudo add-apt-repository ppa:chris-lea/redis-server
30+
sudo apt-get update
31+
sudo apt-get -y install redis-server
32+
redis-cli --version
33+
34+
redis_cluster_setup: &redis_cluster_setup
35+
run:
36+
name: Setup Redis Cluster
37+
background: true
38+
command: |
39+
mkdir 9000 9001 9002 9003 9004 9005
40+
printf "port 9000 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9000/redis.conf
41+
printf "port 9001 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9001/redis.conf
42+
printf "port 9002 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9002/redis.conf
43+
printf "port 9003 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9003/redis.conf
44+
printf "port 9004 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9004/redis.conf
45+
printf "port 9005 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9005/redis.conf
46+
cd 9000 && redis-server ./redis.conf &
47+
cd 9001 && redis-server ./redis.conf &
48+
cd 9002 && redis-server ./redis.conf &
49+
cd 9003 && redis-server ./redis.conf &
50+
cd 9004 && redis-server ./redis.conf &
51+
cd 9005 && redis-server ./redis.conf &
52+
sleep 30
53+
redis-cli --cluster create 127.0.0.1:9000 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003 127.0.0.1:9004 127.0.0.1:9005 --cluster-replicas 1 --cluster-yes
54+
55+
default: &default
56+
executor: rqueue-executor
57+
<<: *environment
58+
59+
copy_logs: &copy_logs
60+
run:
61+
name: Copy Log Files
62+
when: always
63+
command: |
64+
mkdir log || true
65+
test -f rqueue-core/log/monitor.log && cp rqueue-core/log/monitor.log log/core-monitor.log
66+
test -f rqueue-core/log/test.log && cp rqueue-core/log/test.log log/core-test.log
67+
test -f rqueue-spring-boot-starter/log/monitor.log && cp rqueue-spring-boot-starter/log/monitor.log log/boot-monitor.log
68+
test -f rqueue-spring-boot-starter/log/test.log && cp rqueue-spring-boot-starter/log/test.log log/boot-test.log
69+
test -f rqueue-spring/log/monitor.log && cp rqueue-spring/log/monitor.log log/spring-monitor.log
70+
test -f rqueue-spring/log/test.log && cp rqueue-spring/log/test.log log/spring-test.log
71+
72+
copy_test_results: &copy_test_results
73+
run:
74+
name: Copy Test Result Files
75+
when: always
76+
command: |
77+
mkdir test-results || true
78+
test -d rqueue-spring-boot-starter/build/reports/junit/xml && cp -r rqueue-spring-boot-starter/build/reports/junit/xml test-results
79+
test -d rqueue-spring/build/reports/junit/xml && cp -r rqueue-spring/build/reports/junit/xml test-results
80+
test -d rqueue-core/build/reports/junit/xml && cp -r rqueue-core/build/reports/junit/xml test-results
81+
82+
store_logs: &store_logs
83+
store_artifacts:
84+
path: log/
85+
store_test_results: &store_test_results
86+
store_test_results:
87+
path: test-results
88+
89+
690
executors:
791
rqueue-executor:
892
machine:
@@ -22,13 +106,7 @@ executors:
22106

23107
jobs:
24108
build:
25-
executor: rqueue-executor
26-
environment:
27-
SPRING_BOOT_VERSION: 2.1.0.RELEASE
28-
SPRING_VERSION: 5.1.2.RELEASE
29-
SPRING_DATA_VERSION: 2.1.2.RELEASE
30-
MICROMETER_VERSION: 1.1.0
31-
109+
<<: *default
32110
steps:
33111
- checkout
34112
- restore_cache:
@@ -44,126 +122,67 @@ jobs:
44122
key: v1-dependencies-{{ checksum "build.gradle" }}
45123
- run: ./gradlew compileJava
46124
- run: ./gradlew compileTestJava
47-
- persist_to_workspace:
48-
root: .
49-
paths:
50-
- .
125+
- *persist_to_workspace
126+
51127
unit_test:
52-
executor: rqueue-executor
53-
environment:
54-
SPRING_BOOT_VERSION: 2.1.0.RELEASE
55-
SPRING_VERSION: 5.1.2.RELEASE
56-
SPRING_DATA_VERSION: 2.1.2.RELEASE
57-
MICROMETER_VERSION: 1.1.0
128+
<<: *default
58129
steps:
59-
- attach_workspace:
60-
at: .
130+
- *attach_workspace
61131
- run: ./gradlew codeCoverageReport -DincludeTags=unit
62-
- persist_to_workspace:
63-
root: .
64-
paths:
65-
- .
132+
- *persist_to_workspace
133+
- *copy_logs
134+
- *copy_test_results
135+
- *store_logs
136+
- *store_test_results
137+
138+
66139
producer_only_test:
67-
executor: rqueue-executor
68-
environment:
69-
SPRING_BOOT_VERSION: 2.1.0.RELEASE
70-
SPRING_VERSION: 5.1.2.RELEASE
71-
SPRING_DATA_VERSION: 2.1.2.RELEASE
72-
MICROMETER_VERSION: 1.1.0
140+
<<: *default
73141
steps:
74-
- attach_workspace:
75-
at: .
76-
- run:
77-
name: Install Dependencies
78-
command: |
79-
sudo add-apt-repository ppa:chris-lea/redis-server
80-
sudo apt-get update
81-
sudo apt-get -y install redis-server
82-
redis-cli --version
142+
- *attach_workspace
143+
- *redis_dep
83144
- run: ./gradlew codeCoverageReport -DincludeTags=producerOnly
84-
- persist_to_workspace:
85-
root: .
86-
paths:
87-
- .
145+
- *persist_to_workspace
146+
- *copy_logs
147+
- *copy_test_results
148+
- *store_logs
149+
- *store_test_results
150+
88151

89152
integration_test:
90-
executor: rqueue-executor
91-
environment:
92-
SPRING_BOOT_VERSION: 2.1.0.RELEASE
93-
SPRING_VERSION: 5.1.2.RELEASE
94-
SPRING_DATA_VERSION: 2.1.2.RELEASE
95-
MICROMETER_VERSION: 1.1.0
153+
<<: *default
96154
steps:
97-
- attach_workspace:
98-
at: .
99-
- run:
100-
name: Install Dependencies
101-
command: |
102-
sudo add-apt-repository ppa:chris-lea/redis-server
103-
sudo apt-get update
104-
sudo apt-get -y install redis-server
105-
redis-cli --version
155+
- *attach_workspace
156+
- *redis_dep
106157
- run: ./gradlew codeCoverageReport -DincludeTags=integration -DexcludeTags=redisCluster,producerOnly
107-
- persist_to_workspace:
108-
root: .
109-
paths:
110-
- .
158+
- *persist_to_workspace
159+
- *copy_logs
160+
- *copy_test_results
161+
- *store_logs
162+
- *store_test_results
111163

112164
redis_custer_test:
113-
executor: rqueue-executor
114-
environment:
115-
SPRING_BOOT_VERSION: 2.1.0.RELEASE
116-
SPRING_VERSION: 5.1.2.RELEASE
117-
SPRING_DATA_VERSION: 2.1.2.RELEASE
118-
MICROMETER_VERSION: 1.1.0
165+
<<: *default
119166
steps:
120-
# Reuse the workspace from the build job
121-
- attach_workspace:
122-
at: .
123-
- run:
124-
name: Install Dependencies
125-
command: |
126-
sudo add-apt-repository ppa:chris-lea/redis-server
127-
sudo apt-get update
128-
sudo apt-get -y install redis-server
129-
redis-cli --version
130-
- run:
131-
name: Setup Redis Cluster
132-
background: true
133-
command: |
134-
mkdir 9000 9001 9002 9003 9004 9005
135-
printf "port 9000 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9000/redis.conf
136-
printf "port 9001 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9001/redis.conf
137-
printf "port 9002 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9002/redis.conf
138-
printf "port 9003 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9003/redis.conf
139-
printf "port 9004 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9004/redis.conf
140-
printf "port 9005 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9005/redis.conf
141-
cd 9000 && redis-server ./redis.conf &
142-
cd 9001 && redis-server ./redis.conf &
143-
cd 9002 && redis-server ./redis.conf &
144-
cd 9003 && redis-server ./redis.conf &
145-
cd 9004 && redis-server ./redis.conf &
146-
cd 9005 && redis-server ./redis.conf &
147-
sleep 30
148-
redis-cli --cluster create 127.0.0.1:9000 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003 127.0.0.1:9004 127.0.0.1:9005 --cluster-replicas 1 --cluster-yes
167+
- *attach_workspace
168+
- *redis_dep
169+
- *redis_cluster_setup
149170
- run: ./gradlew codeCoverageReport -DincludeTags=redisCluster
150-
- persist_to_workspace:
151-
root: .
152-
paths:
153-
- .
171+
- *persist_to_workspace
172+
- *copy_logs
173+
- *copy_test_results
174+
- *store_logs
175+
- *store_test_results
176+
154177
report_code_coverage:
155-
executor: rqueue-executor
156-
environment:
157-
SPRING_BOOT_VERSION: 2.1.0.RELEASE
158-
SPRING_VERSION: 5.1.2.RELEASE
159-
SPRING_DATA_VERSION: 2.1.2.RELEASE
160-
MICROMETER_VERSION: 1.1.0
178+
<<: *default
161179
steps:
162-
- attach_workspace:
163-
at: .
164-
- run: ls -r build/reports/jacoco/test
165-
- run: pwd
180+
- *attach_workspace
166181
- run: ./gradlew coveralls
182+
- *copy_logs
183+
- *copy_test_results
184+
- *store_logs
185+
- *store_test_results
167186

168187
workflows:
169188
main:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ hs_err_pid*
3030
/.gradle/
3131
/build/
3232
/*/build/
33+
/*/log
3334

3435
.DS_Store

build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ ext {
2828
springDataVersion = System.getenv("SPRING_DATA_VERSION")
2929
microMeterVersion = System.getenv("MICROMETER_VERSION")
3030

31-
// springBootVersion = '2.1.0.RELEASE'
32-
// springVersion = '5.1.2.RELEASE'
33-
// springDataVersion = '2.1.2.RELEASE'
34-
// microMeterVersion = '1.1.0'
31+
springBootVersion = '2.2.0.RELEASE'
32+
springVersion = '5.2.0.RELEASE'
33+
springDataVersion = '2.2.0.RELEASE'
34+
microMeterVersion = '1.3.2'
3535

3636
// logging dependencies
3737
lombokVersion = '1.18.10'
@@ -110,17 +110,17 @@ def publishedProjects = subprojects.findAll({ subproject ->
110110
})
111111

112112
task codeCoverageReport(type: JacocoReport, group: 'verification', description: 'Generate code coverage report') {
113-
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
113+
executionData fileTree(project.rootDir.absolutePath).include("**/build/reports/jacoco/*.exec")
114114

115115
publishedProjects.each {
116116
sourceSets it.sourceSets.main
117117
}
118118

119119
reports {
120-
csv.enabled false
120+
csv.enabled = false
121121
html.enabled = System.getenv("CIRCLECI") != "true"
122-
xml.enabled true
123-
xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
122+
xml.enabled = System.getenv("CIRCLECI") == "true"
123+
xml.destination = file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
124124
}
125125
afterEvaluate {
126126
classDirectories.setFrom(files(classDirectories.files.collect {

gradle/test-runner.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ test {
2727
}
2828
jacoco {
2929
if (System.getenv("CIRCLECI") == "true") {
30-
destinationFile = file("$buildDir/jacoco/${System.env.CIRCLE_WORKFLOW_JOB_ID}_test.exec")
30+
destinationFile = file("$buildDir/reports/jacoco/${System.env.CIRCLE_WORKFLOW_JOB_ID}_test.exec")
31+
} else {
32+
destinationFile = file("$buildDir/reports/jacoco/test.exec")
3133
}
3234
}
35+
reports {
36+
junitXml.enabled = System.getenv("CIRCLECI") == "true"
37+
junitXml.destination = file("$buildDir/reports/junit/xml")
38+
html.enabled = System.getenv("CIRCLECI") != "true"
39+
html.destination = file("$buildDir/reports/junit/html")
40+
}
3341
}

rqueue-core/src/main/java/com/github/sonus21/rqueue/common/RqueueRedisTemplate.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
* Copyright 2020 Sonu Kumar
2+
* Copyright 2021 Sonu Kumar
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and limitations under the License.
914
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
1515
*/
1616

1717
package com.github.sonus21.rqueue.common;
@@ -106,17 +106,7 @@ public Boolean delete(String key) {
106106
}
107107

108108
public Object delete(Collection<String> keys) {
109-
Object result =
110-
RedisUtils.executePipeLine(
111-
getRedisTemplate(),
112-
((connection, keySerializer, valueSerializer) -> {
113-
// TODO fix cross slot error
114-
for (String key : keys) {
115-
connection.del(keySerializer.serialize(key));
116-
}
117-
}));
118-
log.debug("Pipeline result: {}", result);
119-
return result;
109+
return redisTemplate.delete(keys);
120110
}
121111

122112
public DataType type(String key) {

0 commit comments

Comments
 (0)