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 [url=]Activiti User Guide) 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:
com.haulmont.cuba.core.global.RemoteException: 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.
com.haulmont.cuba.core.global.RemoteException: No security context bound to the current thread
at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(ServiceInterceptor.java:83) ~[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(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[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(AbstractMessageListenerContainer.java:746) ~[spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:684) ~[spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:651) ~[spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:315) [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:253) [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1150) [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1142) [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1039) [spring-jms-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at java.lang.Thread.run(Thread.java:745) [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: [url=]https://doc.cuba-platform.com/manual-6.1/system_authentication.html[/url]

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 app.properties file in the core module.

The cuba.jmxUserLogin default value is defined in the cuba-app.properties 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

app.properties - 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

FDRListener.java - JMS Listener component

Also I have included below dependencies for the project in Cuba studio:
org.springframework:spring-jms:4.2.0.RELEASE
org.springframework:spring-messaging:4.2.0.RELEASE
org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1
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)

Archive.zip (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.
com.haulmont.cuba.core.global.RemoteException: 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.

FDRListener.java.zip (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.

jmt.zip (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.