[ 
https://issues.apache.org/jira/browse/CAMEL-21735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17925954#comment-17925954
 ] 

Luis Sergio Faria Carneiro commented on CAMEL-21735:
----------------------------------------------------

Yes, the extension creates a default Mongo client which is injected into the 
component. What made me open this issue in the core project is the 
doStart/resolveMongoConnection methods at the 
[MongoDbEndpoint|https://github.com/apache/camel/blob/main/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java#L422]
 class.

In those methods, if any connection is autowired into the component, it takes 
precedence over the parameters defined at the endpoint level.

There's also the *connectionBean* path parameter, which has a lower precedence 
over the hosts configuration, per the 
[docs.|https://camel.apache.org/components/4.8.x/mongodb-component.html#_endpoint_path_option_connectionBean]

So at the end connections can be defined in three ways:
 # autowiring a MongoDBClient;
 # defining a bean and referencing it with the connectionBean path parameter;
 # defining connection data with the hosts and other endpoint parameters;

#3 takes precedence over #2, but not over #1.

It that's expected, we can close this as Not a bug.

 

> MongoDB component connecting to localhost event if connection data is set
> -------------------------------------------------------------------------
>
>                 Key: CAMEL-21735
>                 URL: https://issues.apache.org/jira/browse/CAMEL-21735
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-mongodb
>    Affects Versions: 4.8.0
>            Reporter: Luis Sergio Faria Carneiro
>            Priority: Major
>
> I'm trying to use the MongoDB component within a Camel K integration. And the 
> code is as following:
> {code:java}
> - to:              
>     uri: mongodb:dummy              
>     parameters:                
>       operation: findAll                
>       collection: environment                
>       database: environments                
>       username: someuser                
>       password: somepass
>       hosts: somehost:27017{code}
> Although the connection parameters are set, I see component trying to connect 
> to 127.0.0.1:27017.
> Debugging the source code and checking the log, I see the component is using 
> an autowired client which is configured to localhost instead of creating a 
> new client from my parameters. 
> I haven't configured any beans.
> But anyways, shoudn't the endpoint parameters take precedence over any 
> pre-configured bean which I'm not even aware of?
>  
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to