Conference Offers and Management API Samples

This API sample illustrates the rapid creation of data processing systems and a modern microservices architecture.
lac53
The Conference Offers and Management videos demonstrate how to build a complete conference offer management system. This system includes database creation, customizing a user interface (UI) using Data Explorer, and defining the business logic.
The Conference Offers and Conference Management API samples illustrate the following systems integration:
You can explore these API samples in API Creator. On the APIs page, click the
Learning Center - Example
tile, then click the
Example
tab in the Learning Center. The high-level steps illustrate creating a microservice, starting from design to outcome.
The API samples illustrate the following capabilities:
Requirement
Shown By
Solution - Low Code Microservices
Business: Rapid creation of data processing systems
The
Conference Offers
processes the conference participation offers it receives from partners. It is created, from scratch, in under 20 minutes.
Low Code:
  • Automatic UI, using Data Explorer
  • Point-and-click API
  • Reactive business logic
Technical: Modern Microservices architecture
The
Conference Management
microservice illustrates a typical pattern of autonomous messaging service for message subscription and processing.
Microservice:
  • APIs
  • Kafka and MQTT messages
This example demonstrates the
Publish and subscribe to messages
use case.
For more information about this use case, see API Creator Overview.
In this article:
3
Business Requirement
The following roles do business with your company:
  • Partners
    put on conferences, which consist of talks and exhibits. Partners extend offers to participate in conferences by posting these offers to the
    Conference Offers
    API, providing a location and talk and exhibit options. The conferences include costs that the system must capture and persist.
  • Organizers
    select talk or exhibit conference options, subject to a budget with the UI that is shown in the previous image.
  • Managers
    approve conference participation, which alerts the conference management by way of an MQTT message, and sends a confirmation back to the partner.
As part of the application economy, your company receives discounts if your interaction is digital. Also as part of the application economy, you needed the system yesterday.
Solution
The following diagram illustrates the solution that this sample provides:
  1. Partners post conference participation offers to the Conference Offers microservice (URL fragment:
    conf-offer
    ).
  2. Managers approve the conference participation (talk or exhibit) that organizers select using Data Explorer.
  3. The
    Alert Management - JSON Message
    event rule alerts the Conference Management microservice (URL fragment:
    conf-management
    ) by way of MQTT messages.
  4. The Conference Management microservice includes a messaging service that subscribes to the MQTT messages and then processes them. Approved conference participation offers cause charges to be incurred. This microservice also optionally sends a confirmation message back to the originating partner.
    ConfOfferDiagram.png
Install the Samples and Configure the Connections
Layer7 Live API Creator
includes the ConfManagement and ConfOffer databases. You add data as part of the validation process of this sample.
The
Conference Offers
and
Conference Management
API samples are included with the single-user demonstration package of
Layer7 Live API Creator
that is based on Jetty and with the
Layer7 Live API Creator
Docker container installation. No additional steps are required to load these APIs.
Activate the Connections
For message operation, you must activate the connections for these API samples.
Configure the MQTT Connections
The samples run with a public MQTT broker. You can reconfigure the
PublishManagementConnection
and the
ManagementConnection
MQTT connections to use a different MQTT broker (for example, a locally installed broker).
Follow these steps:
  1. With the
    Conference Offers
    API sample open, in the Create section, click
    Listeners
    .
  2. Click the
    Connections
    tab.
  3. Select the
    PublishManagementConnection
    MQTT connection, select the
    Active
    checkbox, and then save your changes.
  4. Click the
    Parameters
    tab.
  5. If necessary, update the value for the
    broker
    parameter to a different MQTT broker, for example,
    tcp://<brokername>:1883
    , and then click
    Save Parameters
    .
  6. Click
    Reconnect
    .
    Your changes to the broker name are applied to the connection and your connection is restarted.
  7. Confirm that the connection is in the "Open" status.
  8. Repeat steps 1 through 7 for the
    ManagementConnection
    MQTT connection that is in the
    Conference Management
    API sample.
Your MQTT connections are configured.
Conference Offers Microservice
As is typical for applications today, services must:
  • Process APIs (in the
    Conference Offers
    API sample, process conference participation offers that partners post).
  • Persist the data with associated business logic.
  • Interact with other systems through messaging (in the
    Conference Offers
    API sample, the
    Alert Management - JSON Message
    event rule).
