Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access MongoDB #2684

Closed
bthj opened this issue Oct 8, 2021 · 25 comments
Closed

Unable to access MongoDB #2684

bthj opened this issue Oct 8, 2021 · 25 comments

Comments

@bthj
Copy link

bthj commented Oct 8, 2021

When trying to access a MongoDB Atlas Free Tier Cluster with a Camel-K integration Java file like:

// camel-k: language=java
// camel-k: dependency=camel:mongodb
// camel-k: dependency=camel:jackson
// camel-k: dependency=mvn:org.mongodb:mongo-java-driver:3.12.10

import org.apache.camel.builder.RouteBuilder;

public class MongoDBTest extends RouteBuilder {
  @Override
  public void configure() throws Exception {
      from("timer:java?period=1000")
        .routeId("java")
        .to("mongodb:mongoBean?hosts=[shard1].mongodb.net:27017,[shard2].mongodb.net:27017,[shard3].mongodb.net:27017&username=[user]&password=[pass]&database=[dbname]&collection=[collection-name]&operation=getDbStats")
        .to("log:info");
  }
}

and deploy it with Camel K Client 1.6.0 to a camel-k-operator.v1.6.0 with the command: kamel run MongoDBTest.java --dev it results in the error:

Error processing exchange. Exchange[F6C144558CE94DA-000000000000000B]. Caused by: [org.apache.camel.component.mongodb.CamelMongoDbException - com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]]: org.apache.camel.component.mongodb.CamelMongoDbException: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
[3]     at org.apache.camel.component.mongodb.MongoDbComponent.wrapInCamelMongoDbException(MongoDbComponent.java:84)
  • it seems to be trying to connect to 127.0.0.1:27017 - is there something I should add to have the integration communicate with the correct hosts?
@lburgazzoli
Copy link
Contributor

/cc @squakez

@bthj
Copy link
Author

bthj commented Oct 8, 2021

I tried to use .bean, like so:

.bean(MongoDbComponent.class, "createEndpoint(String 'hosts=[shard1].mongodb.net:27017,[shard2].mongodb.net:27017,[shard3].mongodb.net:27017&username=[user]&password=[pass]&database=[db]&collection=[coll]&operation=getDbStats')")

but that throws:

org.apache.camel.component.bean.AmbiguousMethodCallException: Ambiguous method invocations possible: [protected org.apache.camel.Endpoint org.apache.camel.component.mongodb.MongoDbComponent.createEndpoint(java.lang.String,java.lang.String,java.util.Map) throws java.lang.Exception] on the exchange: Exchange[]

while I thought I was eliminating ambiguity by using the type qualifier String to select among the overloaded methods.

@heiko-braun
Copy link

IIRC there is a problem with the way quarkus initializes the mongodb client. I don’t recall the full context, but in the kamelet we had to provide a custom bean I think to override the quarkus defaults: https://github.com/apache/camel-kamelets/blob/790b6b93975a3d73fb6f8d2396c7aca72ef50766/mongodb-source.kamelet.yaml#L69

@heiko-braun
Copy link

Btw, i believe you can reference the mongo sink and source kamelets directly from your route

@bthj
Copy link
Author

bthj commented Oct 8, 2021

I tried the sink kamelet and it's pod logs also show the same error, on not being able to connect to 127.0.0.1:27017:

Exception in monitor thread while connecting to server 127.0.0.1:27017: com.mongodb.MongoSocketOpenException: Exception opening socket

when deployed from a declaration like:

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
  name: mongodb-sink-binding
spec:
  source:
    ref:
      kind: Channel
      apiVersion: messaging.knative.dev/v1
      name: isgattchannel
  sink:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1alpha1
      name: mongodb-sink
    properties:
      collection: "collection-name"
      database: "dbname"
      hosts: "[shard1].mongodb.net:27017,[shard2]:27017,[shard3].mongodb.net:27017"
      createCollection: true
      password: "pass"
      username: "user"

