Blog Posts BPMN DMN

Serverless Workflow integration with Camel Routes

Blog: Drools & jBPM Blog

A recent addition to the Kogito Serverless Workflow is the ability to call Camel Routes from your workflow!

When to use Camel routes

Camel is a powerful EIP implementation that provides many connectors to integrate with virtually any technology stack.

Kogito Serverless Workflow offers a few ways to make calls to remote services that expose standard interfaces such as OpenAPI and AsyncAPI.

Sometimes, you might need to make calls to legacy systems or specific services that require additional configuration, schema, or data structures so that the standard interfaces might not suffice.

For example, you might need to call a SOAP WebService from the workflow Operation state. Without additional Java implementation in your Kogito workflow application, you won’t be able to make requests to this SOAP service directly.

What if you could explicitly declare in your workflow definition that your function is a call to a Camel route in your project context?

How the integration works

Kogito Serverless Workflow has a new add-on capable of producing messages to a Camel Route within the same application instance.

For example, you have a Camel route in your project that can interface with a SOAP WebService like this one:




  
    
    
    
    
      NumberToWords
    
    
  

Then, from the workflow definition, you can declare a function that produces messages to this route:

{
  "functions": [
    {
      "name": "callSoap",
      "type": "custom",
      "operation": "camel:direct:numberToWords"
    }
  ]
}

Notice the new custom function with a new operation type. The operation is a URI scheme composed of the constant “camel:“, the “direct:” endpoint, and its name. Kogito Serverless Workflow only supports producing messages to a direct endpoint at this time.

To use this function in the State definition, you can refer to the function as you usually would:

{
  "states": [
    {
      "name": "start",
      "type": "operation",
      "actions": [
        {
          "functionRef": {
            "refName": "callSoap",
            "arguments": {
              "body": "${ .number }",
              "headers": { "header1": "value1", "header2": "value2"}
            }
          }
        }
      ],
      "end": true
    }
  ]}

The function arguments can have optional attributes, “body” and “headers.” These arguments will be constructed as part of the Camel Producer Template handled internally by the Kogito engine. The body can be any valid JSON object and the headers must be a key/value pair.

Your route is responsible for properly handling the message. In the example above, the body is the number contained in the JSON payload.

The route response must be a valid Java bean object that can be serialized to JSON or a primitive type. Note that a JSON string is a valid output. The data will be merged into the workflow context data in the response attribute, for example:

{
    "fruit": "orange",
    "response": { "number": 10 }
}

In this GitHub repository, you will find more information about this scenario and the complete project example.

Final thoughts

The Camel Kogito add-on complements our work of integrating with the Camel-K project. In the use case described in this post, the Camel route is tightly coupled to the workflow. If you need to reuse the route or have more complex interface interactions (such as a REST endpoint), you should use Camel-K and interact with the services via OpenAPI interfaces.

Overall, this new feature introduced by Kogito Serverless Workflow can solve many use cases and enable integration with any service interface or data format supported by Camel. It’s a new way of interacting with services that don’t have standard interfaces or formats available, all within the same application.

In a world where many companies are looking to modernize their architecture and lift to the cloud, we believe this new feature can help them through the journey. Leave a comment or open a thread on our Zulip channel if you have any questions.

The post Serverless Workflow integration with Camel Routes appeared first on KIE Community.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/serverless-workflow-integration-with-camel-routes/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×