Receiving http requests


#1

Hi,

Excuse me for novice questions, but how can I model a process so that it can always have an open connection to receive http requests? Another system may at any point send to my process messages that I want to catch.
The http connectors is only to send http requests, right? So, what about receiving?
Maybe I haven’t understood correctly some concepts.

Thanks!


#2

Create a non interrupting message start event inside of a event sub process.


#3

Good point @StephenOTT! I was also thinking of that since I have implemented it on a project where I have an open websocket connection to receive messages which can trigger the message start event in the sub process.

But maybe I didn’t make it clear. The question is how to have a listener to catch http requests send by another system? In the other project, as I said I have a websocket client with a listener to catch the messages. But now that the other system can only send http request messages, how can I catch them?

Hope it’s more clear now.


#4

You can use the /message endpoint to send you messages. But be away of possible race events where the system is sending you message too quickly (usually sub second responses)


#5

Hi @StephenOTT,

Sorry, still can’t get it. Is this to send a message or to receive from another application?
Do you have an example?

Thanks!


#6

See: Camunda Message and signalling

and instead of using the correlation with the expression, use: https://docs.camunda.org/manual/7.9/reference/rest/message/post-message/


#7

Hi,

So, I have a pattern/process like this

In the User Task, I have a “create” Task Listener to send an http request to another system to perform the task.
At any point I want to receive a “message/notification/event/something” from that other system (external to my process) that the task is complete. Once I receive it, I will call the task/complete API to complete the task.

From /message API documentation, I should receive a message like this:

{
  "messageName" : "aMessage",
  "businessKey" : "aBusinessKey",
  "correlationKeys" : {
    "aVariable" : {"value" : "aValue", "type": "String"}
  },
  "processVariables" : {
    "aVariable" : {"value" : "aNewValue", "type": "String", 
                    "valueInfo" : { "transient" : true } },
    "anotherVariable" : {"value" : true, "type": "Boolean"}
  }
}

What shall I write in the message name? Is it the “New_event_arrived” of my model? Is it the “msg_newevent”?

Thanks!

Edit: I tried it with “New_event_arrived” and it worked!


#8

Hi again,

I explain above what I try to achieve with the message start event in the Event Subprocess. It’s about a message call from the API to trigger the completion of a Task.
But how do you think should I pass the “taskInstanceId” in the message body? I would like to avoid it as a process variable because the matching may be wrong if at the same time two messages arrive and the process variable is updated two times (only the last value will be kept).
How can I make it work with correlation keys? Any suggestion?

Thanks!


#9

Hi @kontrag,

for me it seems you want to implement the external task pattern:

https://docs.camunda.org/manual/7.9/user-guide/process-engine/external-tasks/

You could also use a start execution listener on an external service task to inform your external systems that there is some work, but I would recommend the (long) polling approach that is described in the linked resource.

Kind regards,
Ragnar


#10

Hi @Ragnar,

I was also considering External Tasks but not sure if the “external system” can implement the “fetchandlock” logic (well, it’s not difficult with the API but I’m not sure whether I want to let the external system do it).

Thanks anyway!


#11

Hi,

In the example I provided above, I use the Message API to catch a message in a Message Start Event in an Event Subprocess (actually, the Message API is called by another system, external to my application).
The call of the API gives a result like the following:

[{
"resultType": "ProcessDefinition",
"execution": null,
"processInstance": {
    "links": [],
    "id": "aProcInstId",
    "definitionId": "aProcDefId",
    "businessKey": "aKey",
    "caseInstanceId": "aCaseInstId",
    "ended": false,
    "suspended": false,
    "tenantId": "aTenantId"
}
}]

How can I have access and parse this result? I mean both in terms of the modeler or code.
Thanks!

Edit:
Also, in the request body of the POST /message call which is like this:

{
  "messageName" : "aMessage",
  "businessKey" : "aBusinessKey",
  "correlationKeys" : {
    "aVariable" : {"value" : "aValue", "type": "String"}
  },
  "processVariables" : {
    "aVariable" : {"value" : "aNewValue", "type": "String", 
                    "valueInfo" : { "transient" : true } },
    "anotherVariable" : {"value" : true, "type": "Boolean"}
  }
}

how can I pass a JSON variable within the processVariables?