cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to advice routes holding activiti consumers

mteira
Champ in-the-making
Champ in-the-making
Hi there,

I'm new to Activiti, evaluating it as a potential replacement solution for our BPM engine. 
While checking some use cases I've hit a problem trying to write a test case that tries to advice a camel route with an activiti consumer. The environment was:
- Activiti 5.14
- Camel 2.11
- JDK 1.6
- Test case using a spring context, declaring a camel context to scan a package for routes.

The issue seems to be related to this sequence of operations:
- The spring context is setup, creating the camel context, which sets up the discovered routes.
- The test case is started, and the camel context is instructed to advice the route
- The camel context tries to refresh the route, to perform the required modifications
- Starting the route again, throws the following exception:


java.lang.RuntimeException: Activit consumer already defined for activiti://TestProcess:sender!
   at org.activiti.camel.ActivitiEndpoint.addConsumer(ActivitiEndpoint.java:60)
   at org.activiti.camel.ActivitiConsumer.doStart(ActivitiConsumer.java:27)
   at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
   at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1803)
   at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:2097)
   at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:2033)
   at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1963)
   at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1976)
   at org.apache.camel.impl.DefaultCamelContext.startRouteService(DefaultCamelContext.java:1853)
   at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:752)
   at org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:278)
   at camel.test.AdviceActivitiConsumerRouteTest.testAdviceOnActivitiRoute(AdviceActivitiConsumerRouteTest.java:21)



Checking the code in activiti-camel, I understand that on start, the ActivitiConsumer sets himself as the consumer for the ActivitiEndpoint. However, no overloading of the doStop() method is made, and so, a stop/start sequence on the consumer leads to the Endpoint throwing that exception since a consumer is already setup.

In my understanding, this prevents a route with an activiti consumer to be restarted and hence, to be adviced in case it was already started. I've tried a little modifications to the ActivitiConsumer to override doStop() and remove the consumer from the endpoint, and it seems to work properly. I'm adding below some analysis on the issue I've made, to your consideration (and also the patch).

Should I open a Jira issue for this or could be something related to a bad usage from my side?

Best regards,

Manuel.


Following a simple test case to prove it (it throws the aforementioned exception)


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/activiti-camel-test.xml")
public class AdviceActivitiConsumerRouteTest {
   
   @Autowired
   private ModelCamelContext camelContext;
   
    @Test
    public void testAdviceOnActivitiRoute() throws Exception {

       camelContext.getRouteDefinitions().get(0).adviceWith(camelContext,
             new AdviceWithRouteBuilder() {
               @Override
               public void configure() throws Exception {
                  intercept().to("mock:foo");
               }
       });
       
    }
}


Where the route is anything holding an activiti consumer, like:


public class CamelTestRoute extends RouteBuilder {

   @Override
   public void configure() throws Exception {
      from("activiti:TestProcess:sender")
      .to("log:test");
   }
}


The spring context has nothing special other than the standard configuration. Only a camel context to scan a given package for routes:

   <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
      <packageScan>
         <package>camel.test.route</package>
      </packageScan>
   </camelContext>



1 REPLY 1

mteira
Champ in-the-making
Champ in-the-making
Hello again,

I've opened ticket http://jira.codehaus.org/browse/ACT-1988 for this issue.

Best regards,

Manuel