# FlowSync

FlowSync implements synchronous request handling for HTTP server nodes and OPC UA server nodes within Connectware. When activated, Connectware suspends response generation until a corresponding MQTT message is received, enabling synchronized processing across different protocols and systems. This enables a closed communication loop between machines and IT systems, confirming every step of the data journey – even when errors occur.

You can customize the behavior of FlowSync through configuration:

* Define custom timeout durations for request-response cycles
* Configure default timeout messages returned to clients
* Specify custom error messages for different error scenarios

FlowSync is part of the [Cybus:Node](/1-10-1/documentation/services/service-commissioning-files/resources/cybus-node.md) resource.

## Processing Flow

The following outlines the data flow from initial request to completion.

{% stepper %}
{% step %}
**Initial Request Reception**

When a request (HTTP or OPC UA) arrives at the server endpoint:

* The request remains open rather than returning an immediate response
* The system publishes an MQTT message on the `/treq` topic. The published data has the following structure:

{% code lineNumbers="true" %}

```json
{
  "id": "cb75f252-ebd8-4b33-b39d-b74953c6c99c",
  "timestamp": 1733219059372,
  "value": { ... }
}
```

{% endcode %}

* A unique identifier is generated and embedded in the message payload
  {% endstep %}

{% step %}
**Transaction Completion**

Upon receiving the MQTT response message, the system:

* Correlates it with the original request using the unique identifier
* Processes the response data on the `/tres` topic. The received data has the following structure:

{% code lineNumbers="true" %}

```json
{
  "id": "cb75f252-ebd8-4b33-b39d-b74953c6c99c",
  "timestamp": 1733219059372,
  "value": { ... }
}
```

{% endcode %}

* Completes the original protocol-specific request

The transaction remains active until either:

* A valid MQTT response is received
* The configured timeout period expires
  {% endstep %}
  {% endstepper %}

## Enabling FlowSync

FlowSync functionality is controlled through the node resource configuration in your service commissioning files.

* To implement synchronous processing, set the `operation` property of a [Cybus:Node](/1-10-1/documentation/services/service-commissioning-files/resources/cybus-node.md) resource to `transaction`:

{% code lineNumbers="true" %}

```yaml
node:
    operation: transaction
```

{% endcode %}

## FlowSync Example Files

The following sections provide practical examples of service commissioning files that demonstrate how to implement FlowSync with both HTTP and OPC UA connections. Each example includes a complete configuration along with explanations of key aspects to help you understand and adapt FlowSync for your specific needs.

* [Example 1 - Node with Transaction Mode (HTTP)](/1-10-1/documentation/services/flowsync/flowsync-example-1.md)
* [Example 2 - Node Responds (HTTP)](/1-10-1/documentation/services/flowsync/flowsync-example-2.md)
* [Example 3 - Node with Error (HTTP)](/1-10-1/documentation/services/flowsync/flowsync-example-3.md)
* [Example 4 - Node with Timeout Error Code and Error Message (HTTP)](/1-10-1/documentation/services/flowsync/flowsync-example-4.md)
* [Example 5 - Full Flow (HTTP)](/1-10-1/documentation/services/flowsync/flowsync-example-5.md)
* [Example 6 - Full Transactional Data Flow (OPC UA)](/1-10-1/documentation/services/flowsync/flowsync-example-6.md)


---

# 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://docs.cybus.io/1-10-1/documentation/services/flowsync.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.
