Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding priority queue support to this bundle. #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.qtrouper</groupId>
<artifactId>qtrouper</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>
<packaging>jar</packaging>

<licenses>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/github/qtrouper/Trouper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class Trouper<C extends QueueContext> {
private static final String EXPIRES_AT_TIMESTAMP = "x-expires-timestamp";
private static final String EXPIRES_AT_ENABLED = "x-expires-enabled";
private static final String CONTENT_TYPE = "text/plain";

private static final String PRIORITY = "x-max-priority";
private final QueueConfiguration config;
private final RabbitConnection connection;
private final Class<? extends C> clazz;
Expand Down Expand Up @@ -279,7 +279,11 @@ public void start() {
ensureExchange(exchange);
ensureExchange(dlExchange);
this.publishChannel = connection.newChannel();
connection.ensure(queueName, this.config.getNamespace(), connection.rmqOpts());
Map<String, Object> arguments = new HashMap<>(connection.rmqOpts());
if (this.config.getPriority() != 0) {
arguments.put(PRIORITY, this.config.getPriority());
}
connection.ensure(queueName, this.config.getNamespace(), arguments);
connection.ensure(getRetryQueue(), dlExchange, connection.rmqOpts(exchange, queueName));
connection.ensure(getSidelineQueue(), this.config.getNamespace(), connection.rmqOpts());
if (config.isConsumerEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public class QueueConfiguration {
private RetryConfiguration retry;
@Valid
private SidelineConfiguration sideline;
@Valid
@Min(0)
@Max(255)
private int priority;

@JsonIgnore
public boolean isConsumerEnabled(){
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/io/github/qtrouper/TrouperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,21 @@ public void trouperStartWithAllEncompassingConfig() throws Exception {
Assert.assertEquals(20, trouper.getHandlers().size());
trouper.stop();
}

@Test
public void priorityQueueTest() throws Exception {
val queueConfiguration = QueueConfiguration.builder()
.queueName("p-queue")
.namespace(DEFAULT_NAMESPACE)
.concurrency(10)
.priority(5)
.prefetchCount(10)
.consumerDisabled(false)
.retry(getRetryConfiguration(false, 10))
.sideline(getSidelineConfiguration(true, 10))
.build();
val trouper = getTrouperAfterStart(queueConfiguration);
Assert.assertEquals(5, trouper.getConfig().getPriority());
trouper.stop();
}
}