# Demo using Reader and Writer Block

## 1. Overview

This demo showcases a complete message lifecycle within the Guardian-based workflow:

1. Admin pre-configuration (Schema & Branch setup)
2. Topic creation and routing configuration
3. External message ingestion simulation
4. Schema validation and branch-based distribution
5. Data transformation, calculation, and persistence
6. Publishing to IPFS and a Hedera topic
7. Forwarding processed VCs to additional external topics

The objective is to demonstrate how Verifiable Credentials (VCs) are validated, routed dynamically based on business rules, processed independently per branch, and then published to distributed infrastructure and external systems.

## 2. Admin Pre-Configuration (Schema & Branch Setup)

### Objective

Demonstrate how an administrator configures validation and routing rules before runtime.

### Steps Demonstrated

#### 2.1 Reader Block Configuration

* The **Reader block** is opened in edit mode.
* Multiple **branches** are created to handle different commodity types:
  * `BEEF`
  * `DAIRY`

<figure><img src="/files/iL4IDaB0lu0vGvPlyDys" alt=""><figcaption></figcaption></figure>

#### 2.2 Schema Assignment

* A specific **schema** is assigned to the Reader block.
* This schema defines the required structure of incoming VC documents.
* Only VCs that conform to this schema are eligible for processing.

**Key Outcome**

* Any incoming VC must:
  1. Match the assigned schema.
  2. Contain the expected routing field (`commodityType`).
* If validation fails, the message is rejected before routing.

## 3. Topics and Routing Configuration

### Objective

Show how message channels are created and routing rules are defined.

### 3.1 Topic Creation (Reader & Writer Blocks)

#### Reader Block

* A new **input topic** is created.
* The topic is activated.
* It becomes the ingestion point for external VC messages.

<figure><img src="/files/vi42LNpc22jExoPk8Chf" alt=""><figcaption></figcaption></figure>

#### Writer Block(s)

* Output topics are created for:
  * Processed data publishing
  * Forwarding to second and third external topics

<figure><img src="/files/28YgPKFtqOgs0aMzTAyt" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/UkkggrxHoSdbKuGpGkaI" alt=""><figcaption></figcaption></figure>

Each topic is:

* Created
* Activated
* Connected to the appropriate block

### 3.2 Routing Rule Configuration

Routing logic is configured inside the Reader block:

* A specific field: `commodityType`
* Conditional routing:
  * If `commodityType = BEEF` → Route to BEEF branch
  * If `commodityType = DAIRY` → Route to DAIRY branch
* Routing only occurs after schema validation passes

<figure><img src="/files/xtuOGhB69dq5rlEimlwL" alt=""><figcaption></figcaption></figure>

## 4. External Input Simulation

#### Objective

Simulate a third-party system sending messages into the workflow.

### 4.1 External Block Usage

The **External block** simulates an outside system.

Two messages are sent:

1. Message 1 → `commodityType = BEEF`
2. Message 2 → `commodityType = DAIRY`

<figure><img src="/files/c5mnRVA34aGeeIge5u4W" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2MXS9KKQLwAtI8V47f2g" alt=""><figcaption></figcaption></figure>

### 4.2 Topic Confirmation

We confirm:

* Both messages are successfully written to the external input topic.
* Messages are visible in the topic explorer/log.
* No schema errors are triggered.

#### Result

The ingestion pipeline is functioning correctly.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guardian.hedera.com/guardian-dev/guardian/standard-registry/policies/multi-workflow-engine/demo-using-reader-and-writer-block.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