@oscerd
Copy link
Contributor

oscerd commented Oct 8, 2021

Well this seems weird. I tested the sink and source Kamelets multiple times and never faced this

@bthj
Copy link
Author

bthj commented Oct 8, 2021

It is indeed weird (I've been fighting this for two days).

Ignoring the kamelets for now, if I reference the bean @heiko-braun mentioned in properties, like:

camel.beans.mongoBean = #class:org.apache.camel.component.mongodb.MongoDbComponent

then there is still the 127.0.0.1:27017 error, when referencing it on a route like:

.to("mongodb:mongoBean?hosts=[shard1].mongodb.net:27017,[shard2].mongodb.net:27017,[shard3].mongodb.net:27017&username=[user]&password=[pass]&database=[dbname]&collection=[collection-name]&operation=getDbStats")

@bthj
Copy link
Author

bthj commented Oct 8, 2021

The MongoClient does seem to have been refactored, and it seems I should be referencing com.mongodb.client.MongoClient instead of com.mongodb.MongoClient, where the former is an interface. So probably I should configure a singleton bean by its type, like so?:

camel.beans.mongoBean = #type:com.mongodb.client.MongoClient

But how to add an instance of that type to the Camel context? - there is the factory-like method com.mongodb.client.MongoClients.create(String connectionString) - I say "-like" because it doesn't return it's own type, but rather com.mongodb.client.MongoClient (singular), so placing this in properties doesn't work:

camel.beans.mongoClient = #class:com.mongodb.client.MongoClients#create("...connection string...")
  • How can I combine the output of #class:com.mongodb.client.MongoClients#create with #type:com.mongodb.client.MongoClient ?
    ...or how could I utilise the custom bean mentioned?

@oscerd
Copy link
Contributor

oscerd commented Oct 8, 2021

With the kamelets, you'll get some complaints before the correct connection will be done

2021-10-08 19:08:39,308 WARN  [io.qua.net.run.NettyRecorder] (Thread-0) Netty DefaultChannelId initialization (with io.netty.machineId system property set to 6b:d5:f4:43:a6:d8:c4:47) took more than a second
2021-10-08 19:08:41,106 INFO  [org.mon.dri.cluster] (main) Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-10-08 19:08:42,019 INFO  [org.mon.dri.cluster] (main) Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-10-08 19:08:42,710 INFO  [org.mon.dri.cluster] (cluster-ClusterId{value='61609738311ec2632f641801', description='null'}-127.0.0.1:27017) Exception in monitor thread while connecting to server 127.0.0.1:27017: com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:165)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:195)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:151)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.base/java.net.Socket.connect(Socket.java:609)
	at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:107)
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
	... 4 more

2021-10-08 19:08:43,009 INFO  [org.mon.dri.cluster] (cluster-ClusterId{value='6160973a311ec2632f641802', description='null'}-127.0.0.1:27017) Exception in monitor thread while connecting to server 127.0.0.1:27017: com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.internal.connection.AsynchronousSocketChannelStream$OpenCompletionHandler.failed(AsynchronousSocketChannelStream.java:124)
	at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:129)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:283)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213)
	at java.base/sun.nio.ch.EPollPort$EventHandlerTask.run(EPollPort.java:306)
	at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:252)
	... 7 more

But after that you'll get the correct connection, this is something related to underlined quarkus extension

