Cuba BPM Module: Initiating a process based on JMS Message

Is it possible to initiate a BPM process based on message arrival in JMS queue?

I have looked into Activiti engine, and the suggested approach is to use Apache camel to invoke the BPM process based on arrival of messages in JMS queue. I wanted to know if Cuba offers any different approach to this as Apache camel would require to be executed as separate process and would have extra maintenance overhead.
Or, Is there a way to embed apache camel router into same Cuba application which is hosting the BPM process and make it work together?

Any sample project on Cuba-Camel integration would be appreciable to start with.

1 Like

CUBA Platform doesn’t have a custom integration with message brokers. So you’ll have to implement this part by yourself.
Is there a way to embed apache camel router into same Cuba application” - we don’t have much experience in working with Apache Camel, but it looks like that the camelContext can be easily registered in the same Spring context with the CUBA application.
You also can implement the JMS message consumer without Apache Camel, using the Spring JMS for example. Then inside the listener call the ProcessRuntimeManager.startProcess(…) method to start the BPM process in a regular way.
If you have multiple processes that must be started when some message is received, then using message start events (see in you process models may be a good choice. But in this case, you cannot use BPM module wrappers for starting the process and you will have to use the Activiti API methods directly: RuntimeService#startProcessInstanceByMessage.

1 Like

Hi Max,

Suggested approach to use Spring JMS sounds better and I tried to implement similar to my previous Spring jms experience, but seems there are some more Cuba security related area that needs to be handled.

Getting below error: No security context bound to the current thread

Can you guide on the above error, what have I missed to configure to override security context validation?

Stack trace:
2016-05-16 14:46:22.378 WARN [jmsMessageReceiver-8] org.springframework.jms.listener.DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set. No security context bound to the current thread
at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke( ~[cuba-core-6.1.4.jar:6.1.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke( ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke( ~[na:1.8.0_65]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke( ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at com.sun.proxy.$Proxy177.onMessage(Unknown Source) ~[na:na]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener( ~[spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener( ~[spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener( ~[spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute( [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute( [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener( [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop( [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$ [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at [na:1.8.0_65]

The problem is that your thread is not associated with any system user. Use the Authentication bean to provide the system authentication for a code block. Details are here:

1 Like

Seems like System Authentication doesn’t work for JMS Listener configured for Spring Jms.
I have tried both approach mentioned in the above link and seems to be some bug. I am using platform-6.1.4

Also, as mentioned in doc the default value for the app property cuba.jmxUserLogin is ‘admin’, do I need to overwrite it or it will work with default configuration as I don’t see this property under file in the core module.

The cuba.jmxUserLogin default value is defined in the file. You have to override it in your own properties file only if you want to change the defaults.
As for authentication, it should work. Can you please provide a source code of your JMS listener?

Hi Max,

Thank you very much for such extensive support.

Please find attached implementation files.
applicaitonContext-mq.xml - Spring JMS configuration file (you can replace the values for providerUrl, ConnectionFactory jndiName and MessageQueue jndiName according to the environment - Modified to include above spring configuration file (Please note that I’m able to read from the JMS queue based on configuration in applicationContext-mq.xml - JMS Listener component

Also I have included below dependencies for the project in Cuba studio:
wlslib:wlthint3client-10.3.6 (This is required for Oracle Weblogic t3 client, in case you are using ActiveMQ or other JMS queue based implementation you could include the related libraries) (2.8K)

I don’t see a BPM beans invocations from the listener. Can you please show me how you are trying to start the process from the listener.

I have removed the part for BPM process instance creation as I though it to be the issue, but i’m getting security error which I believe is the first step I should resolve. No security context bound to the current thread

As suggested I have added the necessary changes to override the above error but it’s still throwing same error, hence my issue that System Authentication is not working for spring Jms listener and i’m unable to complete the activity of initiating a process based on JMS messages.

I have attached here the BPM RuntimeManager invocation included code. Please advise. (1.2K)

I tried your listener and it works. My project is attached to the comment (I used ActiveMQ for the demo). Try it on your side.
A test message can be sent with a sendMessage method of the MessageSender MBean.
Maybe you’ll see any differences with your project. (182.4K)

Hi Max,

It worked on my project and I’m not sure if this was issue with Cuba Studio not able to clean tomcat directories.
After I deleted tomcat directory from build myself and deployed a fresh same code worked.

Thank you very much for your support and yes the spring-jms approach fits best to this requirement.