Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-16971

MongoDb3 component always connects to localhost

    XMLWordPrintable

Details

    • Bug
    • Status: Done
    • Minor
    • Resolution: Done
    • fuse-7.8-GA
    • fuse-7.10-GA
    • Spring Boot
    • None
    • False
    • False
    • % %
    • Todo
    • Undefined
    • Hide

      Prerequisites

      • No mongo server on localhost 
      • A reachable mongo server instance 

       

      Steps

      1. Create a fuse spring boot project 

      export FUSE_ARCHETYPE_VERSION=2.2.0.fuse-sb2-780040-redhat-00002
      
      mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \   -DarchetypeCatalog=https://maven.repository.redhat.com/ga/io/fabric8/archetypes/archetypes-catalog/${FUSE_ARCHETYPE_VERSION}/archetypes-catalog-${FUSE_ARCHETYPE_VERSION}-archetype-catalog.xml \   -DarchetypeGroupId=org.jboss.fuse.fis.archetypes \   -DarchetypeArtifactId=spring-boot-camel-archetype \   -DarchetypeVersion=${FUSE_ARCHETYPE_VERSION}
      

      2. Add maven dependency

       

              <dependency>
                  <groupId>org.apache.camel</groupId>
                  <artifactId>camel-mongodb3-starter</artifactId>
              </dependency>
      

       

      3. Define a mongoClient

      @Bean 
      public MongoClient mongoClient(){ 
            return new MongoClient(new MongoClientURI("mongodb://admin:password@192.168.99.102:32553"));  
      }
      

       

      4. Change route to perform an insert operation on mongo

      @Override
          public void configure() throws Exception {
              from("timer://foo?period=5000")
                  .setBody().constant("{\"val\": \"foobar\"}")
                  .to("mongodb3:mongoClient?database=test&collection=sampleCollection&operation=insert");
          }
      

       

       

      Unexpected Result

      12:01:12.644 [main] INFO  c.redhat.saiello.fusemongo.Application - Started Application in 6.461 seconds (JVM running for 8.69)12:01:12.644 [main] INFO  c.redhat.saiello.fusemongo.Application - Started Application in 6.461 seconds (JVM running for 8.69)12:01:12.811 [cluster-ClusterId{value='60e6cce7665549478a7f2fbe', description='null'}-localhost:27017] INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) at java.lang.Thread.run(Thread.java:748)Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:607) at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ... 3 common frames omitted12:01:13.780 [Camel (MyCamel) thread #1 - timer://foo] INFO  org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:6}] to 192.168.99.102:32553
      
      Show
      Prerequisites No mongo server on localhost  A reachable mongo server instance    Steps 1. Create a fuse spring boot project  export FUSE_ARCHETYPE_VERSION=2.2.0.fuse-sb2-780040-redhat-00002 mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \   -DarchetypeCatalog=https: //maven.repository.redhat.com/ga/io/fabric8/archetypes/archetypes-catalog/${FUSE_ARCHETYPE_VERSION}/archetypes-catalog-${FUSE_ARCHETYPE_VERSION}-archetype-catalog.xml \   -DarchetypeGroupId=org.jboss.fuse.fis.archetypes \   -DarchetypeArtifactId=spring-boot-camel-archetype \   -DarchetypeVersion=${FUSE_ARCHETYPE_VERSION} 2. Add maven dependency           <dependency>             <groupId> org.apache.camel </groupId>             <artifactId> camel-mongodb3-starter </artifactId>         </dependency>   3. Define a mongoClient @Bean public MongoClient mongoClient(){ return new MongoClient( new MongoClientURI( "mongodb: //admin:password@192.168.99.102:32553" )); }   4. Change route to perform an insert operation on mongo @Override public void configure() throws Exception { from( "timer: //foo?period=5000" ) .setBody().constant( "{\" val\ ": \" foobar\ "}" ) .to( "mongodb3:mongoClient?database=test&collection=sampleCollection&operation=insert" ); }     Unexpected Result 12:01:12.644 [main] INFO  c.redhat.saiello.fusemongo.Application - Started Application in 6.461 seconds (JVM running for 8.69)12:01:12.644 [main] INFO  c.redhat.saiello.fusemongo.Application - Started Application in 6.461 seconds (JVM running for 8.69)12:01:12.811 [cluster-ClusterId{value= '60e6cce7665549478a7f2fbe' , description= ' null ' }-localhost:27017] INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) at java.lang. Thread .run( Thread .java:748)Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:607) at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ... 3 common frames omitted12:01:13.780 [Camel (MyCamel) thread #1 - timer: //foo] INFO  org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:6}] to 192.168.99.102:32553

    Description

      Although the mongoClient uri has a different value, a connection to localhost: 27017 is always opened.

      Attachments

        Issue Links

          Activity

            People

              rnetuka@redhat.com Radovan Netuka
              saiello@redhat.com Simone Aiello
              Tomas Veskrna Tomas Veskrna
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: