Send message start event

Hi,

First I’m sorry for my bad English :frowning:

For a student project i’am trying to instantiate a processe instance with a message start event, but don`t work.

I need to get a message from an API in my start event name SendMessage and start the next task, your name is Send Email.

How do I post a message from my API to my sendMessage name start event message?

This is my very Simple BPM example
send.bpmn (2.7 KB)

and my code.

public class SendMessage implements JavaDelegate {
private final Logger LOGGER = Logger.getLogger(SendMessage.class.getName());

@Override
public void execute(DelegateExecution execution) throws Exception {
    RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
    runtimeService.startProcessInstanceByMessage("SendMessage");

    this.LOGGER.info("\n\n  ... my process=" + execution.getProcessDefinitionId() + ", activtyId=" + execution.getCurrentActivityId() + ", activtyName='" + execution.getCurrentActivityName() + "', processInstanceId=" + execution.getProcessInstanceId() + ", businessKey=" + execution.getProcessBusinessKey() + ", executionId=" + execution.getId() + " \n\n");

}

}

How can we realize this? Sorry for my question, I’m a high school student and never programmed.
Thanks =)

It might be a good idea to take a look at these tutorial videos, and the specific tutorial that will likely help you answer this question is here.

Hi Nial,

I was able to implement doing a post directly on postman to the message API of the camunda, but not being able to do the post to the message API of the camunda when picking up the value of my rabbit queue in the spring boot to start the process could help me?

my code is:

import org.camunda.bpm.engine.RuntimeService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class ReceiveMessage implements MessageListener{

    @Autowired
    RuntimeService runtimeService;


    @Override
    public void onMessage(Message message) {
        try {
            

            Map<String,Object> variables = new HashMap<>();
            variables.put("value", new String(message.getBody(), "UTF-8"));

            runtimeService.createMessageCorrelation("ReceiveMessage")
                    .setVariable("value", variables).correlate();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

}

Messagem name in my bpmn is:

Thanks =)

what exactly is the error you’re getting?

Hi Nial.

nial, at the moment my application has error, did not show error in my catalina.out log file.
Sorry if I’m saying something wrong, I’m a beginner in programming and I’m doing it, the process I’m doing is a use case for a high school job.

I was able to create the MQ queue in Rabbit and receive the messages from my MQ queue in my application, but I can not send this message to the camunder to start my task automatically. I’m sorry if I can not spell out my problem exactly.

In Postman, when I mount the Request and implement my JavaDelegate it works, for example:

http://localhost:8080/engine-rest/message

{
  "messageName" : "ReceiveMessage",
  "businessKey" : "3",
  "processVariables" : {
    "question" : {"value" : "Hi Nial", "type": "String"}
  }
}

And implementation Javadelegate:

 String question = (String) execution.getVariable("question");
  execution.getProcessEngineServices()
.getRuntimeService().createMessageCorrelation("ReceiveMessage")
.setVariable("question", question)
.correlate();

Its works.

but how could I post the message from Rabbit automatically in my spring boot application? Without me having to use Postman?

I Try this, and dont work:

package com.example.camunda.cainao.demo.domain;

import org.camunda.bpm.engine.RuntimeService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class ReceiveMessage implements MessageListener {


RuntimeService runtimeService;

@Override
public void onMessage(Message message) {
    try {

Map<String,Object> variables = new HashMap<>();
variables.put("value", new String(message.getBody(), "UTF-8"));

System.out.println("this is my Receive Messages of my RabbitMQ: "+ new String(message.getBody(), "UTF-8"));
      runtimeService.createMessageCorrelation("ReceiveMessage")
         .setVariable("value", variables)
         .correlateWithResult();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

}

}

It’s very hard to know what to suggest without knowing what exactly happens when your code runs. when you say your application has an error what exactly do you see?

Hi nial,

my log error:

Hi Nial,

I created a new spring boot project using archpypes camunda, did not add anything in my application to start everything from scratch, and received the following error in the start application

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceConfigCustomizer' defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration$JacksonResourceConfigCustomizer.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer]: Factory method 'resourceConfigCustomizer' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement

Would you help me?

can you upload your process model.
I’ll be able to help you if you have a problem with Camunda, but if the messaging service is the issue i won’t really be able to give you much advice

Hi Nial,

this is my simple BPMprocess.bpmn (2.8 KB)

And this is my simple code

**package** org.camunda.esfera.pocfinal;

**import** java.util.HashMap;

**import** java.util.Map;

**import** org.camunda.bpm.engine.RuntimeService;

**import** org.camunda.bpm.engine.runtime.ProcessInstance;

**import** org.camunda.bpm.spring.boot.starter.event.PostDeployEvent;

**import** org.springframework.beans.factory.annotation.Autowired;

**import** org.springframework.context.event.EventListener;

**public** **class** DeployProcess {

@Autowired

**private** RuntimeService runtime;

@EventListener

**private** **void** processPostDeploy(PostDeployEvent event) {

Map variables = **new** HashMap();

variables.put("message", "Hi Nial");

ProcessInstance instance = runtime.startProcessInstanceByKey("pocfinal", variables);

}

}

and this is my code structure in my IDE with my process to deploy. My code is correctaly?

as I send a simple variable in my process to see it in my tasklist camunda? I want to execute my process after receiving this sent message understand?

Where can I see the log of this message, since it is a web spring boot application and I do not use the standalone camunda?

I can reproduce the ClassNotFoundException: javax.xml.bind.annotation.XmlElement. Did you already find a solution?