Set up Key Rewrite
This guide illustrates how to set up the Key Rewrite feature in the StreamX Mesh.
You can find exhaustive information about Key Rewrite feature in StreamX Key Rewrite reference.
Prerequisites
Ensure you have the following before proceeding:
-
Approximately 15 minutes to complete the setup
-
A predefined
Mesh.yaml
file for StreamX -
A web browser of your choice.
A simple Mesh.yaml and knowledge on how to serve web resources with StreamX you can gain with Create a simple website with StreamX CLI tutorial.
|
Step 1: Provide match-rewrite patterns pair
Consider an example, where the input system generates data with resource key:
"blog-entries/2023-05-12/food/john-smith/page.html"
.
You want to modify this key to simplify resource identification in StreamX. The rewritten publication key should look like this:
"blogs/food/john-smith/page.html"
.
The goal is to:
-
change the part
"blog-entries"
to"blogs"
, -
remove the date from the key,
-
make key rewrite only for
.html
keys.
To achieve this, prepare match-rewrite patterns. For the given example:
-
match pattern:
"^blog-entries/([^/])/(.*)\\.html$"+
, -
rewrite pattern:
"blogs/$2.html"
.
Step 2: Configure Key Rewrite
The transformation can be achieved by passing environment variables into StreamX Rest Ingestion. You must use given properties to setup match an rewrite pattern:
ingestion:
rest-ingestion:
environment:
STREAMX_INBOXES_KEY-REGEX-REWRITE_PATTERNS_CONFIG1_MATCH-PATTERN: "^blog-entries/([^/]+)/(.*)\\.html$"
STREAMX_INBOXES_KEY-REGEX-REWRITE_PATTERNS_CONFIG1_REWRITE-PATTERN: "blogs/$2.html"
Step 3: Validate StreamX
To validate your StreamX setup, you can publish a simple website with a blog entry and check whether the entry is published with the rewritten resource path.