Example of Messaging without code

Is there any example/tutorial on how to use messageevents without coding?

Hi @mbrain
If you want to implement message events without coding, you can use message Rest API as described in the following link :

Would an external task in nodejs be able to handle messaging? I only found examples in java.

Hi @mbrain,

yes. You have to code the Message correlation request with Java script.

I don’t konw if this is the most elegant way to build it, but it worked for me in the past:

const { Client, logger, Variables } = require("camunda-external-task-client-js");
const got = require('got');

// configuration for the Client:
//  - 'baseUrl': url to the Workflow Engine
//  - 'logger': utility to automatically log important events
const config = { 
  baseUrl: "http://localhost:8080/engine-rest", 
  use: logger,
  interval: 5000,
  lockDuration: 60000,
  maxTasks: 1
};

// create a Client instance with custom configuration
const client = new Client(config);

client.subscribe("confirmation-sending", async function({task, taskService}) {
  const processVariables = new Variables();
  const randomOrderId = Math.floor((Math.random() * 1000) + 1);
  processVariables.set("orderId", randomOrderId);
  try {
    console.log("Send out confirmation ...");
    var response = await got.post("http://localhost:8080/engine-rest/message", {
      json: {
        messageName: "confirmationMessage", 
        businessKey: task.businessKey, 
        processVariables: {orderId: {value: randomOrderId}}},
      retry: 0
    });
    console.log("Process started");
    await taskService.complete(task, processVariables);
  } catch (error) {
    console.log("Error message: " + error.message);
    console.log("Error details: " + JSON.stringify(error));
    await taskService.handleFailure(task, {errorMessage: error.message, errorDetails: JSON.stringify(error), retries: 0});
  }
});

Hope this helps, Ingo

Maybe you also have an example of receiving (or subscribing?) it in another external task in nodejs?

Hi @mbrain,

to receive a messge it is sufficient to model a receive event or task with a message name in the process.

Hope this helps, Ingo

So an external task does not receive it, only the process engine?

Hi @mbrain,

the code I posted implements a send task that should send a message to a message receive event in another process instance, running in the same engine.

If you receive a message from another channel (AMQP, Kafka, …) you have to implement a listener in that technology that translates the message into the message correlation API call.

Hope this helps, Ingo

Ok, so what is the message end event good for? Is it like the “data store reference” just for documentation? I delpoyed 2 simple processes.

At the end of “process1” i have a “message end event” sending a message “TestMessage”.

At the beginning of “process2” i have a “message start event” also configured for “TestMessage”.

But the end of “process1” does not start “process2”. Why?

Hi @mbrain,

this sounds OK.

Did you implement the Message End Event with an external task or Java class or Expression?

If not, thats the reason. The message definition in the Message Send Events didn’t have any impact on the process execution.

Hope this helps, Ingo

Hi @Ingo_Richtsmeier i did not. My question was if i have to do so and if yes, what is the event actually for? Shouldnt it be a service task then?

Hi @mbrain,

it depends how you read the icons of the bpmn symbols. A black envelope shows something different to the reader than the two cogwheels. But technically it’s the same, as well for message send events. They can have an implementation to send the message via every channel that is technically possible.

As a developer you may not worry about the symbols, as the job is to send out a message. You have written the code to send it and you can use it on all task types that allows code execuction: Service, Message send, Business Rules, Script and the message send events.

The BPMN standard allows a lot options here which makes discussions with the business people interesting. You can model the same sequence of activities with different symbols and agree as a group of developers and business people, which model expresses the real world best.

Hope this helps, Ingo

1 Like

Ok, thank you, now i understand so it has to be coded. Is it the same for signal events?

Hi @mbrain,

no, signals are different. Send and receive works without coding, just configuration in the model.

But signals are broadcasts from the BPMN standard. One thrown signal will be catched by all process instances that are listening to the signal. It’s a one-to-many relationship where messages are always a one-to-one relationship.

Hope this helps, Ingo

I dont get it. Does a “intermediate message throw event” do anything?

Hi @mbrain,

if you don’t configure any implementation, the message send events are just passed (intermediate and end).

You can use them to send real messages, but you don’t have to.

Hope this helps, Ingo