2021-10-08 19:08:54,308 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) StreamCaching is enabled on CamelContext: camel-k-runtime-examples-yaml
2021-10-08 19:08:54,609 INFO  [org.mon.dri.cluster] (main) Cluster created with settings {hosts=[172.17.0.3:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-10-08 19:08:54,907 INFO  [org.apa.cam.com.mon.MongoDbEndpoint] (main) Initialising MongoDb endpoint: local-mongodb-1://test?collection=log&createCollection=false&database=test&hosts=172.17.0.3&operation=insert&password=xxxxxx&username=mongoadmin
2021-10-08 19:08:55,415 INFO  [org.mon.dri.cluster] (main) Cluster description not yet available. Waiting for 30000 ms before timing out
2021-10-08 19:08:55,613 INFO  [org.mon.dri.connection] (cluster-ClusterId{value='61609746311ec2632f641803', description='null'}-172.17.0.3:27017) Opened connection [connectionId{localValue:9, serverValue:2}] to 172.17.0.3:27017
2021-10-08 19:08:55,613 INFO  [org.mon.dri.connection] (cluster-rtt-ClusterId{value='61609746311ec2632f641803', description='null'}-172.17.0.3:27017) Opened connection [connectionId{localValue:10, serverValue:3}] to 172.17.0.3:27017
2021-10-08 19:08:55,615 INFO  [org.mon.dri.cluster] (cluster-ClusterId{value='61609746311ec2632f641803', description='null'}-172.17.0.3:27017) Monitor thread successfully connected to server with description ServerDescription{address=172.17.0.3:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=804429642}
2021-10-08 19:09:00,107 INFO  [org.mon.dri.connection] (main) Opened connection [connectionId{localValue:11, serverValue:4}] to 172.17.0.3:27017

I set 172.17.0.3 on the kameletBinding.

It's just logging, but the feature works and I think it is the same for the component.

@bthj
Copy link
Author

bthj commented Oct 8, 2021

Regarding the MongoDB sink kamelet, I tried again deploying the k8s declaration listed above, to grab the full logs which I'll paste in here in case the provide any insights:

exec java -cp ./resources:/etc/camel/application.properties:/etc/camel/conf.d/_resources:/etc/camel/conf.d/user.properties:/etc/camel/resources:/etc/camel/sources/camel-k-embedded-flow.yaml:/etc/camel/sources/mongodb-sink.yaml:dependencies/app/camel-k-integration-1.6.0.jar:dependencies/lib/boot/io.quarkus.quarkus-bootstrap-runner-2.2.0.Final.jar:dependencies/lib/boot/io.quarkus.quarkus-development-mode-spi-2.2.0.Final.jar:dependencies/lib/boot/io.smallrye.common.smallrye-common-io-1.6.0.jar:dependencies/lib/boot/org.glassfish.jakarta.json-1.1.6.jar:dependencies/lib/boot/org.graalvm.sdk.graal-sdk-21.2.0.jar:dependencies/lib/boot/org.jboss.logging.jboss-logging-3.4.2.Final.jar:dependencies/lib/boot/org.jboss.logmanager.jboss-logmanager-embedded-1.0.9.jar:dependencies/lib/boot/org.wildfly.common.wildfly-common-1.5.4.Final-format-001.jar:dependencies/lib/main/com.fasterxml.jackson.core.jackson-annotations-2.12.4.jar:dependencies/lib/main/com.fasterxml.jackson.core.jackson-core-2.12.4.jar:dependencies/lib/main/...
�[38;5;145m2021-10-08 19:07:56,131�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.mon.dri.cluster�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mCluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}�[39m�[38;5;203m�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,171�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.mon.dri.cluster�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mCluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}�[39m�[38;5;203m�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,220�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.mon.dri.cluster�[39m�[38;5;188m] (�[39m�[38;5;71mcluster-ClusterId{value='6160970c21ccfd22aca10618', description='null'}-127.0.0.1:27017�[39m�[38;5;188m) �[39m�[38;5;151mException in monitor thread while connecting to server 127.0.0.1:27017�[39m�[38;5;203m: com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:165)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:195)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:151)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.base/java.net.Socket.connect(Socket.java:609)
	at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:107)
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
	... 4 more
�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,246�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.mon.dri.cluster�[39m�[38;5;188m] (�[39m�[38;5;71mcluster-ClusterId{value='6160970c21ccfd22aca10619', description='null'}-127.0.0.1:27017�[39m�[38;5;188m) �[39m�[38;5;151mException in monitor thread while connecting to server 127.0.0.1:27017�[39m�[38;5;203m: com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.internal.connection.AsynchronousSocketChannelStream$OpenCompletionHandler.failed(AsynchronousSocketChannelStream.java:124)
	at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:129)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:283)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213)
	at java.base/sun.nio.ch.EPollPort$EventHandlerTask.run(EPollPort.java:306)
	at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:252)
	... 7 more
�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,267�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.apa.cam.k.Runtime�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mApache Camel K Runtime 1.9.0�[39m�[38;5;203m�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,270�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.apa.cam.qua.cor.CamelBootstrapRecorder�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151m�[39mBootstrap runtime: �[38;5;188morg.apache.camel.quarkus.main.CamelMainRuntime�[39m�[39m�[38;5;203m�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,353�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.apa.cam.k.lis.SourcesConfigurer�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mLoading routes from: SourceDefinition{name='camel-k-embedded-flow', language='yaml', type='source', location='file:/etc/camel/sources/camel-k-embedded-flow.yaml', }�[39m�[38;5;203m�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,409�[39m�[38;5;188m �[39m�[38;5;107mINFO �[39m�[38;5;188m [�[39m�[38;5;69morg.apa.cam.k.lis.SourcesConfigurer�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mLoading routes from: SourceDefinition{name='mongodb-sink', language='yaml', type='source', location='file:/etc/camel/sources/mongodb-sink.yaml', }�[39m�[38;5;203m�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,538�[39m�[38;5;188m �[39m�[38;5;203mERROR�[39m�[38;5;188m [�[39m�[38;5;69morg.apa.cam.qua.mai.CamelMainRuntime�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mFailed to start application�[39m�[38;5;203m: org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[knative:channel/isgattchannel?apiVersion=... because of Failed to resolve endpoint: knative://channel/isgattchannel?apiVersion=messaging.knative.dev%2Fv1&kind=Channel due to: Cannot load Knative configuration from file or env variable
	at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:80)
	at org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49)
	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:826)
	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:716)
	at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2757)
	at org.apache.camel.quarkus.core.FastCamelContext.doInit(FastCamelContext.java:165)
	at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
	at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2475)
	at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
	at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2494)
	at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:245)
	at org.apache.camel.quarkus.main.CamelMain.doStart(CamelMain.java:94)
	at org.apache.camel.support.service.BaseService.start(BaseService.java:119)
	at org.apache.camel.quarkus.main.CamelMain.startEngine(CamelMain.java:139)
	at org.apache.camel.quarkus.main.CamelMainRuntime.start(CamelMainRuntime.java:49)
	at org.apache.camel.quarkus.core.CamelBootstrapRecorder.start(CamelBootstrapRecorder.java:45)
	at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy_0(CamelBootstrapProcessor$boot-173480958.zig:101)
	at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy(CamelBootstrapProcessor$boot-173480958.zig:40)
	at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:843)
	at io.quarkus.runtime.Application.start(Application.java:101)
	at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
	at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:48)
	at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:25)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: knative://channel/isgattchannel?apiVersion=messaging.knative.dev%2Fv1&kind=Channel due to: Cannot load Knative configuration from file or env variable
	at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:962)
	at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:844)
	at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:58)
	at org.apache.camel.reifier.AbstractReifier.resolveEndpoint(AbstractReifier.java:177)
	at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:94)
	at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:74)
	... 30 more
Caused by: java.lang.IllegalStateException: Cannot load Knative configuration from file or env variable
	at org.apache.camel.component.knative.KnativeComponent.getKnativeConfiguration(KnativeComponent.java:278)
	at org.apache.camel.component.knative.KnativeComponent.createEndpoint(KnativeComponent.java:226)
	at org.apache.camel.support.DefaultComponent.createEndpoint(DefaultComponent.java:171)
	at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:928)
	... 35 more
�[39m�[38;5;227m
�[39m�[38;5;145m2021-10-08 19:07:56,574�[39m�[38;5;188m �[39m�[38;5;203mERROR�[39m�[38;5;188m [�[39m�[38;5;69mio.qua.run.Application�[39m�[38;5;188m] (�[39m�[38;5;71mmain�[39m�[38;5;188m) �[39m�[38;5;151mFailed to start application (with profile prod)�[39m�[38;5;203m: java.lang.IllegalStateException: Cannot load Knative configuration from file or env variable
	at org.apache.camel.component.knative.KnativeComponent.getKnativeConfiguration(KnativeComponent.java:278)
	at org.apache.camel.component.knative.KnativeComponent.createEndpoint(KnativeComponent.java:226)
	at org.apache.camel.support.DefaultComponent.createEndpoint(DefaultComponent.java:171)
	at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:928)
	at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:844)
	at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:58)
	at org.apache.camel.reifier.AbstractReifier.resolveEndpoint(AbstractReifier.java:177)
	at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:94)
	at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:74)
	at org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49)
	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:826)
	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:716)
	at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2757)
	at org.apache.camel.quarkus.core.FastCamelContext.doInit(FastCamelContext.java:165)
	at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
	at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2475)
	at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
	at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2494)
	at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:245)
	at org.apache.camel.quarkus.main.CamelMain.doStart(CamelMain.java:94)
	at org.apache.camel.support.service.BaseService.start(BaseService.java:119)
	at org.apache.camel.quarkus.main.CamelMain.startEngine(CamelMain.java:139)
	at org.apache.camel.quarkus.main.CamelMainRuntime.start(CamelMainRuntime.java:49)
	at org.apache.camel.quarkus.core.CamelBootstrapRecorder.start(CamelBootstrapRecorder.java:45)
	at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy_0(CamelBootstrapProcessor$boot-173480958.zig:101)
	at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy(CamelBootstrapProcessor$boot-173480958.zig:40)
	at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:843)
	at io.quarkus.runtime.Application.start(Application.java:101)
	at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
	at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:48)
	at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:25)
�[39m�[38;5;227m
�[39m
  • somewhere in there you'll see a reference to hosts=[127.0.0.1:27017] even though I've declared spec.sink.properties.hosts: "[shard1].mongodb.net:27017,[shard2]:27017,[shard3].mongodb.net:27017".

@bthj
Copy link
Author

bthj commented Oct 8, 2021

With the kamelets, you'll get some complaints before the correct connection will be done
....
But after that you'll get the correct connection, this is something related to underlined quarkus extension

On my end it's just stuck in "CrashLoopBackOff".

Does my deployment declaration above look OK ?

@bthj
Copy link
Author

bthj commented Oct 8, 2021

How does it work for you to run this integration?

// camel-k: language=java
// camel-k: dependency=camel:mongodb
// camel-k: dependency=camel:jackson
// camel-k: dependency=mvn:org.mongodb:mongo-java-driver:3.12.10

import org.apache.camel.builder.RouteBuilder;

public class MongoDBTest extends RouteBuilder {
  @Override
  public void configure() throws Exception {
      from("timer:java?period=1000")
        .routeId("java")
        .to("mongodb:mongoBean?hosts=[host1:port,host2:port,host3:port]&username=[user]&password=[pass]&database=[dbname]&collection=[collection-name]&operation=getDbStats")
        .to("log:info");
  }
}
  • do you need further configuration, like in properties?

@bthj
Copy link
Author

bthj commented Oct 8, 2021

I should add that this works fine:

public class MongoDBTest extends RouteBuilder {
  @Override
  public void configure() throws Exception {

    com.mongodb.client.MongoClient mongoClient = com.mongodb.client.MongoClients.create("...connection string...");
    String firstCollectionName = mongoClient.getDatabase("[myDb]").listCollectionNames().first();
    System.out.println("----------firstCollectionName:"+firstCollectionName);
  • deployed in the same way as a Camel-K integration it correctly prints:
----------firstCollectionName:myFirstCollection

@oscerd
Copy link
Contributor

oscerd commented Oct 8, 2021

My test was using this

https://github.com/apache/camel-performance-tests/tree/main/profiling/kafka-mongo

Which it is using Kamelets in the route definition.

Btw I'll try to test on minikube to check

@bthj
Copy link
Author

bthj commented Oct 8, 2021

I'm using the Red Hat OpenShift Container Platform (CodeReady containers, locally on my workstation), and I'm connecting to a MongoDB Atlas cluster (where I've confirmed that the connection string works).

@bthj
Copy link
Author

bthj commented Oct 8, 2021

I could provide in a private message the exact MongoDB Atlas connection string I'm using, which is to a Free Tier Cluster and contains nothing important.

@squakez
Copy link
Contributor

squakez commented Oct 11, 2021

The problem is that in Camel K we support the default Camel Quarkus MongoDB client named camelMongoClient.

This is the one we used internally in Camel K, and, in order to override its default property (which are that 127.0.0.1 you see logged), we must use a property. Your integration will work renaming the route as something like:

        .routeId("java")
        .to("mongodb:camelMongoClient?database=z&collection=z&operation=getDbStats")
        .to("log:info");

And then, executing the Integration with:

kamel run /tmp/MongoDBTest.java --dev -p quarkus.mongodb.connection-string=mongodb://1.2.3.4:27017/

See documentation for more details about how to configure the properties to store the values you need.

@bthj
Copy link
Author

bthj commented Oct 11, 2021

Thanks @squakez, the quarkus.mongodb... properties is what I was missing; I was stuck at
https://camel.apache.org/components/3.12.x/mongodb-component.html
but never reached this document without your help:
https://camel.apache.org/camel-quarkus/latest/reference/extensions/mongodb.html

The kamelets didn't work on my end; does that mean they are also not setting those properties correctly, or did I somehow fail to deploy them correctly? - example above.

@oscerd
Copy link
Contributor

oscerd commented Oct 11, 2021

Kamelets are working. They have been tested for 1.6 by the way I'll try to reproduce. On minikube at least i don't see this

@oscerd
Copy link
Contributor

oscerd commented Oct 12, 2021

I tried again and cannot reproduce on the kamelets side.

@oscerd
Copy link
Contributor

oscerd commented Oct 12, 2021

By the way your kamelet error seems to be related to knative not to mongodb

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: knative://channel/isgattchannel?apiVersion=messaging.knative.dev%2Fv1&kind=Channel due to: Cannot load Knative configuration from file or env variable

@bthj
Copy link
Author

bthj commented Oct 12, 2021

Thanks for checking this out @oscerd. I tried applying the Kubernetes declaration above again and get the same error. spec.source.ref.name: isgattchannel is just arbitrarily set; am I free to use whatever name there?

The Camel-K operator works in the same Red Hat CodeReady Containers cluster, so Knative seems to be working in some aspects there.

@claudio4j
Copy link
Contributor

@bthj This is a slightly different way to connect to mongodb and not using the camel-quarkus property.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale due to 90 days of inactivity.
It will be closed if no further activity occurs within 15 days.
If you think that’s incorrect or the issue should never stale, please simply write any comment.
Thanks for your contributions!

@lucamaf
Copy link

lucamaf commented Apr 21, 2022

I'm experiencing a somehow similar issue.
here is my kamelet binding definition:

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
  name: mongo-to-events
  namespace: poc-workshop
spec:
  sink:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: event-display
      namespace: poc-workshop
  source:
    properties:
      collection: mycollection
      database: mydb
      hosts: 'my-mongo-mongodb.poc-workshop.svc.cluster.local:27017'
      password: M0ng0..
      persistentTailTracking: true
      tailTrackIncreasingField: _id
      username: root
    ref:
      apiVersion: camel.apache.org/v1alpha1
      kind: Kamelet
      name: mongodb-source

and here you can find the error log:
mongo-to-events-85b899f669-689sp-integration.log

I'm on version 1.6.5 of camel-k on OpenShift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants