Skip to content

Guide to integrating a custom gRPC service with the Measurement Plug-In, featuring a logger service to demonstrate the integration process.

License

Notifications You must be signed in to change notification settings

ni/measurement-plugin-service-extension-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Measurement Plug-In Service Extension Example

Custom gRPC Service in Measurement Plug-In

The Measurement Plug-In architecture is built on a microservices model, with each component functioning as a gRPC service. As a network-based protocol, gRPC enables these components to be language-agnostic, allowing seamless interoperability across diverse programming environments. This approach ensures that any feature extensions or customizations can also be implemented as gRPC services.

A user-defined gRPC service is a custom service in which you specify service methods and message types in a .proto file, generate client and server code, and implement the server logic. Registering this service with the NI Discovery Service enables various clients to access and communicate with it over gRPC, simplifying integration across technology stacks.

This repository includes a sample logger service that demonstrates how a typical data logger can be made into a gRPC service. By registering this gRPC-based logger with the NI Discovery Service, the provided examples showcase seamless integration, enabling all measurement plug-ins, regardless of language (e.g., Python, LabVIEW, or C#), to access the logger service and record measurement during execution.

Required Software

Package dependencies:

User flow

User flow

Steps to create and register a custom gRPC service

  • The flowchart below outlines the steps for creating a custom gRPC service and registering it with the NI Discovery service.

    Register service

  1. Define the gRPC Service and implement the Server:
    • Begin by defining a .proto file to specify the service structure and data types, following the instructions provided here.
    • Generate the client and server code based on the .proto file.
    • Implement the gRPC server using the generated code.
    • Refer to the repository for an example of gRPC server initialization here.
  2. Register the Service with the NI Discovery Service:
    • Use the discovery client from the Python or LabVIEW service package to register the user-defined service with the NI Discovery Service, providing its location details. This registration enables the service to be accessed and utilized within measurement plug-ins.
    • See the example implementation of the logger service for reference.

Note

  • It is recommended to use the NI Discovery Service for dynamic service location resolution instead of relying on a static port number. Static port numbers can lead to conflicts and are less adaptable to changes in the network environment.
  • Dynamically resolving the service's port number allows for services to be relocated or scaled across multiple machines without the need to modify client configurations. This approach results in more robust and maintainable deployments.

Creating Clients for the custom gRPC Service

  • The flowchart below details the steps necessary to integrate a user-defined service into the measurement service.

    Resolve logger service

Python

  • Generate the client stubs for the user-defined service.
  • Refer to the instructions provided here to create a stub.
  • Create a client module to establish a connection with the user-defined service from the python measurements.
  • Define Service Interface and Service Class Names inside the module.
  • Create a class that abstracts the methods from the generated client stubs to interact with the service.
  • Resolve the service location using the discovery client.
  • Establish a gRPC channel to the service and create a stub for making API calls.
  • Define methods in the client class to call the service methods, constructing and sending requests as needed.
  • Example: logger_service_client.py.

LabVIEW

  • Install gRPC and LabVIEW gRPC Server and Client tool packages.

    • Refer to this document for installation instructions.
  • Generate client interfaces from the .proto file to communicate with the service methods using the gRPC Server-Client [2] - Code Generator.

    gRPC Server Client Generator

  • Establish the connection to communicate with the service methods.

  • Create client VIs under a common class to interact with the user-defined service from LabVIEW measurements.

  • Develop a client VI to initially establish a connection between the service and the measurement.

    • Define Service Interface and Class Names:

      • Provide the gRPC service interface and class names as inputs to the Resolve Service API to retrieve the port where the user-defined service is running.
    • Create a Discovery Client:

      • Instantiate a DiscoveryClient to resolve the service location.
    • Example:

      Establish Connection

  • In addition to establishing the connection, create a VI to call the service APIs using the gRPC ID obtained from the output of the previous VI.

    • Use the client generated during the stub creation process to call the service APIs.

    • The client then calls the Service APIs by obtaining the request models from the measurement service.

    • Example:

      Call Service Methods

  • Finally, Create a VI to ensure that the client is properly closed without any open connections and all associated resources are released for the client.

    • Example:

      Call Service Method

About

Guide to integrating a custom gRPC service with the Measurement Plug-In, featuring a logger service to demonstrate the integration process.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published