# Overview

Service orchestration is a powerful function provided by the FizzGate integration platform. It can quickly generate an aggregate interface based on existing business microservices through online configuration, reducing middle-layer glue code and coding investment. Functions are supported in service orchestration. In this advanced tutorial, we will introduce data in three articles (Part 1: List expansion & merging, Part 2: List extraction & association, Part 2: List field renaming & field removal). Use of list functions.

This article is the first part of the service orchestration processing list data series.

# Function

Functions are a powerful and convenient function provided by service orchestration. By encapsulating some commonly used logic into functions, and using functions in service orchestration to process data in the service orchestration process, we can simplify our configuration and realize complex functions.

# Function classification

Version requirements: v2.3 or above

Functions start with fn., such as fn.date.timestamp(), date is the category, and the gateway has built-in functions of the following categories:

  • Public class fn.common
  • Date class fn.date
  • String class fn.string
  • Codec class fn.codec
  • Math fn.math
  • Data list class fn.list

# Reference value

Reference values are supported in functions, such as:

fn.string.concat({step1.result.channelCode},{step1.result.nonce})

{step1.result.channelCode} represents the reference value, which refers to the result of step1

fn.string.concat({step1.result.channelCode},{g.account.name})

{g.account.name} represents a reference value, which refers to the public resource "account.name". Starting with g represents a reference to a public resource.

# Nested calls

Supports multiple nested calls, such as:

fn.codec.md5(fn.date.add(fn.date.add("2021-07-09 22:44:55", "yyyy-MM-dd HH:mm:ss", 1, fn.math. addExact(999,1)), "yyyy-MM-dd HH:mm:ss", fn.math.addExact(0,1), 1000))
fn.string.toUpperCase(fn.codec.sha256(fn.string.concat({step1.result.channelCode},{step1.result.nonce},{step1.result.timestamp},{step1.result.appSecret}) ))

# Data list function

Function Return value type Purpose Parameter description
fn.list.expand(
List<List<Object>> data)
List<Object> Expand a two-dimensional array (list) into a one-dimensional array (list),
For example:
data=[[{a:1}],[{a:2}],[{a:3}]]
fn.list.expand(data)<br/ >Return: [{a:1},{a:2},{a:3}]
data: two-dimensional array (list)
fn.list.merge(
List<Object>... data)
List<Object> Merge multiple lists into one, such as:
data1=[{a: 1}]
data2=[{a:2}]
data3=[{a:3}]
fn.list.merge(data1,data2,data3)
Return :[{a:1},{a:2},{a:3}]
data: list, can be multiple
fn.list.extract(
List<Map<String, Object>> data,
String... fields)
List<Map<String, Object>> Extract only some fields in the list, such as:
data=[
{a:1,b:4,c:7},
{a:2,b:5,c :8},
{a:3,b:6,c:9}
]
fn.list.extract(data, "a", "c")
Return: [
{a:1,c:7},
{a:2,c:8},
{a:3,c:9}
]
data: list
fields: [optional] fields, there can be multiple
fn.list.join(
List<Map<String, Object>> dest,
List<Map<String, Object>> src,
String joinField,
String... fields)
List<Map<String, Object>> Merge 2 list fields, you can only merge specified fields, such as:
dest=[
{a:1,b:4,c:7},
{a:2,b:5,c:8},
{a:3,b:6,c:9 }
]
src=[
{a:1,d:444,e:777},
{a:2,d:555,e:888}<br/ />]
fn.list.join(dest,src, "a", "d")
Return: [
{a:1,b:4,c:7,d :444},
{a:2,b:5,c:8,d:555},
{a:3,b:6,c:9}
]
dest : Target list
src: The merged list
joinField: The field associated with the two lists
Format:
The associated field of the dest list: The
associated field of the src list , such as: userName:uname,
If the associated fields of the two lists are the same, you can
fill in only one, such as: userName
fields: [Optional] The fields that need to be merged in the merged list, Multiple fields are allowed. If left blank, all fields will be merged
fn.list.rename(
List<Map<String, Object>> data,
String... fieldPairs)
List<Map<String, Object>> Rename some fields in the list, such as:
data=[
{a:1,b:4,c:7},
{a:2,b:5,c :8},
{a:3,b:6,c:9}
]
fn.list.rename(data, "a:apple", "c:cat")
Return: [
{apple:1,b:4,cat:7},
{apple:2,b:5,cat:8},
{apple: 3,b:6,cat:9}
]
data: list
fieldPairs: [Optional] There can be multiple field pairs to be renamed
. Format:
Original field name: New field name, such as: c:cat
fn.list.removeFields(
List<Map<String, Object>> data,
String... fields)
List<Map<String, Object>> Delete some fields in the list, such as:
data=[
{a:1,b:4,c:7},
{a:2,b:5,c: 8},
{a:3,b:6,c:9}
]
fn.list.removeFields(data, "b")
Return: [
{a:1,c:7},
{a:2,c:8},
{a:3,c:9}
]
data: list<br/ />fields: [Optional]
fields to be deleted, there can be multiple

# Data preparation

# FizzGate integrated platform installation

Please refer to: https://www.fizzgate.com/fizz/guide/installation (opens new window)

# Underlying service interface

