Creatio development guide
PDF
This documentation is valid for Creatio version 7.16.0. We recommend using the newest version of Creatio documentation.

Messages. The "messages" property

Glossary Item Box

Introduction

Data exchange between modules is organized through messages.

There are two message modes:

  • Address. Address messages are only received by the last subscriber. To switch to address mode, set the mode property to this.Terrasoft.MessageMode.PTP.
  • Broadcasting. Broadcasting messages are received by all subscribers. To switch to broadcasting mode, set the mode property to this.Terrasoft.MessageMode.BROADCAST.

The list of available message modes is represented by the Terrasoft.MessageMode enumeration.

There are two message directions:

  • Publication – a message that can only be published (outbound). To set the direction for message publishing, set the direction property to this.Terrasoft.MessageDirectionType.PUBLISH.
  • Subscription – a message that can only be subscribed to (inbound). To set the direction for message subscription, set the direction property to this.Terrasoft.MessageDirectionType.SUBSCRIBE.

The same message can not be announced with different directions in the schema inheritance hierarchy.

Message use examples

Message publishing

Declare a message with the “publishing” direction in the schema you want to publish the message in.

messages: {
    // Message name.
    "GetColumnsValues": {
        // Message type – address.
        mode: this.Terrasoft.MessageMode.PTP,
        // Message direction – publication
        direction: this.Terrasoft.MessageDirectionType.PUBLISH
    }
}

Publishing is done through calling the publish method from the sandbox class instance.

// The GetColumnsValues method for obtaining message publication resuls.
getColumnsValues: function(argument) {
    // Message publishing.
    return this.sandbox.publish("GetColumnsValues", argument, ["key"]);
}

In this code:

  • “GetColumnsValues” – message name.
  • Argument – the argument passed to the handler function of the subscriber. An object with message parameters.
  • ["Key"] – an array of tags for filtering messages.

The sandbox property is declared in all schemas.

Message publishing can return the handler function result only in the “address” mode.

Message subscription

A message with the "subscription" direction should be declared in the subscription schema.

messages: {
    // Message name.
    "GetColumnsValues": {
        // Message type – address.
        mode: this.Terrasoft.MessageMode.PTP,
        // Message direction – subscription.
        direction: this.Terrasoft.MessageDirectionType.SUBSCRIBE
    }
}

A subscription is carried out by calling the subscribe method in the sandbox class instance.

this.sandbox.subscribe("GetColumnsValues", messageHandler, context, ["key"]);

In this code:

  • “GetColumnsValues” – message name.
  • messageHandler – message handler function.
  • Context – handler function execution context.
  • ["Key"] – an array of tags for filtering messages.

In the “address” mode, the messageHandler method should return the object, which is processed as the result of message publication.

methods: {
    messageHandler: function(args) { 
    // Returning the object that is being processed as a result of message publishing.
    return { }; 
    }
}    

In broadcast mode, the messageHandler method returns nothing.

methods: {
    messageHandler: function(args) { 
    }
}    
© Creatio 2002-2020.

Did you find this information useful?

How can we improve it?