Sample Publisher Apps

Publisher apps consists of the following:

C++ Publisher

The C++ publisher and server are supported in Ubuntu operating systems or docker images. The C++ publisher runs in the independent containers as ia_ubuntu_cpp_sample_pub.

Go Publisher

The Go publisher and server are supported in Ubuntu operating systems or docker images. The Go publisher runs in the independent containers as ia_ubuntu_go_sample_pub.

Python Publisher

The Python publisher and server are supported only in Ubuntu operating systems or docker images. The Python publisher runs in the independent containers ia_ubuntu_python_sample_pub.

Note

The sample publisher container comprises of both the publisher and the server functionality.

High-level Logical Flow for Sample Publisher Apps

The high-level logical flow of a sample publisher app is as follows:

  1. Sample apps use the ConfigMgr([WORK_DIR]/IEdgeInsights/common/libs/ConfigMgr/src/cfgmgr.c) APIs to construct the msgbus config from the ETCD. It fetches its private key and the allowed client’s public keys. Then it creates the publisher object and starts publishing the sample data at a given topic (topic name: publish_test).

  2. The server contacts the ETCD service and fetches its private key and the allowed client’s public keys. Then it creates a server object according to the given service name and waits for the client’s request.

Steps to Independently Build and Deploy Samples Publisher Service

Note

For running 2 or more microservices, we recommend users to try the use case-driven approach for building and deploying as mentioned at Generate Consolidated Files for a Subset of Edge Insights for Industrial Services

Steps to Independently Build Samples Publisher Service

Note

When switching between independent deployment of the service with and without config manager agent service dependency, one would run into issues with docker compose build w.r.t Certificates folder existence. As a workaround, run the command sudo rm -rf Certificates to proceed with docker compose build.

To independently build Samples publisher service, complete the following steps:

  1. The downloaded source code should have a directory named Samples:

    Enter into the AppContext by selecting the <language> and <linux_flavor> of your choice in the following command:

    cd IEdgeInsights/Samples/publisher/<language>/<linux_flavor>
    

    NOTE: <language> can be either cpp, go or python and <linux_flavor> is ubuntu. Ensure to select <linux_flavor> as ubuntu. If the <language> is python as the Python publisher and server are supported only in Ubuntu operating systems or docker images.

  2. Copy the IEdgeInsights/build/.env file using the following command in the current folder

    cp ../../../../build/.env .
    

    NOTE: Update the HOST_IP and ETCD_HOST variables in the .env file with your system IP.

    # Source the .env using the following command:
    set -a && source .env && set +a
    
  3. Independently build

    docker compose build
    

Steps to Independently Deploy Samples Publisher Service

You can deploy the Samples publisher service in any of the following two ways:

Deploy Samples Publisher Service without Config Manager Agent Dependency

Run the following commands to deploy Samples publisher service without Config Manager Agent dependency:

# Enter the AppContext
cd IEdgeInsights/Samples/publisher/<language>/<linux_flavor>

Copy the IEdgeInsights/build/.env file using the following command in the current folder, if not already present.

cp ../../../../build/.env .

Note: Ensure that docker ps is clean and docker network ls must not have EII bridge network.

Update .env file for the following:
1. HOST_IP and ETCD_HOST variables with your system IP.
2. `READ_CONFIG_FROM_FILE_ENV` value to `true` and `DEV_MODE` value to `true`.

Source the .env using the following command:
set -a && source .env && set +a
    # Run the service
docker compose -f docker-compose.yml -f docker-compose-dev.override.yml up -d

Deploy Samples Publisher Service with Config Manager Agent Dependency

Run the following commands to deploy Samples publisher service with Config Manager Agent dependency:

Note

Ensure that the Config Manager Agent image present in the system. If not, build the Config Manager Agent locally when independently deploying the service with Config Manager Agent dependency.

# Enter the AppContext
cd IEdgeInsights/Samples/publisher/<language>/<linux_flavor>

Copy the IEdgeInsights/build/.env file using the following command in the current folder, if not already present.

cp ../../../../build/.env .

Note: Ensure that docker ps is clean and docker network ls doesn’t have EII bridge networks.

Update .env file for following:
1. HOST_IP and ETCD_HOST variables with your system IP.
2. `READ_CONFIG_FROM_FILE_ENV` value is set to `false`.

Copy the docker-compose.yml from IEdgeInsights/ConfigMgrAgent as docker-compose.override.yml.

cp ../../../../ConfigMgrAgent/docker-compose.yml docker-compose.override.yml

Copy the builder.py with standalone mode changes from IEdgeInsights/build directory

cp ../../../../build/builder.py .

Run the builder.py in standalone mode, this will generate eii_config.json and update docker-compose.override.yml

python3 builder.py -s true

Build the service (This step is optional for building the service if not done in the Independently buildable step).

docker compose build

Run the service in PROD mode, ececute the following command:

NOTE: Ensure to update DEV_MODE to false in .env while running in PROD mode and source the .env using the command set -a && source .env && set +a.

docker compose up -d

Run the service in DEV mode, execute the following command:

NOTE: Ensure to update DEV_MODE to true in .env while running in DEV mode and source the .env using the command set -a && source .env && set +a.

docker compose -f docker-compose.yml -f docker-compose-dev.override.yml -f docker-compose.override.yml up -d