-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
Feature/550 queue splitter
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"queue-static-split": { | ||
"description": "Simple static splitter", | ||
"postfixFromStatic": [ | ||
"A", | ||
"B", | ||
"C", | ||
"D" | ||
] | ||
}, | ||
"queue-header-[a-z]+": { | ||
"description": "Simple splitter with request header", | ||
"postfixDelimiter": "+", | ||
"postfixFromRequest": { | ||
"header": "x-rp-deviceid" | ||
} | ||
}, | ||
"queue-path-[a-z]+": { | ||
"description": "Simple splitter with request url matching", | ||
"postfixDelimiter": "_", | ||
"postfixFromRequest": { | ||
"url": ".*/path1/(.*)/.*" | ||
} | ||
}, | ||
"queue-header-and-path-[a-z]+": { | ||
"description": "Simple splitter with request header and url matching", | ||
"postfixDelimiter": "_", | ||
"postfixFromRequest": { | ||
"header": "x-rp-deviceid", | ||
"url": ".*/path1/(.*)/.*" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.swisspush.gateleen.queue.queuing.splitter; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.Promise; | ||
import io.vertx.core.http.HttpServerRequest; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public class NoOpQueueSplitter implements QueueSplitter { | ||
|
||
@Override | ||
public Future<Void> initialize() { | ||
Promise<Void> promise = Promise.promise(); | ||
promise.complete(); | ||
return promise.future(); | ||
} | ||
|
||
@Override | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public String convertToSubQueue(String queue, HttpServerRequest request) { | ||
return queue; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.swisspush.gateleen.queue.queuing.splitter; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.http.HttpServerRequest; | ||
|
||
/** | ||
* Interface for queues configured to be split in sub-queues. The method {@link QueueSplitter#convertToSubQueue(String, HttpServerRequest)} | ||
* evaluates the convert of the queue name in a sub-queue name. | ||
* | ||
* @author https://github.com/gcastaldi [Giannandrea Castaldi] | ||
*/ | ||
public interface QueueSplitter { | ||
|
||
public Future<Void> initialize(); | ||
|
||
/** | ||
* Convert the queue name in a sub-queue name. If not necessary maintains the initial queue name. | ||
* | ||
* @param queue | ||
* @param request | ||
* @return sub-queue name | ||
*/ | ||
String convertToSubQueue(String queue, HttpServerRequest request); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.swisspush.gateleen.queue.queuing.splitter; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Container holding configuration values for {@link QueueSplitterImpl} identified | ||
* by a queue pattern. | ||
* | ||
* @author https://github.com/gcastaldi [Giannandrea Castaldi] | ||
*/ | ||
public class QueueSplitterConfiguration { | ||
|
||
private final Pattern queue; | ||
|
||
private final String postfixDelimiter; | ||
|
||
@Nullable | ||
private final List<String> postfixFromStatic; | ||
|
||
@Nullable | ||
private final String postfixFromHeader; | ||
|
||
@Nullable | ||
private final Pattern postfixFromUrl; | ||
|
||
|
||
public QueueSplitterConfiguration( | ||
Pattern queue, | ||
String postfixDelimiter, | ||
@Nullable List<String> postfixFromStatic, | ||
@Nullable String postfixFromHeader, | ||
@Nullable Pattern postfixFromUrl) { | ||
this.queue = queue; | ||
this.postfixDelimiter = postfixDelimiter; | ||
this.postfixFromStatic = postfixFromStatic; | ||
this.postfixFromHeader = postfixFromHeader; | ||
this.postfixFromUrl = postfixFromUrl; | ||
} | ||
|
||
public Pattern getQueue() { | ||
return queue; | ||
} | ||
|
||
public String getPostfixDelimiter() { | ||
return postfixDelimiter; | ||
} | ||
|
||
@Nullable | ||
public List<String> getPostfixFromStatic() { | ||
return postfixFromStatic; | ||
} | ||
|
||
@Nullable | ||
public String getPostfixFromHeader() { | ||
return postfixFromHeader; | ||
} | ||
|
||
@Nullable | ||
public Pattern getPostfixFromUrl() { | ||
return postfixFromUrl; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
QueueSplitterConfiguration that = (QueueSplitterConfiguration) o; | ||
Check warning on line 70 in gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterConfiguration.java Codecov / codecov/patchgateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterConfiguration.java#L70
|
||
return Objects.equals(queue, that.queue) && | ||
Objects.equals(postfixDelimiter, that.postfixDelimiter) && | ||
Objects.equals(postfixFromStatic, that.postfixFromStatic) && | ||
Objects.equals(postfixFromHeader, that.postfixFromHeader) && | ||
Objects.equals(postfixFromUrl, that.postfixFromUrl); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(queue, postfixDelimiter, postfixFromStatic, postfixFromHeader, postfixFromUrl); | ||
Check warning on line 80 in gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterConfiguration.java Codecov / codecov/patchgateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterConfiguration.java#L80
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "QueueSplitterConfiguration{" + | ||
Check warning on line 85 in gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterConfiguration.java Codecov / codecov/patchgateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterConfiguration.java#L85
|
||
"queue=" + queue + | ||
", postfixDelimiter='" + postfixDelimiter + '\'' + | ||
", postfixFromStatic=" + postfixFromStatic + | ||
", postfixFromHeader='" + postfixFromHeader + '\'' + | ||
", postfixFromUrl='" + postfixFromUrl + '\'' + | ||
'}'; | ||
} | ||
|
||
public boolean isSplitStatic() { | ||
return postfixFromStatic != null && !postfixFromStatic.isEmpty(); | ||
} | ||
|
||
public boolean isSplitFromRequest() { | ||
return postfixFromHeader != null || postfixFromUrl != null; | ||
} | ||
} |