How to: Use Spark XConnector service to connect a remote service
The process to set up a Spark XConnector service is similar to Call Spark services as functions (Xcall).
Configure the remote service
The sample remote service is publicly available without authentication. Please see Secure XConnector access with OAuth 2.0 tokens for information about secure remote services.
For this guide, a remote service has been configured with an Azure Function called species. The species remote service receives a table of animal types and returns a table of results for the species name, type, and countries.
Run the
curlstatement in your application of choice. The request body follows the format in Remote service request format.Remove entries under
["Type"]and run the command again.The list of species returned should change.
The response follows the format Remote service response format.
The species Azure Function can be built with this C# project.
Create a downstream Spark service with the remote service call
In Call Spark services as functions (Xcall), downstream services contain encapsulated calculations in Data. For XConnector, it only needs to contain the references to the remote service and the input / output specifications.
Open the Excel file.
The workbook has two tabs.
XConnector: Defines the location of the remote service.POST: Define the inputs and outputs to send to the remote service.
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.NameValueRefers toCommentXinput_type...=POST!$B$2:$B$7List of the species types. This range needs to be long enough to accept the maximum input length to the remote service.
Xoutput_results...=POST!$E$2:$G$102List of species received. This range needs to be long enough to accept the maximum output length from the remote service.
XPROPERTY_DefaultEngineTypeXConnector=XConnector!$B$4Sets the service type as
XConnectorin Spark.XPROPERTY_XConnectorServiceNamespecies=XConnector!$B$3Name of the remote service within the base URL.
XPROPERTY_XConnectorTargetUrlhttps://func-xconnector-sample.azurewebsites.net/api/=XConnector!$B$2Base URL for the remote resource. Must end with
/.
Note that this Excel workbook contains no formulas. Its purpose is only to define the location and layout of the remote service request and response.
Create a folder called
xconnectorsif it does not exist.Upload the Excel file for the downstream service into the folder.
Note that the API Tester and Execute API will not function directly on this service.
Create an upstream Spark service to invoke the downstream service
With Call Spark services as functions (Xcall), any Excel file can have access to the remote service. The upstream service makes the API request and receives the response from the downstream service.
Interact with XConnector in Excel
Open the upstream file
species-xcall.xlsxin Excel. The file includes aCS.SPARK_XCALLfunction toxconnectors/species.Load Coherent Assistant and sign in to the same environment and tenant.
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.NameValueRefers toCommentXinput_type...=Sheet1!$B$2:$B$7List of the species types. This range needs to be long enough to accept the maximum input length to the remote service.
Xoutput_count71=Sheet1!$T$2Number of species returned.
Xoutput_results...=Sheet1!$O$2:$Q$102List of species received. This range needs to be long enough to accept the maximum output length from the remote service.
Remove entries under the input
typeand the species returned will change.
Use the XConnector with an integration
When uploaded to Spark, the Excel file becomes an upstream service with access to the remote service.
Open the previously created
xconnectorsfolder.Upload the Excel file for the upstream service into the folder.
Use the API Tester to interact with the upstream service
species-xcall. For this to work properly, you must add the request_metaxconnector_parse_mode = 1.In API request (inputs), select Raw view.
In the
request_meta, add a comma,to the end of the last entry and then add"xconnector_parse_mode" = 1.
Remove entries under the input
typeand the species returned will change.If you would like to make any changes to the upstream service, edit the Excel file and re-test the
CS.SPARK_XCALLfunction with Coherent Assistant. Upload the Excel file again to update the service.
Two levels of calculations take place:
The downstream service calls the remote service to query the
speciesdata in the Azure Function.The upstream file receives the response and processes the response into the
CS.SPARK_XCALLoutput template. Any calculations within the upstream file are also calculated, such as theXoutput_count.
Considerations
If the
request_meta"xconnector_parse_mode" = 1is omitted, you will encounter issues handling anyXConnectorservices that return tables.Although Remote service request and response format specification supports multiple request records and response records at a time, the upstream Spark integration can only process one request at a time. In other words, the length of the
outputs,warnings,errors,process_timearray should be2elements only.Array Xcall for scaling is not supported with
XConnector.
Last updated
