Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-13954

Sending Message from External Task to Engine (via specific method)



    • Feature Request
    • Resolution: Won't Do
    • L3 - Default
    • None
    • 7.16.0-alpha5
    • None


      User Story (Required on creation):

      Hello Team.
      I hope you are doing well.
      Following this post, sending a managed message will be important for the end-user client that need to work with Rest API (between External task and Engine). Actually, we need a module for sending any kind of message to the Engine (from External Task) and it seems we could prepare it according to the suggestion ( use Rest API for POST /message).

      Functional Requirements (Required before implementation):

      The main goal is to send any kind of message (with related variables) between External tasks and the Engine which is used to communicate or notify some information. it should be done with an External Task.

      As we describe the point, it will be like a specific method for sending proper messages to the Engine. So just we need a new API method.

      According to your contribution structure, the idea is under the Community Extensions category.

      Technical Requirements (Required before implementation):

      We could send our message with two VariableMap(for example `processVariables` and `correlationKeys`) easily. I have developed below source code on the External Task project.
      I have attached each modification separately


      //   public static final String SEND_MESSAGE =  "/message";
        public void sendMessage(ExternalTask externalTask, String message, VariableMap correlationKeys, VariableMap processVariables, Boolean all) throws EngineClientException {
          SendMessageRequestDto payload = new SendMessageRequestDto(externalTask, message, correlationKeys, processVariables, all);
          String resourceUrl = baseUrl + SEND_MESSAGE;
          engineInteraction.postRequest(resourceUrl, payload, Void.class, xsrf);


        public void sendMessage(ExternalTask externalTask, String message, VariableMap correlationKeys, VariableMap processVariables, Boolean all) {
          try {
            engineClient.sendMessage(externalTask, message, correlationKeys, processVariables, all);
          } catch (EngineClientException e) {
            throw handleException(e, "send message", true);

      ExternalTaskService.java (interface)

         * Send Message
         * @param message     which message string that you need to send to engine
         * @param correlationKeys indicates the master keys for correlation.
         * @param processVariables provides related variables to the process.
         * @param all      specifies which params should be send (all or not).
         * @throws NotFoundException if the task has been canceled and therefore does not exist anymore
         * @throws NotAcquiredException if the task's most recent lock could not be acquired
         * @throws ConnectionLostException if the connection could not be established
         * @throws ValueMapperException
         * <ul>
         *   <li> if an object cannot be serialized
         *   <li> if no 'objectTypeName' is provided for non-null value
         *   <li> if value is of type abstract
         *   <li> if no suitable serializer could be found
         * </ul>
        void sendMessage(ExternalTask externalTask, String message, VariableMap correlationKeys, VariableMap processVariables, Boolean all);

      In the end, I prepared a sample test and catch a successful response from the Engine.

         public static void main(String[] args) {
              // Personal Test
              ExternalTaskClient client = ExternalTaskClient.create()
                      .asyncResponseTimeout(10000) // long polling timeout
                      .handler((externalTask, externalTaskService) -> {
                          VariableMap correlationKeys = new VariableMapImpl();
                          correlationKeys.putValueTyped("aVariable", Variables.stringValue("aValue"));
                         VariableMap processVariables = new VariableMapImpl();
                         processVariables.putValueTyped("aVariable", Variables.stringValue("aNewValue", true));
                         processVariables.putValueTyped("anotherVariable", Variables.booleanValue(true, true));
                         externalTaskService.sendMessage(externalTask, "aMessage", correlationKeys, processVariables, null);

      Limitations of Scope (Optional):

      Hints (optional):

      It's our pleasure if we can help you with developing the module.
      According to the post, it could be such a necessary feature that would be helpful for users and Mr. @tassilo.weidner according to this comment said to make a pull request.

      Let me know your final feedback.

      Thank you in advance


        This is the controller panel for Smart Panels app




              tassilo.weidner Tassilo Weidner
              tahaarian taha arian
              Tassilo Weidner Tassilo Weidner
              0 Vote for this issue
              3 Start watching this issue