TheNetherWatcher commented on code in PR #6913:
URL: https://github.com/apache/camel-k/pull/6913#discussion_r4547888460


##########
pkg/trait/keda/scalers/spring_rabbitmq.go:
##########
@@ -0,0 +1,137 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package scalers
+
+import (
+       "net"
+       "net/url"
+       "strings"
+
+       keda "github.com/apache/camel-k/v2/pkg/trait/keda"
+)
+
+const (
+       springRabbitMQConnectionFactoryProp = 
"camel.component.spring-rabbitmq.connection-factory"
+       camelBeansPrefix                    = "camel.beans."
+       rabbitMQDefaultPort                 = "5672"
+)
+
+// SpringRabbitMQScaler maps Camel Spring RabbitMQ consumer endpoints to the 
KEDA rabbitmq scaler.
+type SpringRabbitMQScaler struct{}
+
+func init() {
+       keda.Register(&SpringRabbitMQScaler{})
+}
+
+func (s *SpringRabbitMQScaler) Component() string {
+       return "spring-rabbitmq"
+}
+
+// Map takes the queue from the `queues` parameter. The URI path is the 
exchange name, which the
+// scaler does not use. The broker address is read from the connection factory 
bean when it is
+// declared with camel.beans properties; credentials are left to a 
TriggerAuthentication.
+func (s *SpringRabbitMQScaler) Map(pathValue string, params map[string]string, 
props map[string]string) (string, map[string]string) {
+       metadata := make(map[string]string)
+       // A KEDA rabbitmq trigger watches a single queue, so a list of queues 
is left for the user to choose.
+       if v, ok := params["queues"]; ok && v != "" && !strings.Contains(v, 
",") {
+               metadata["queueName"] = v
+       }
+       if host := springRabbitMQHost(params, props); host != "" {

Review Comment:
   Done in c437716: a `host` endpoint parameter is now used as is, and the 
broker address is only worked out from the connection factory bean when it's 
missing. Added a unit test for that and updated the trait docs.
   
   _Claude Code on behalf of @TheNetherWatcher_



##########
e2e/keda/files/keda-it-spring-rabbitmq-to-log-auto.yaml:
##########
@@ -0,0 +1,55 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+
+# Spring RabbitMQ trigger is auto-discovered from the consumer URI (queueName 
comes from `queues`).
+# The broker address is not part of the URI, so host, mode and value are 
merged via autoMetadata.
+
+apiVersion: camel.apache.org/v1
+kind: Integration
+metadata:
+  name: keda-it-spring-rabbitmq-to-log-auto
+spec:
+  flows:
+  - beans:
+    - name: rabbitConnectionFactory
+      type: org.springframework.amqp.rabbit.connection.CachingConnectionFactory
+      properties:
+        host: my-rabbitmq.%%%.svc
+        port: 5672
+        username: admin
+        password: admin
+  - route:
+      from:
+        uri: spring-rabbitmq:my-exchange?queues=my-queue&routingKey=my-key
+        steps:
+        - to: log:info
+  traits:
+    camel:
+      properties:
+        - 
camel.component.spring-rabbitmq.connection-factory=#rabbitConnectionFactory
+    keda:
+      enabled: true
+      minReplicaCount: 0
+      maxReplicaCount: 1
+      cooldownPeriod: 20
+      pollingInterval: 10
+      autoMetadata:

Review Comment:
   `host` is still needed here, but only for the credentials. The discovered 
address is `amqp://my-rabbitmq.<ns>.svc:5672/` without a user, because 
credentials are never copied out of the bean. The default RabbitMQ `guest` user 
can only connect from localhost, and auto-discovered triggers can't carry a 
`TriggerAuthentication` (`secrets` only applies to manual `triggers`), so the 
override is how the test gives KEDA the credentials. `mode` and `value` aren't 
strictly required (KEDA falls back to a default queue length), but `value: 5` 
keeps the scale-up quick and predictable in the test.
   
   If you'd prefer the test to also prove discovery, I can add a check on the 
generated ScaledObject before the override, or add secrets support for 
auto-discovered triggers in a follow-up.
   
   _Claude Code on behalf of @TheNetherWatcher_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to