You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by jgoggins <jo...@hotmail.com> on 2016/01/29 17:49:09 UTC

Akka, Camel and Spring Boot

Hi all, first time poster here and a first time user of Camel 

I have a working Spring Boot service developed using the example provided
here https://spring.io/guides/gs/producing-web-service/ 

I built a web service from a provided WSDL file. The service needed to
support SOAP12 as shown in the code, this is done. All is working. This can
be started as a service and will work as expected.

With the service working, the jar is provided as a dependent jar to another
application. This application is an akka scala application. The idea is to
use Camel to consume the endpoints of the Spring Boot jar

	@EnableWs
	@Configuration
	public class WebServiceConfig extends WsConfigurerAdapter {
		@Bean
    public ServletRegistrationBean
messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);

        servlet.setMessageFactoryBeanName("soap12");

        return new ServletRegistrationBean(servlet, "/myEvents/*");
    }

    @Bean 
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema
mySchema) {
        DefaultWsdl11Definition wsdl11Definition = new
DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("EventService");
        wsdl11Definition.setLocationUri("/myEvents");
        wsdl11Definition.setTargetNamespace("http://event");
        wsdl11Definition.setSchema(mySchema);

        return wsdl11Definition;
    }
    @Bean
    public XsdSchema mySchema() {
        return new SimpleXsdSchema(new ClassPathResource("mySchema.xsd"));
    }

    @Bean(name = "soap12")
    public SaajSoapMessageFactory soap12MessageFactory() throws
SOAPException {
        SaajSoapMessageFactory factory = new
SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL));
        return factory;
    }  

    // Added to suppport Camel. 
    @Autowired
    CamelContext camelContext;

    @Bean  public CamelEndpointMapping  endpointMapping() { 
        return new CamelEndpointMapping();
    }

    @Bean
    public EndpointAdapter messageEndpointAdapter() {
        return new MessageEndpointAdapter();
    }

}
The following dependencies were added to the maven pom file. 

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.16.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-boot</artifactId>
        <version>2.16.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-ws</artifactId>
        <version>2.16.2</version>
    </dependency>
	
My endpoint remains as it was working (although I never expect this to get
called if the camel route is setup - is that a correct assumption?) 

	@Endpoint 
	public class HeartbeatEndpoint {
		private static final String NAMESPACE_URI = "http://myevent";

		@Action("http://myevent/Heartbeat") 
		@ResponsePayload
		public HeartbeatResponse Heartbeat(@RequestPayload Heartbeat arg) {
			HeartbeatResponse response = new HeartbeatResponse();
			response.setHeartbeatResult(5);
			System.out.println("HEART BEAT");
			return response;
		}
	}

The Scala Camel consumer.

	val camel = CamelExtension(actorSystem).context
	SpringApplication.run(classOf[Application])     // Call the Java Spring
