Skip to content

Commit fa5d51f

Browse files
authored
Pebble template (#75)
* get pending/schedule/processing message count * Counter for priority based queue * Pebble template #74 * wip * pebble template change * pebble template test fix * nonce issue * 2.6.1
1 parent ff7ef9f commit fa5d51f

File tree

29 files changed

+464
-145
lines changed

29 files changed

+464
-145
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# [Rqueue] New and Notable Changes
22

3+
## [2.6.1] - 1-Marc-2021
4+
5+
### Fixes
6+
7+
* Graph not rendering in firefox due to unsafe csp rule
8+
* Crash in dashboard due to Twig template, changed it to Pebble template
9+
310
## [2.6.0] - 22-Feb-2021
411

512
Message counts api
@@ -198,3 +205,5 @@ Fixes:
198205
[2.5.0]: https://repo1.maven.org/maven2/com/github/sonus21/rqueue-core/2.5.0-RELEASE
199206

200207
[2.6.0]: https://repo1.maven.org/maven2/com/github/sonus21/rqueue-core/2.6.0-RELEASE
208+
209+
[2.6.1]: https://repo1.maven.org/maven2/com/github/sonus21/rqueue-core/2.6.1-RELEASE

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ services code is in Spring.
5353
* Add dependency
5454
* Gradle
5555
```groovy
56-
implementation 'com.github.sonus21:rqueue-spring-boot-starter:2.6.0-RELEASE'
56+
implementation 'com.github.sonus21:rqueue-spring-boot-starter:2.6.1-RELEASE'
5757
```
5858
* Maven
5959
```xml
6060
<dependency>
6161
<groupId>com.github.sonus21</groupId>
6262
<artifactId>rqueue-spring-boot-starter</artifactId>
63-
<version>2.6.0-RELEASE</version>
63+
<version>2.6.1-RELEASE</version>
6464
</dependency>
6565
```
6666
@@ -71,14 +71,14 @@ services code is in Spring.
7171
* Add Dependency
7272
* Gradle
7373
```groovy
74-
implementation 'com.github.sonus21:rqueue-spring:2.6.0-RELEASE'
74+
implementation 'com.github.sonus21:rqueue-spring:2.6.1-RELEASE'
7575
```
7676
* Maven
7777
```xml
7878
<dependency>
7979
<groupId>com.github.sonus21</groupId>
8080
<artifactId>rqueue-spring</artifactId>
81-
<version>2.6.0-RELEASE</version>
81+
<version>2.6.1-RELEASE</version>
8282
</dependency>
8383
```
8484

build.gradle

+11-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ext {
5353

5454
// server
5555
javaxServletVersion = '4.0.1'
56-
twigVersion = '5.87.0.RELEASE'
56+
pebbleVersion = '3.1.5'
5757

5858
// database
5959
lettuceVersion = '5.2.0.RELEASE'
@@ -63,22 +63,31 @@ ext {
6363

6464
// other dependencies
6565
javaxValidationApiVersion = '2.0.1.Final'
66+
67+
guavaVersion = '30.1-jre'
6668

6769
}
6870

6971

7072
subprojects {
7173
group = 'com.github.sonus21'
72-
version = '2.6.0-RELEASE'
74+
version = '2.6.1-RELEASE'
7375

7476
dependencies {
7577
// https://mvnrepository.com/artifact/org.springframework/spring-messaging
7678
compile group: 'org.springframework', name: 'spring-messaging', version: "${springVersion}"
7779
// https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis
7880
compile group: 'org.springframework.data', name: 'spring-data-redis', version: "${springDataVersion}"
7981

82+
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
83+
compile group: 'org.apache.commons', name: 'commons-lang3', version: "${lang3Version}"
84+
85+
// https://mvnrepository.com/artifact/com.google.guava/guava
86+
compile group: 'com.google.guava', name: 'guava', version: "${guavaVersion}"
87+
8088
compileOnly "org.projectlombok:lombok:${lombokVersion}"
8189
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
90+
8291
testCompile "org.projectlombok:lombok:${lombokVersion}"
8392
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
8493

@@ -93,8 +102,6 @@ subprojects {
93102
testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockitoVersion}"
94103
// https://mvnrepository.com/artifact/org.hamcrest/hamcrest
95104
testCompile group: 'org.hamcrest', name: 'hamcrest', version: "${hamcrestVersion}"
96-
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
97-
testCompile group: 'org.apache.commons', name: 'commons-lang3', version: "${lang3Version}"
98105
testCompile("org.springframework.boot:spring-boot-test:${springBootVersion}")
99106
testCompile group: 'org.junit-pioneer', name: 'junit-pioneer', version: '0.9.0'
100107

gradle/code-signing.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ publishing {
6161
repositories {
6262
repositories {
6363
maven {
64-
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
65-
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
64+
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2"
65+
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots"
6666
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
6767
credentials {
6868
username sonatypeUsername

rqueue-core/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ dependencies {
1515
compile group: 'javax.servlet', name: 'javax.servlet-api', version: "${javaxServletVersion}"
1616
// https://mvnrepository.com/artifact/org.springframework/spring-webmvc
1717
compile group: 'org.springframework', name: 'spring-webmvc', version: "${springVersion}"
18-
// https://mvnrepository.com/artifact/org.jtwig/jtwig-spring
19-
compile group: 'org.jtwig', name: 'jtwig-spring', version: "${twigVersion}"
18+
compile "io.pebbletemplates:pebble-spring5:${pebbleVersion}"
2019
compile group: 'io.seruco.encoding', name: 'base62', version: "0.1.3"
2120
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
2221
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'

rqueue-core/src/main/java/com/github/sonus21/rqueue/annotation/RqueueListener.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,16 @@
171171
* weighted a round robin approach is used, and weight is followed.
172172
*
173173
* @return the priority for this listener.
174+
* @see #priorityGroup()
174175
*/
175176
String priority() default "";
176177

177178
/**
178-
* Priority group for this listener. More than one priority group can be configured in an
179-
* application. Priority groups are useful when inside a group some queue(s) have higher priority
180-
* then the queue(s).
179+
* Priority group for this listener.
180+
*
181+
* <p>More than one priority group can be configured in an application. Priority groups are
182+
* useful
183+
* when inside a group some queue(s) have higher priority than the other queue(s).
181184
*
182185
* @return priority group name.
183186
*/

rqueue-core/src/main/java/com/github/sonus21/rqueue/config/RqueueListenerBaseConfig.java

+14-19
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
import com.github.sonus21.rqueue.dao.impl.RqueueStringDaoImpl;
3131
import com.github.sonus21.rqueue.metrics.RqueueQueueMetrics;
3232
import com.github.sonus21.rqueue.utils.RedisUtils;
33-
import com.github.sonus21.rqueue.web.view.DateTimeFunction;
34-
import com.github.sonus21.rqueue.web.view.DeadLetterQueuesFunction;
35-
import org.jtwig.environment.EnvironmentConfiguration;
36-
import org.jtwig.environment.EnvironmentConfigurationBuilder;
37-
import org.jtwig.spring.JtwigViewResolver;
38-
import org.jtwig.web.servlet.JtwigRenderer;
33+
import com.github.sonus21.rqueue.utils.pebble.ResourceLoader;
34+
import com.github.sonus21.rqueue.utils.pebble.RqueuePebbleExtension;
35+
import com.mitchellbosecke.pebble.PebbleEngine;
36+
import com.mitchellbosecke.pebble.spring.extension.SpringExtension;
37+
import com.mitchellbosecke.pebble.spring.servlet.PebbleViewResolver;
3938
import org.springframework.beans.factory.annotation.Autowired;
4039
import org.springframework.beans.factory.annotation.Value;
4140
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -172,20 +171,16 @@ public RqueueLockManager rqueueLockManager(RqueueStringDao rqueueStringDao) {
172171
}
173172

174173
@Bean
175-
public JtwigViewResolver rqueueViewResolver() {
176-
EnvironmentConfiguration configuration =
177-
EnvironmentConfigurationBuilder.configuration()
178-
.functions()
179-
.add(new DateTimeFunction())
180-
.add(new DeadLetterQueuesFunction())
181-
.and()
174+
public PebbleViewResolver rqueueViewResolver() {
175+
PebbleEngine pebbleEngine =
176+
new PebbleEngine.Builder()
177+
.extension(new RqueuePebbleExtension(), new SpringExtension(null))
178+
.loader(new ResourceLoader())
182179
.build();
183-
JtwigRenderer renderer = new JtwigRenderer(configuration);
184-
JtwigViewResolver viewResolver = new JtwigViewResolver();
185-
viewResolver.setRenderer(renderer);
186-
viewResolver.setPrefix("classpath:/templates/rqueue/");
187-
viewResolver.setSuffix(".html");
188-
return viewResolver;
180+
PebbleViewResolver resolver = new PebbleViewResolver(pebbleEngine);
181+
resolver.setPrefix("templates/rqueue/");
182+
resolver.setSuffix(".html");
183+
return resolver;
189184
}
190185

191186
@Bean

rqueue-core/src/main/java/com/github/sonus21/rqueue/core/EndpointRegistry.java

+19
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.github.sonus21.rqueue.exception.OverrideException;
2020
import com.github.sonus21.rqueue.exception.QueueDoesNotExist;
2121
import com.github.sonus21.rqueue.listener.QueueDetail;
22+
import com.github.sonus21.rqueue.utils.PriorityUtils;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Map;
@@ -44,6 +45,7 @@ private EndpointRegistry() {}
4445
* @param queueName queue name
4546
* @return queue detail
4647
* @throws QueueDoesNotExist this error is thrown when queue is not registered.
48+
* @see #get(String, String)
4749
*/
4850
public static QueueDetail get(String queueName) {
4951
QueueDetail queueDetail = queueNameToDetail.get(queueName);
@@ -53,6 +55,23 @@ public static QueueDetail get(String queueName) {
5355
return queueDetail;
5456
}
5557

58+
/**
59+
* Get QueueDetail for the given queue, with priority
60+
*
61+
* @param queueName queue name
62+
* @param priority priority of this queue like critical, high
63+
* @return queue detail
64+
* @throws QueueDoesNotExist this error is thrown when queue is not registered.
65+
*/
66+
public static QueueDetail get(String queueName, String priority) {
67+
QueueDetail queueDetail =
68+
queueNameToDetail.get(PriorityUtils.getQueueNameForPriority(queueName, priority));
69+
if (queueDetail == null) {
70+
throw new QueueDoesNotExist(queueName);
71+
}
72+
return queueDetail;
73+
}
74+
5675
public static void register(QueueDetail queueDetail) {
5776
synchronized (lock) {
5877
if (queueNameToDetail.containsKey(queueDetail.getName())) {

rqueue-core/src/main/java/com/github/sonus21/rqueue/listener/RqueueMessagePoller.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ private void execute(QueueThread queueThread, QueueDetail queueDetail, RqueueMes
6969
postProcessingHandler,
7070
message,
7171
queueDetail,
72-
queueThread.getSemaphore()
73-
));
72+
queueThread.getSemaphore()));
7473
}
7574

7675
boolean shouldExit() {
@@ -96,7 +95,9 @@ void poll(int index, String queue, QueueDetail queueDetail, QueueThread queueThr
9695
}
9796
if (!acquired) {
9897
deactivate(index, queue, DeactivateType.SEMAPHORE_UNAVAILABLE);
99-
} else if (isQueueActive(queue)) {
98+
return;
99+
}
100+
if (isQueueActive(queue)) {
100101
try {
101102
RqueueMessage message = getMessage(queueDetail);
102103
log(Level.DEBUG, "Queue: {} Fetched Msg {}", null, queue, message);

rqueue-core/src/main/java/com/github/sonus21/rqueue/listener/StrictPriorityPoller.java

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class StrictPriorityPoller extends RqueueMessagePoller {
5959

6060
private String getQueueToPoll() {
6161
long now = System.currentTimeMillis();
62+
// starvation
6263
for (String queue : queues) {
6364
if (isQueueActive(queue)) {
6465
if (now - lastFetchedTime.get(queue) > Constants.MILLIS_IN_A_MINUTE) {

rqueue-core/src/main/java/com/github/sonus21/rqueue/metrics/RqueueQueueMetrics.java

+49
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,53 @@ public long getProcessingMessageCount(String queue) {
7979
return -1;
8080
}
8181
}
82+
83+
/**
84+
* Get number of messages waiting for consumption
85+
*
86+
* @param queue queue name
87+
* @param priority priority of this queue
88+
* @return -1 if queue is not registered otherwise message count
89+
*/
90+
public long getPendingMessageCount(String queue, String priority) {
91+
try {
92+
QueueDetail queueDetail = EndpointRegistry.get(queue, priority);
93+
return redisTemplate.getListSize(queueDetail.getQueueName());
94+
} catch (QueueDoesNotExist e) {
95+
return -1;
96+
}
97+
}
98+
99+
/**
100+
* Get number of messages waiting in delayed queue, these messages would move to pending queue as
101+
* soon as the scheduled time is reach.
102+
*
103+
* @param queue queue name
104+
* @param priority priority of this queue
105+
* @return -1 if queue is not registered otherwise message count
106+
*/
107+
public long getScheduledMessageCount(String queue, String priority) {
108+
try {
109+
QueueDetail queueDetail = EndpointRegistry.get(queue, priority);
110+
return redisTemplate.getZsetSize(queueDetail.getDelayedQueueName());
111+
} catch (QueueDoesNotExist e) {
112+
return -1;
113+
}
114+
}
115+
116+
/**
117+
* Get number of messages those are currently being processed
118+
*
119+
* @param queue queue name
120+
* @param priority priority of this queue
121+
* @return -1 if queue is not registered otherwise message count
122+
*/
123+
public long getProcessingMessageCount(String queue, String priority) {
124+
try {
125+
QueueDetail queueDetail = EndpointRegistry.get(queue, priority);
126+
return redisTemplate.getZsetSize(queueDetail.getProcessingQueueName());
127+
} catch (QueueDoesNotExist e) {
128+
return -1;
129+
}
130+
}
82131
}

rqueue-core/src/main/java/com/github/sonus21/rqueue/web/view/DateTimeFunction.java rqueue-core/src/main/java/com/github/sonus21/rqueue/utils/pebble/DateTimeFunction.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
*
1515
*/
1616

17-
package com.github.sonus21.rqueue.web.view;
17+
package com.github.sonus21.rqueue.utils.pebble;
1818

1919
import com.github.sonus21.rqueue.utils.DateTimeUtils;
20-
import org.jtwig.functions.FunctionRequest;
21-
import org.jtwig.functions.SimpleJtwigFunction;
20+
import com.mitchellbosecke.pebble.extension.Function;
21+
import com.mitchellbosecke.pebble.template.EvaluationContext;
22+
import com.mitchellbosecke.pebble.template.PebbleTemplate;
23+
import java.util.Collections;
24+
import java.util.List;
25+
import java.util.Map;
2226

23-
public class DateTimeFunction extends SimpleJtwigFunction {
27+
public class DateTimeFunction implements Function {
28+
public static final String FUNCTION_NAME = "time";
2429

2530
@Override
26-
public String name() {
27-
return "time";
31+
public Object execute(
32+
Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
33+
Long milli = (Long) args.get("milli");
34+
return DateTimeUtils.formatMilliToString(milli);
2835
}
2936

3037
@Override
31-
public Object execute(FunctionRequest request) {
32-
Long milli = (Long) request.getArguments().get(0);
33-
return DateTimeUtils.formatMilliToString(milli);
38+
public List<String> getArgumentNames() {
39+
return Collections.singletonList("milli");
3440
}
3541
}

0 commit comments

Comments
 (0)