[InterSystems IRIS for the first time] Interoperability: Message
Tags: beginners, programming, tutorial, interoperability
Published: 2022-11-15 21:11:46

**This article is a follow-up to <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-what-prodction" target="_blank">this post</a>**.

In the <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-what-prodction" target="_blank">previous article</a>, [What is a Production?], we checked the production contents. We ran the sample code and checked the flowing messages' contents into the production on the Visual Trace page.

This article will review the concept and the definition of the **<span style="color:#16a085;"> messages</span>**  used to send and receive data between components from the required development content for system integration.

* <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-what-prodction" target="_blank">Production[ previous post ]</a>
* <span style="color:#16a085;"><strong>Message</strong></span>
* Components
  * Business Services
  * Business Processes
  * Business Operations

Before creating a <span style="color:#16a085;"><strong>message</strong></span>, let's review the case study.
> <span style="color:#2980b9;">A company operates a shopping site and is changing the order of displaying product information to match the seasons.<br />However, some items sell well regardless of the season, while others sell at unexpected times, which does not match the current display rule of changing the order.<br />Therefore, we looked into the possibility of changing the order of display to match the day's temperature instead of the season. It became necessary to survey the temperature of the purchased products at that time.<br/> Since an external Web API is available for checking weather information, we plan to collect the weather information at the time of purchase and register it in the later review database.</span>

From this case, you can see the following:
<p style="margin-left: 40px;">Information to be received from the outside is "purchased product name and name of the city."<br />The information to be sent from IRIS to an external system to request processing is the "name of the city." The result of this process will be "weather information" for the city used as an input.
</p>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05trr50fuk07kew8ue53.png)

From this case study, we will implement the components needed for system integration. But before that, to run the components, you need to send and receive<span style="color:#16a085;"><strong> messages</strong></span>, which are relay data, and to use the <span style="color:#16a085;"><strong>messages</strong></span>, you need to define the message class.

A message class is designed to consider **<span style="background-color:#f1c40f;">what information (i.e., messages) should be sent and received to make the component to run.</span>**

In this process, we need the following two types of information:
<p style="margin-left: 40px;">
  A) The <u><strong> name of the city</strong></u> to send to an external Web API to obtain <span style="color:#c0392b;"><strong> weather information.</strong></span>
  </p>
<p style="margin-left: 40px;"> 
B)<span style="color:#c0392b;"><strong> weather information</strong></span> and <u><strong>purchased product name</strong></u> for recording in the DB.
</p>

The <u><strong> name of the city</strong></u>  in A) and the **<u>purchased product name</u>** in B) can be included in the input information to IRIS.

The<span style="color:#c0392b;"><strong> weather information</strong></span> in B) can be retrieved from the response information of an <span style="color:#c0392b;"><strong>external Web API.</strong></span>

Here is a diagram that considers what information would be needed to send and receive each component from the available data.

The<u><strong> first line</strong></u> of the **<span style="background-color:#f1c40f;"> yellow balloons</span>** describes the <u><strong>message class name</strong></u>, and the second line onwards states what to set for the property.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11sl6d21t8pr2qf8ghlr.png)


In the sample code, we have the following three types of **<span style="color:#16a085;">messages</span>**:

<p style="text-align: justify; margin-left: 40px;">
  <u><strong><a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Request.cls" target="_blank">Start.Request</a>（Request message)</strong></u><br />It is used to send the name of the <u><strong><em>purchased product</em></strong></u> and the <u><strong>city</strong></u> to acquire the weather information.
</p>

<p style="margin-left: 40px;">
  <u><strong><a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Response.cls" target="_blank">Start.Response</a>（Response message)</strong></u><br />They are used to return the results of operations (<span style="color:#c0392b;"><strong>weather information</strong></span>) to obtain weather information.
</p>

<p style="margin-left: 40px;">
  <u><strong><a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/InsertRequest.cls" target="_blank">Start.InsertRequest</a>（Request message)</strong></u><br />
It is used to send the<span style="color:#c0392b;"><strong> weather information</strong></span> and the <u><strong>name of the purchased products</strong></u> for DB registration.
</p>

The<span style="color:#16a085;"><strong> messages</strong></span> are specified in a superclass, Request message, and Response message are derived from **Ens.Request** and **Ens.Response**, respectively.

The following is an example of the definition of the Request message Start.Request.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sf6ebw2xoeihyd93ah4w.png)

Below is an example of the definition of the Response message.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwerifpueitiy71aoyjy.png)

The Request message, Start.InsertRequest to be sent with the DB registration request is as follows:

(We plan to set the WeatherInfo property to the information in Start.Response, which will be returned after the weather information is obtained.)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1anoadieyqy14sj8ik9.png)

<p style="margin-left: 40px;"></p>

<p style="margin-left: 40px;">
If you want to create it in Studio, you can also use the Message Creation Wizard.
</p>

<p style="margin-left: 40px;">
 Reference) Steps to create a response class in Studio
</p>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pgb4s19c5vgum9skkpm.png)

<p style="margin-left: 40px;">
  <img src="https://jp.community.intersystems.com/sites/default/files/inline/images/images/image(1078).png" />The key point so far
</p>

<p style="margin-left: 40px;">
 A message class is designed with the idea of "what information (i.e., <span style="color:#16a085;"><strong>messages</strong></span>) should be sent and received" to make the component RUN.
</p>

Once the message class (which is the information to drive each component) is implemented, the next step is to create a class for the component.