Implementation:Tensorflow Serving static source router h
| Knowledge Sources | |
|---|---|
| Domains | Model Serving, Core Framework |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
StaticSourceRouter is a SourceRouter with statically configured output ports that routes items based on cascading substring matching against the servable name.
Description
StaticSourceRouter<T> extends SourceRouter<T> and provides N output ports configured at creation time with N-1 substrings. Routing uses a fall-through (cascading) strategy: items whose servable name contains substring 0 are routed to port 0; items that do not match substring 0 but match substring 1 are routed to port 1; and so on. Items that match none of the substrings are routed to the last port (port N-1), which serves as the default route.
The substring matching uses str_util::StrContains() for simple substring detection. The configuration is immutable after creation; unlike DynamicSourceRouter, routes cannot be updated at runtime.
The router is created via the static Create() factory method, which takes a vector of substrings and returns a router with substrings.size() + 1 output ports.
Usage
Use StaticSourceRouter when routing decisions can be made by substring matching against servable names and the routing configuration does not need to change at runtime. This is suitable for scenarios where servable types are distinguished by naming conventions (e.g., paths containing "apple" vs. "orange").
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/core/static_source_router.h
- Lines: 1-104
Signature
template <typename T>
class StaticSourceRouter final : public SourceRouter<T> {
public:
static Status Create(const std::vector<string>& route_substrings,
std::unique_ptr<StaticSourceRouter<T>>* result);
~StaticSourceRouter() override;
protected:
int num_output_ports() const override;
int Route(const StringPiece servable_name,
const std::vector<ServableData<T>>& versions) override;
};
Import
#include "tensorflow_serving/core/static_source_router.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| route_substrings | const std::vector<string>& | Yes | Substrings for cascading match; creates substrings.size()+1 output ports |
Outputs
| Name | Type | Description |
|---|---|---|
| Create() | Status | Always OK; constructs the router |
| Route() | int | Port index of the first matching substring, or the last port (default) if none match |
Usage Examples
Creating a StaticSourceRouter
#include "tensorflow_serving/core/static_source_router.h"
using namespace tensorflow::serving;
// Route "apple" servables to port 0, "orange" to port 1,
// and everything else to port 2 (default)
std::vector<string> substrings = {"apple", "orange"};
std::unique_ptr<StaticSourceRouter<StoragePath>> router;
TF_CHECK_OK(StaticSourceRouter<StoragePath>::Create(substrings, &router));
auto ports = router->GetOutputPorts();
// ports.size() == 3
// ports[0] receives servables with "apple" in name
// ports[1] receives servables with "orange" in name (but not "apple")
// ports[2] receives all other servables