Partner Integration - Process Partner Posts
Explore the
PartnerPost
resource in the
Conference Offers
API sample. The API definition chooses and renames the columns that match the API agreement. The following image shows the details for the
Exhibits_List
subresource:
PartnerPosts.png
The
PartnerPost
resource saves the request payload for auditing and error/retry purposes by way of extended properties. The following code snippet shows the code for the extended properties for this resource:
{
"PersistTo": "PartnerPostAudit"
}
The
SysAudit Pipeline
request pipeline determines which resource to persist the payload by accessing the extended properties for the
PartnerPost
resource.
For more information:
Business Logic
The
Conference Offers
API sample uses the following reactive logic, which provides the behavior to roll up costs and check budget:
ConfOffersRules.png
Application Integration - Alert Management
Microservices architecture recommends that systems be autonomous, with decreased dependencies on other systems. This internal communication is by way of a message (rather than an API), so that the Conference Offers microservice functions even while Conference Management microservice is down.
The
Alert Management - JSON Message
event rule in the
Conference Offers
API sample implements this communication using MQTT messaging, as shown in the following code snippet:
var title = "ConfOffer Alert: ";
if (row.Approved === true && row.Approved !== oldRow.Approved) {
var msgContent = logicContext.transformCurrentRow('ManagementAlert');
var result = SysUtility.publishMessage("PublishManagementConnection","ProcessChargesTopic", msgContent, null);
msgContent = logicContext.transformCurrentRow('PartnerConfirmation');
if (row.PartnerURL === null) {
ConfLib.db(title + "No Partner URL, not confirming this back to partner: " + msg.Content.substring(1,32) + else { SysUtility.restPost(row.PartnerURL, {}, row.PartnerAuth, msgContent); }
}
This code creates a message that is formatted for accounting using the
logicContext.transformCurrentRow()
method. It sends the message by way of an MQTT connection using the
SysUtility.publishMessage()
method.
The
Conference Offers
API sample includes the following versions of the
Alert Management
event rule:
  • The
    Alert Management - XML Message
    event rule: Illustrates how to send JSON. It contains comments showing how to send XML, instead.
  • The
    Alert Management - API
    event rule: Illustrates how to send using an API instead of a message.
Activate only
one
of the event rules.
You can explore the listener code in the
Conference Management
API sample.
Data Integration - Multi-database Logic
The previous code snippet also POSTs a message back to the partner, confirming conference participation. The request content is formatted by using the
PartnerConfirmation
table-based resource for mapping and transformation. This resource integrates multiple databases. It includes the
ProgramName
and
Description
parent resource attributes from the
MarketingProgram
entity of the
ConfManagement
database, joined by a virtual foreign key, as illustrated in the following image:
confOffer_PartnerConfirmation.png
Layer7 Live API Creator
validates the marketing program using this virtual foreign key. This system defines
conditional referential integrity
(only required for approved conference participation offers), as illustrated in the following image of the
Approval requires Marketing Program
validation rule in the
Conference Offers
API sample:
Screen Shot 2018-05-16 at 7.19.55 AM.png
Validate the Conference Offers API Sample
Post Conference Data to an API Endpoint
As a partner, you want to post your conference data to the Conference Offers microservice. You can load sample conference data by posting it using a resource.
Follow these steps:
  1. With the
    Conference Offers
    API sample open, in the Tools section, click
    REST Lab
    .
  2. Select
    Resource
    as the endpoint, and then select the
    PartnerPost
    resource.
  3. Enter the data that is in the Learning Center into the
    Request Area
    . Go to the Learning Center, click the
    Example
    tab, and then click the
    Post Data
    step that is in the workflow. You might need to scroll down the page.
  4. Click
    POST
    .
  5. Verify that the response contains the
    statusCode 201
    message.
    This message confirms that the data is posted.
View and Update Conference Selections
As an organizer, you want to select the talk or exhibit options that you want to attend for a given conference.
Follow these steps:
  1. In the Execute section, click
    Data Explorer
    .
    Data Explorer opens in a new browser tab.
  2. Log in to Data Explorer.
    On the toolbar,
    Entities
    is selected as the endpoint type in the endpoint type drop-down by default.
  3. Verify that you can see conference, talks, and exhibits posted to the Conference Offers microservice.
  4. On the toolbar, select
    main:Conferences
    as the entity you want to view in the Main Grid from the endpoints drop-down.
    The Talks and Exhibits child tables are displayed as tabs in the Child Grid.
  5. Select the
    App Economy World
    conference by clicking the conference row in the Main Grid.
  6. In the Form, update the
    Budget
    field to 10,000, and then click
    Save
    .
  7. With the
    App Economy World
    conference selected, in the Child Grid, select the talk or exhibit options that you want to attend by selecting the
    Use
    checkbox for those talks or exhibits, and then click
    Save
    .
The two sum rules that are defined for the Conferences table calculate the accrued costs in the
Exhibit Costs
and the
Talk Costs
fields in the Form. The
Budget Check
commit validation rule ensures that the sum of exhibits cost and talks cost do not exceed the budget for the conference.
Layer7 Live API Creator
automatically invokes this reactive logic.
Approve Conferences
As a manager, you want to approve the talk or exhibit options that the organizers select.
Follow these steps:
  1. In Data Explorer, on the toolbar, select
    Conferences
    as the entity that you want to view in the Main Grid from the endpoints drop-down.
  2. In the Main Grid, select the
    App Economy World
    conference as the row for which you want to call the
    Approve
    function.
  3. Approve a conference by completing
    one
    of the following:
    • In the Main Grid, select the
      Approved
      checkbox, and then click
      Save
      .
    • In the Form, call the
      Approve
      function on the
      Conferences
      table by selecting the
      Approve
      function from the functions drop-down.
      This drop-down is located on the upper right of the Form. For more information about this drop-down, see Data Explorer.
Observe that the
Alert Management - JSON Message
event rule fires with the approved value change.
Layer7 Live API Creator
automatically invokes this reactive logic.
Conference Management Microservice
Process Messages
The Conference Management microservice processes the messages that the Conference Offers microservice publishes. The
Conference Management
API sample illustrates a common pattern in message processing.
Layer7 Live API Creator
system components process MQTT messages using the following workflow:
Connection
Approach
  1. Incoming message
Explore the
ProcessChargesListener
MQTT listener, which has the following JavaScript code:
var title = "conf-management Listener (1): ";
try { // persist payload
var postPayloadResponse = listenerUtil.restPost(Config.settings.resourceURL + "/ProcessChargesResource",
{}, Config.settings.authHeader, message.toString());
print(title + "Payload Processed, postPayloadResponse: " + postPayloadResponse + "\n\n");
} catch(e) {
print (title + "post exception: " + e);
throw title + "post exception: " + e;
}
2.
ProcessChargesResource
resource processing - mapping
The
ProcessChargesResource
resource defines the resource/row mapping.
Layer7 Live API Creator
automatically does the processing (persistence, mapping, and business rules). You do not have to code.
3. Logic execution
Layer7 Live API Creator
executes the logic that is associated with the underlying tables.
4. Error retry
But what if, for example, the update violates a rule, such as the
Active Marketing Program
rule? You can correct the situation (for example, define a marketing program), then set the
ProcessedStatus
row to retry the transaction. Use the
retryPayload
function to retry and reprocess any pending.
Advanced Configuration
The following topics provide advanced configuration details.
Scaling Your Integration - Store Incoming Messages
You can extend this integration solution to scale and handle a high load at any given time. As the
ProcessChargesListener
MQTT listener receives incoming messages, it stores them into the
SystemQueue
table so that CA Live API Creator can process them asynchronously. This approach ensures that your solution can scale to process, receive, and store incoming messages without any delays and data loss:
  • SysScalableQueue Error HijackEvent
    error pipeline:
    Used to intercept POSTs to the
    ProcessChargesResource
    resource, this request pipeline persists messages to the
    SystemQueue
    table endpoint.
  • SysTimerSystemQueue
    timer:
    Scheduled to periodically process incoming messages that are stored in the
    SystemQueue
    table, POSTs
    SystemQueue
    rows to the
    ProcessChargesResource
    resource.
For more information:
  • About how to scale your integration with this implementation pattern that uses a
    SystemQueue
    table and a timer for processing, see the final step, Process Message in the
    Learning Center - Example
    tab that is in the Learning Center.
  • About other request pipeline patterns that can apply to your integration, see the available request pipelines that start with
    Sys*
    in the
    Conference Management
    API sample.
Follow these steps:
  1. In the
    ProcessChargesResource
    resource, update the extended properties by setting the
    Async
    attribute from
    SystemQueue Disabled
    to
    SystemQueue Enabled
    , and then click
    Save
    . The following code block shows an example of the JSON for the extended properties:
    {
    "IgnoreColumns":
    true
    ,
    "AppendGroups":
    "Cost"
    ,
    "Async":
    "SystemQueue Enabled"
    ,
    "ignore":
    "status!== APPROVED"
    }
    For more information about how to define extended properties for a resource, see Manage the Extended Properties for Resources.
  2. In the
    SysTimerSystemQueue
    timer, activate the timer by selecting the
    Active
    checkbox, and then click
    Save
    .
This solution is enabled.
Outboarded Constants using Property Files
In step 2 of the process MQTT messages workflow, request pipeline resource processing, note the use of the
Config
variable. This variable is defined in the
ConfManagementLib
JavaScript library so that constants are defined once and not embedded in the code. Further, the values are loaded from a properties file using the
ConfManagementStartup
startup listener.
For more information about how to access Java system properties, see Access Java System Properties from JavaScript Code.