The source code of the underlying service interface called by the service orchestration in this article can be obtained from github (https://github.com/wehotel/fizz-examples). Clone the latest fizz-examples source code from github and start the fizz-examples-rest-api service.

aggr_fn_list_demo_backend_1

aggr_fn_list_demo_backend_2

In the management background (menu location: RPC Management->Service Statement) configure the service statement, as shown in the figure.

aggr_fn_list_demo_backend_3

# Added new orchestration interface

Management background, menu location: Service Edit->Interface List, click Add.

# List expansion fn.list.expand

This example calls the /fn-list/user-basic-info-list-by-roles/{roleList} interface of the underlying fizz-examples-rest-api service in the orchestration interface (interface source code: [FnListController](https:// github.com/wehotel/fizz-examples/blob/master/fizz-examples-rest-api/src/main/java/we/controller/FnListController.java)) to obtain the user’s basic information list and respond to this interface The data is list-expanded to fit our desired data format.

# Basic information

aggr_fn_list_expand_1

# Configuration input

In the configuration input, you can define the input parameters and request headers of the interface. If you do not configure the input parameters or request headers, the gateway will receive all input parameters or request headers from the caller as is, but will not do anything with the received parameters. check. In this example we do not need to enter parameters, leave them all blank.

# Configuration steps

Add a new step step1, and then add a request request1 in step step1. The service selects our pre-prepared fizz-examples-rest-api service and requests /fn-list/user-basic-info-list-by. -roles/developer,manager interface. If the configuration response part is left blank, the gateway will receive the result returned by the interface as is.fruit.

aggr_fn_list_expand_2

# Configure output

In the configuration output, we use step1.request1.response.body.* to reference the response result of the request in the configuration step (for the usage of related reference values, please refer to the document: [Data conversion usage document](https://www.fizzgate .com/fizz/guide/aggregate/configuration.html#%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%8D%A2)).

Configure the response message to be returned to the front end. Here, the response body is configured with the following fields:

code: reference type, the value is the code field of the response to request1 in step 1;

message: reference type, the value is the message field of the response to request1 in step 1;

data: reference type, the value is the data field of the response to request1 in step 1 and is expanded using the fn.list.expand function.

aggr_fn_list_expand_3

# test

Directly call /fn-list/user-basic-info-list-by-roles/developer, and the manager interface will get the response as shown in the figure.

aggr_fn_list_expand_4

The test interface gets the response as shown in the figure.

aggr_fn_list_expand_5

From the response of the test interface, we can see that the service orchestration interface has completed the request to the /fn-list/user-basic-info-list-by-roles/developer, manager interface and correctly expanded the list of the response data fields. .

# List merge fn.list.merge

This example calls the /fn-list/user-basic-info-list-by-roles/{roleList} interface of the underlying fizz-examples-rest-api service twice in the orchestration interface (interface source code: [FnListController](https: //github.com/wehotel/fizz-examples/blob/master/fizz-examples-rest-api/src/main/java/we/controller/FnListController.java)) to obtain the user’s basic information list and use the interface The response data of the two calls are list-merged to meet the data format we want.

# Basic information

aggr_fn_list_merge_1

# Configuration input

In this example we do not need to enter parameters, leave them all blank.

# Configuration steps

Add a new step step1, add a request request1 in step step1, select fizz-examples-rest-api as the service, and request the /fn-list/user-basic-info-list-by-role/admin interface. In step 1, add a new request request2, select fizz-examples-rest-api as the service, and request the /fn-list/user-basic-info-list-by-role/manager interface.

aggr_fn_list_merge_2

aggr_fn_list_merge_3

# Configure output

Configure the response message to be returned to the front end. Here, the response body is configured with the following fields:

code: reference type, the value is the code field of the response to request1 in step 1;

message: reference type, the value is the message field of the response to request1 in step 1;

data: reference type, the value is the data field of the response to request1 in step 1 and the data field of the response to request2 in step 1 and merge them using the fn.list.merge function.

aggr_fn_list_merge_4

# Test

The response obtained by directly calling the /fn-list/user-basic-info-list-by-role/admin interface is as shown in the figure.

aggr_fn_list_merge_5

The response obtained by directly calling the /fn-list/user-basic-info-list-by-role/manager interface is as shown in the figure.

aggr_fn_list_merge_6

The test interface gets the response as shown in the figure.

aggr_fn_list_merge_7

From the response of the test interface, we can see that the service orchestration interface has completed the request to the /fn-list/user-basic-info-list-by-role/admin interface and the /fn-list/user-basic-info-list -by-role/manager interface request and correctly merge the list of data fields in the responses of the two calls.

# Introduction to FizzGate Integration Platform

FizzGate is a microservice aggregation gateway developed based on Java. It can achieve hot service orchestration and aggregation, automatic authorization selection, online service script coding, online testing, high-performance routing, API audit management, callback management, etc., and has powerful customization The plug-in system can be expanded by itself and provides a friendly graphical configuration interface, which can quickly help enterprises manage API services, reduce middle-layer glue codes, reduce coding investment, and improve the stability and security of API services.

Official website: https://www.fizzgate.com (opens new window)

GitHub: https://github.com/fizzgate/fizz-gateway-node (opens new window)

Code cloud: https://gitee.com/fizzgate/fizz-gateway (opens new window)

Getting Started Tutorial: https://www.fizzgate.com/fizz/guide/GettingStarted/ (opens new window)

Advanced tutorial: https://www.fizzgate.com/fizz/guide/advanced/ (opens new window)


Author: ZHONG.J