Skip to content

Commit f51941e

Browse files
Thomas Winterhalder IT132lbovet
Thomas Winterhalder IT132
authored andcommitted
#186 Enqueue directly to destination queue
1 parent 1599e5f commit f51941e

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ target
77
.vertx
88
build
99
.gradle
10-
playground_logs.log
10+
playground_logs.log
11+
**/node/
12+
**/node_modules/
13+
redis

gateleen-hook/src/main/java/org/swisspush/gateleen/hook/HookHandler.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class HookHandler implements LoggableResource {
4545
public static final String HOOK_ROUTES_LISTED = "x-hook-routes-listed";
4646
public static final String HOOKS_LISTENERS_URI_PART = "/_hooks/listeners/";
4747
public static final String LISTENER_QUEUE_PREFIX = "listener-hook";
48+
private static final String X_QUEUE = "x-queue";
4849
private static final String LISTENER_HOOK_TARGET_PATH = "listeners/";
4950

5051
public static final String HOOKS_ROUTE_URI_PART = "/_hooks/route";
@@ -683,7 +684,7 @@ private void callListener(final HttpServerRequest request, final Buffer buffer,
683684
log.debug(" > external target: " + targetUri);
684685
}
685686

686-
String queue = LISTENER_QUEUE_PREFIX + "-" + listener.getListenerId();
687+
String queue = listener.getDestinationQueue();
687688

688689
// Create a new multimap, copied from the original request,
689690
// so that the original request is not overridden with the new values.
@@ -1232,6 +1233,16 @@ private void registerListener(Buffer buffer) {
12321233

12331234
extractAndAddStaticHeadersToHook(jsonHook, hook);
12341235

1236+
Map<String, String> staticHeaders = hook.getStaticHeaders();
1237+
String destinationQueue = null;
1238+
if (staticHeaders != null) {
1239+
// remove static x-queue header. Otherwise it will be re-queued at the end of the queue.
1240+
destinationQueue = hook.getStaticHeaders().remove(X_QUEUE);
1241+
}
1242+
if (destinationQueue == null) {
1243+
destinationQueue = LISTENER_QUEUE_PREFIX + "-" + listenerId;
1244+
}
1245+
12351246
/*
12361247
* Despite the fact, that every hook
12371248
* should have an expiration time,
@@ -1281,7 +1292,7 @@ private void registerListener(Buffer buffer) {
12811292
}
12821293

12831294
// create and add a new listener (or update an already existing listener)
1284-
listenerRepository.addListener(new Listener(listenerId, getMonitoredUrlSegment(requestUrl), target, hook));
1295+
listenerRepository.addListener(new Listener(listenerId, getMonitoredUrlSegment(requestUrl), target, hook, destinationQueue));
12851296
}
12861297

12871298
/**
@@ -1296,7 +1307,7 @@ private void extractAndAddStaticHeadersToHook(final JsonObject jsonHook, final H
12961307
if (staticHeaders != null && staticHeaders.size() > 0) {
12971308
hook.addStaticHeaders(new LinkedHashMap<>());
12981309
for (Map.Entry<String, Object> entry : staticHeaders.getMap().entrySet()) {
1299-
hook.getStaticHeaders().put(entry.getKey(), entry.getValue().toString());
1310+
hook.getStaticHeaders().put(entry.getKey().toLowerCase(), entry.getValue().toString());
13001311
}
13011312
}
13021313
}

gateleen-hook/src/main/java/org/swisspush/gateleen/hook/Listener.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Listener {
1111
private String monitoredUrl;
1212
private Integer expireAfter;
1313
private HttpHook hook;
14+
private String destinationQueue;
1415

1516
/**
1617
* Creates a new instance of a HookListener.
@@ -26,11 +27,12 @@ public class Listener {
2627
* If it's a local listener, this can also be the target url.
2728
* @param hook - the hook of this listener
2829
*/
29-
public Listener(String listenerId, String monitoredUrl, String listener, HttpHook hook) {
30+
public Listener(String listenerId, String monitoredUrl, String listener, HttpHook hook, String destinationQueue) {
3031
this.listenerId = listenerId;
3132
this.monitoredUrl = monitoredUrl;
3233
this.listener = listener;
3334
this.setHook(hook);
35+
this.setDestinationQueue(destinationQueue);
3436
}
3537

3638
/**
@@ -127,4 +129,21 @@ public void setHook(HttpHook hook) {
127129
this.hook = hook;
128130
}
129131

132+
/**
133+
* Returns the destinationQueue of this listener.
134+
*
135+
* @return String
136+
*/
137+
public String getDestinationQueue() {
138+
return destinationQueue;
139+
}
140+
141+
/**
142+
* Sets the destinationQueue for this listener.
143+
*
144+
* @param destinationQueue queue name
145+
*/
146+
public void setDestinationQueue(String destinationQueue) {
147+
this.destinationQueue = destinationQueue;
148+
}
130149
}

0 commit comments

Comments
 (0)