quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.49k stars 2.59k forks source link

Allow for catch-all / wildcard in funqy-knative-binding. #18337

Open pilhuhn opened 3 years ago

pilhuhn commented 3 years ago

Description

Currently either the method name of a @Funq or the trigger value is taken to match the type of an incoming cloud event. Sometimes (especially with the new filtering functionality) it is desirable to match on multiple types (e.g. in some kind of audit scenarios).

It should be allowed to say

    @Funq
    @CloudEventMapping(trigger = "*")
    public Map<String,Object> process(Map<String,Object> in,  @Context CloudEvent eventInfo) {

or

    @Funq
    @CloudEventMapping(trigger = "audit.*")
    public Map<String,Object> process(Map<String,Object> in,  @Context CloudEvent eventInfo) {

* (1st example) could be seen as "fallback if no better match"

In then 2nd example it could be determined if regex-match is desired or not.

Implementation ideas

https://github.com/quarkusio/quarkus/blob/main/extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/VertxRequestHandler.java#L162 could get a retry logic a la

   if (candidates == null  ) { // as is
       if (typeTriggers.get("*") != null ) {
           candidates.add(typeTriggers.get("*");
       } else {
             // continue to bail out as before
quarkus-bot[bot] commented 3 years ago

/cc @geoand, @matejvasek, @patriot1burke

patriot1burke commented 3 years ago

Catch-all ability would be great.

pilhuhn commented 3 years ago

This works in 1.13.7: and allows @CloudEventMapping(trigger = "*")

Index: extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/VertxRequestHandler.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>x-MacRoman
===================================================================
diff --git a/extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/VertxRequestHandler.java b/extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/VertxRequestHandler.java
--- a/extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/VertxRequestHandler.java (revision 7bdb007f650a604f589eb44264b4df4800f697c0)
+++ b/extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/VertxRequestHandler.java (date 1625492068660)
@@ -149,7 +149,11 @@
                 if (defaultInvoker != null) {
                     invoker = defaultInvoker;
                 } else {
-                    invoker = typeTriggers.get(ceType);
+                    if (typeTriggers.get(ceType) != null) {
+                        invoker = typeTriggers.get(ceType);
+                    } else {
+                        invoker = typeTriggers.get("*"); // Catch all
+                    }
                     if (invoker == null) {
                         routingContext.fail(404);
                         log.error("Couldn't map CloudEvent type: '" + ceType + "' to a function.");
matejvasek commented 2 years ago

@patriot1burke I think this should be closed.