How to run a Microservice Route - 6.5

Talend Data Fabric Studio User Guide

EnrichVersion
6.5
EnrichProdName
Talend Data Fabric
task
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This section will show you how to run a Route that is built as a Spring-boot based Microservice.

To run a Route that is exported as a .jar file, proceed as follows in a console window:

  1. Change to the directory where the Microservice .jar file is located.

  2. Type in the following command. For more information about the Spring Boot properties, see the site http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html. Note that not all of the properties listed on the web page are applicable to the ESB Microservice. It depends primarily on the features that are included by Talend and also the Routes you build.

    java -jar <ArchiveFileName> --<SpringBootProperty>

    For example, the following command executes a Microservice named demoRoute.0.1.jar using an environment property that is configured in the file Prod, where Prod is also the Talend context name. This parameter needs to be specified to switch between context properties.

    java -jar demoRoute.0.1.jar --spring.config.name=Prod

    By default, when running the Microservice Route, it calls the configuration files in the /config folder inside the Microservice jar. You can switch to an external configuration folder where the configuration files are located using the spring.config.location property. For example, the following command executes the Microservice named demoRoute.0.1.jar using the configuration files in the config folder in the directory where the Microservice jar is located.

    java -jar demoRoute.0.1.jar --spring.config.location=./config

To run a Route that is exported as a .zip file, proceed as follows:

  1. Extract the .zip file in the directory of your choice.

  2. Go to the <RouteName> folder that contains the external config folder, the Microservice .jar file, and the start scripts to start the Microservice for Linux (.sh) and Windows (.bat).

  3. Edit the configuration files in the config folder as needed and run the .sh file on Linux or the .bat file on Windows to start the Microservice with the external configurations.

If the Route contains the cSOAP or cREST component, and if one or more of the ESB infrastructure services are used, you need to do the following when running the Microservice Route:

  • If the Service Activity Monitor is enabled, start the Service Activity Monitoring Server in a Runtime container before running the Microservice Route. For more information, see the relevant section in the Infrastructure Services Configuration Guide.

  • If the Service Locator is enabled, start the Service Locator Server in a Runtime container before running the Microservice Route. For more information, see the relevant section in the Infrastructure Services Configuration Guide.

  • If the Route is a service provider and the Authentication with HTTP Basic is enabled, specify the user credentials when running the Microservice Route:

    java -jar <ArchiveFileName>.jar --security.user.name=<USERNAME> -- security.user.password=<PASSWORD>
  • If the Authentication with the SAML Token is enabled, you need to start the STS service in a Runtime container before running the Microservice Route. For more information, see the relevant section in the Infrastructure Services Configuration Guide.

  • If the Authentication with the SAML Token, and Authorization is enabled, before running the Microservice Route,you need to:

    • install and start the Talend Identity Management Service, and create users and roles in it. For more information, see the relevant section in the Talend Installation Guide and the Infrastructure Services Configuration Guide.

    • start the STS service in a Runtime container. For more information, see the relevant section in the Infrastructure Services Configuration Guide.

    • start the Authorization service in a Runtime container. For more information, see the relevant section in the Infrastructure Services Configuration Guide.

    • start the Talend Administration Center and configure the XACML policy in the Authorization page. For more information, see the relevant section in the Talend Administration Center User Guide.

  • If the Service Registry is used, you need to:

    • start the related infrastructure service according to the WS-Policy in use. For more information, see the relevant section in the Infrastructure Services Configuration Guide.

    • start the Talend Administration Center, and add the service WSDL and the WS-Policy into the Service Registry from the Service Registry page. For more information, see the relevant section in the Talend Administration Center User Guide.

For more information about the cSOAP or cREST component, see Talend Help Center.

For more information about how to build a Route to a ESB Microservice, see How to build a Route to a Spring-boot based ESB Microservice.

An example of running a Microservice Route using external Log4j configuration

This section will show you an example of how to run a Microservice Route using external Log4j configuration.

The Microservice is built from a simple Route containing a cTimer and cLog component.

The cTimer component will trigger the message exchange five times.

The cLog component will log the message exchanges. The logging level is set to WARN, which is the default configuration of the Studio.

When running the Route in the Studio, the following result is shown in the execution console.

After building the Route to the Microservice .jar file, you can run it in a console window:

  • To run the Microservice with the default configuration, use the following command:

    java -jar demo_0.1.jar

    The following log messages are shown, which is the same as the execution result in the Studio.

  • To run the Microservice with a custom Log4j configuration, you can use the spring.config.location property to call the customized log4j.xml file in an external configuration folder. A sample Log4j configuration which is located in the config folder in the directory of the Microservice jar is shown below to provide a tesb.log file when the Microservice is started.

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
        <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d | %-5.5p | %-16.16t | %-32.32C %4L | %m%n"/>
            </layout>
        </appender>
        <appender name="rollingFile" class="org.apache.log4j.RollingFileAppender">
            <param name="file" value="tesb.log"/>
            <param name="MaxFileSize" value="1024KB"/>
            <param name="MaxBackupIndex" value="10"/>
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d | %-5.5p | %-16.16t | %-32.32C %4L | %m%n"/>
            </layout>
        </appender>
        <root>
            <priority value="info"/>
            <appender-ref ref="stdout"/>
            <appender-ref ref="rollingFile"/>
        </root>
    </log4j:configuration>

    To use this configuration, run the following command:

    java -jar demo_0.1.jar --spring.config.location=./config

    Alternatively, you can use the logging.config property to call the Log4j configuration file:

    java -jar demo_0.1.jar --logging.config=./config/log4j.xml

    The following log messages are shown, and written to the tesb.log file in the directory where the Microservice jar file is located.

    The tesb.log file is created:

    The log messages are written to the tesb.log file: