Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added example for new addServicesOnStartup method

...

Code Block
xml
xml
    <route>
      <from uri="direct:start"/>
      <to uri="bean:org.apache.camel.test.blueprint.MyService"/>
      <to uri="mock:result"/>
    </route>

 

From Camel 2.16.0, an additional addServicesOnStartup method is available to be overridden making it ideal for when needing to specify multiple services with the same interface. 

Code Block
languagejava
  @Override
  protected void addServicesOnStartup(List<KeyValueHolder<String, KeyValueHolder<Object, Dictionary>>> services) {
      Dictionary<String, String> dict1 = new Hashtable<String, String>();
      dict1.put("osgi.jndi.service.name", "jdbc/db1");
        
      Dictionary<String, String> dict2 = new Hashtable<String, String>();
      dict2.put("osgi.jndi.service.name", "jdbc/db2");
        
      services.add(asKeyValueService(javax.sql.DataSource.class.getName(), mockService1, dict1));
      services.add(asKeyValueService(javax.sql.DataSource.class.getName(), mockService2, dict2));
    }

The asKeyValueService builder method can be used to construct the necessary parameters to create the service. The method takes in the name of the registered service, the object, and and a Dictionary as arguments.