Boot dependent jar file to host the endpoints. 
	actorSystem.actorOf(Props(classOf[CamelService])


          //// I know that I now have 2 CamelContext's created; one in the
actor system and one in the spring boot application.. How is this to be
shared ?????? 

	class CamelService extends Consumer {
	  def endpointUri = "spring-ws:http://localhost:8080/http://event"

	  def receive: Receive = {
		case s @ _ => println("Received " + s)
	  }
	 }
	 
Note: on startup the following is printed

	2016-01-29 10:21:24.728  INFO 15652 --- [           main]
ationConfigEmbeddedWebApplicationContext : Refreshing
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@70beb599:
startup date [Fri Jan 29 10:21:24 GMT 2016]; root of context hierarchy
	2016-01-29 10:21:26.821  INFO 15652 --- [           main]
o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for
bean 'beanNameViewResolver' with a different definition: replacing [Root
bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3;
dependencyCheck=0; autowireCandidate=true; primary=false;
factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration;
factoryMethodName=beanNameViewResolver; initMethodName=null;
destroyMethodName=(inferred); defined in class path resource
[org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]]
with [Root bean: class [null]; scope=; abstract=false; lazyInit=false;
autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false;
factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter;
factoryMethodName=beanNameViewResolver; initMethodName=null;
destroyMethodName=(inferred); defined in class path resource
[org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
	2016-01-29 10:21:27.251  INFO 15652 --- [           main]
trationDelegate$BeanPostProcessorChecker : Bean
'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [class
org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$67832a83]
is not eligible for getting processed by all BeanPostProcessors (for
example: not eligible for auto-proxying)
	2016-01-29 10:21:27.445  INFO 15652 --- [           main]
trationDelegate$BeanPostProcessorChecker : Bean
'camel.springboot.CONFIGURATION_PROPERTIES' of type [class
org.apache.camel.spring.boot.CamelConfigurationProperties] is not eligible
for getting processed by all BeanPostProcessors (for example: not eligible
for auto-proxying)
	2016-01-29 10:21:27.670  INFO 15652 --- [           main]
trationDelegate$BeanPostProcessorChecker : Bean 'camelContext' of type
[class org.apache.camel.spring.SpringCamelContext] is not eligible for
getting processed by all BeanPostProcessors (for example: not eligible for
auto-proxying)
	2016-01-29 10:21:27.671  INFO 15652 --- [           main]
trationDelegate$BeanPostProcessorChecker : Bean 'webServiceConfig' of type
[class
com.aspect.manhattan.hubchannel.ctips.ws.producer.config.WebServiceConfig$$EnhancerBySpringCGLIB$$201e0532]
is not eligible for getting processed by all BeanPostProcessors (for
example: not eligible for auto-proxying)
	2016-01-29 10:21:27.677  INFO 15652 --- [           main]
trationDelegate$BeanPostProcessorChecker : Bean
'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type
[class
org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$bd9acd63]
is not eligible for getting processed by all BeanPostProcessors (for
example: not eligible for auto-proxying)
	2016-01-29 10:21:27.712  INFO 15652 --- [           main]
.w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August
2004, WS-Addressing 1.0]

Starting the scala application will host the web service and the service is
called as normal. I was expecting that the messageDispatcher would route the
calls to the Camel Endpoint ie: that HeartbeatEndpoint method Heartbeat
would never get called. This is not what is happening.

	2016-01-29 10:02:47.723  INFO 14988 --- [nio-8080-exec-1]
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring
FrameworkServlet 'messageDispatcherServlet'
	2016-01-29 10:02:47.723  INFO 14988 --- [nio-8080-exec-1]
o.s.w.t.http.MessageDispatcherServlet    : FrameworkServlet
'messageDispatcherServlet': initialization started
	2016-01-29 10:02:47.730  INFO 14988 --- [nio-8080-exec-1]
o.s.w.t.http.MessageDispatcherServlet    : FrameworkServlet
'messageDispatcherServlet': initialization completed in 7 ms
	HEART BEAT  
	
	
Any help or guidance appreciated.



--
View this message in context: http://camel.465427.n5.nabble.com/Akka-Camel-and-Spring-Boot-tp5777000.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: Akka, Camel and Spring Boot

Posted by jgoggins <jo...@hotmail.com>.
In an attempt to get the Camel Context I did the following in the scala
project. 

In application.conf I added 

akka.camel.context-provider="com.utility.MyContextProvider"

I then created a new class in the scala file. 

@Component
final class MyContextProvider extends ContextProvider {

 @Autowired() var ctx: ApplicationContext = _

  override def getContext(system: ExtendedActorSystem) = {
    println(s"Context called {$ctx}") // ctx is NULL.
    //     new SpringCamelContext(ctx)
    println(s"Context called ${WebServiceConfig.camelContext1}")

    WebServiceConfig.camelContext1 /// A static member created as a
workaround
  }

This causes an error 

Context called {null}
Context called SpringCamelContext(camel-1) with spring id application
Exception in thread "main" java.lang.IllegalStateException: Disabling JMX
can only be done when CamelContext has not been started
	at
org.apache.camel.impl.DefaultCamelContext.disableJMX(DefaultCamelContext.java:3842)
	at
akka.camel.internal.DefaultCamel.context$lzycompute(DefaultCamel.scala:35)
	at akka.camel.internal.DefaultCamel.context(DefaultCamel.scala:33)
	at akka.camel.internal.DefaultCamel.start(DefaultCamel.scala:53)
	at akka.camel.CamelExtension$.createExtension(Camel.scala:134)
	at akka.camel.CamelExtension$.createExtension(Camel.scala:128)
	at akka.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:757)
	at akka.actor.ExtensionId$class.apply(Extension.scala:79)
	at akka.camel.CamelExtension$.apply(Camel.scala:128)
	at
com.aspect.manhattan.hubchannel.ctips.utility.CtipsHcaApplication.Run(CTIPSHcaApplication.scala:86)
	at
com.aspect.manhattan.hubchannel.ctips.utility.CtipsHcaApplication$.main(CTIPSHcaApplication.scala:50)
	at
com.aspect.manhattan.hubchannel.ctips.utility.CtipsHcaApplication.main(CTIPSHcaApplication.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)



--
View this message in context: http://camel.465427.n5.nabble.com/Akka-Camel-and-Spring-Boot-tp5777000p5777002.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: Akka, Camel and Spring Boot

Posted by jgoggins <jo...@hotmail.com>.
Reading more on this; I found a reference in support forums that direct-vm
would be the way to go - can anyone back this up ? One camel context across
multiple modules possible ? 



--
View this message in context: http://camel.465427.n5.nabble.com/Akka-Camel-and-Spring-Boot-tp5777000p5777065.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: Akka, Camel and Spring Boot

Posted by jgoggins <jo...@hotmail.com>.
Another option; 

If I reverse the call in my Scala application to be 

val camel = CamelExtension(actorSystem).context 
        SpringApplication.run(classOf[Application])     // Call the Java
Spring Boot dependent jar file to host the endpoints. 
        actorSystem.actorOf(Props(classOf[CamelService]) 


Then the Camel Context is started before the Spring Boot application -- but
that returns the question, how do I then get my spring boot application to
use the Camel Context that was created for the Scala Actor System.

Is there anything I can do here in the Java bean when its been created or
will I have issues with the incorrect application context ??? 

 @Bean
    public SpringCamelContext camelContext(ApplicationContext
applicationContext) throws Exception {

        SpringCamelContext camelContext = new
SpringCamelContext(applicationContext);

        System.out.println("SpringCamelContext camelContext is created : " +
camelContext.getName() + " version "+  camelContext.getVersion() + " status
"+ camelContext.getStatus());
 
        return camelContext;
    }


Thanks for any advice. 




--
View this message in context: http://camel.465427.n5.nabble.com/Akka-Camel-and-Spring-Boot-tp5777000p5777004.html
Sent from the Camel Development mailing list archive at Nabble.com.