squakez commented on code in PR #6913: URL: https://github.com/apache/camel-k/pull/6913#discussion_r4505576027
########## 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: With the new implementation, are these properties still required? ########## 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: I think we should let the user provide the "host" in the params. If it is missing, then, we can try to calculate automatically. -- 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]
