Message Start Event - Consuming message from message broker such as RabbitMQ

Does Flowable have the ability to consume a message from a message broker such as RabbitMQ. Most of what I have found points to having to do this ourselves. Essentially, we would need to implement a message listener and call the runtime service [runtimeService.startProcessInstanceByMessage(messageName)] to publish a message within the Flowable infrastructure. Before proceeding, I wanted to confirm that there was no easier way to do this as this is behaviour I was expecting to be present within the product.

Thanks in advance for the help,

Stephane

Hi Stephane,

Apache Camel, Spring Integration or Mule provide this kind of integration points out of the box, so that’s why we just provide an integration point with these frameworks. For Apache Camel you could consume the message and then start a new process instance in Flowable using a Camel route. You can have a look at the docs here http://www.flowable.org/docs/userguide/index.html#bpmnCamelTask

Best regards,

Tijs

Hi Tijs,

Thanks for the reply. I was off working on something for a little bit and I’m coming back to this. I managed to get the functionality in place to use Apache Camel. The question I’m asking myself is how do I start a process and pass in process variables that are read from the message on the queue.

Here is the way I had gotten it to work without Camel:

    @RabbitListener(queues = "${ams.rabbitmq.caseCreated}", containerFactory = "amsFactory")
public void receiveMessageCaseCreate(CaseCreatedEvent msg) {

	Map<String, Object> processVariables = new HashMap<String, Object>();
	processVariables.put("caseId", msg.getCaseId());
	
	runtimeService.startProcessInstanceByMessage("caseCreatedMessage", processVariables);
}

Using Camel, I’ve setup the following route:

from(“rabbitmq://localhsost/ams.rabbitmq.caseCreated?queue=ams.rabbitmq.caseCreated&exchangeType=direct&routingKey=ams.rabbitmq.caseCreated&autoDelete=false”).to(“flowable:camelProcess”);

The documentation describes how to set a header for the process initiator:
from(“direct:startWithInitiatorHeader”)
.setHeader(“CamelProcessInitiatorHeader”, constant(“kermit”))
.to(“flowable:InitiatorCamelCallProcess?processInitiatorHeaderName=CamelProcessInitiatorHeader”);

Is there a way to set a header for process variables?

Thanks,

Stephane

You can influence how/if camel headers/body/exchangeProperties are mapped process variables, for example if you use:

from(“direct:startWithInitiatorHeader”)
    .setHeader(“ProcessVariableA”, constant(“ValueA”))
    .setHeader(“ProcessVariableB”, constant(“ValueB”))
    .to(“flowable:InitiatorCamelCallProcess?copyVariablesFromHeader=true”);

“ProcessVariableA” and “ProcessVariableB” will be available in the process as variables.

See http://www.flowable.org/docs/userguide/index.html#bpmnCamelTaskPingPong section starting with “The following table provides an overview of three available Camel behaviors:” for more details.

2 Likes