---
title: Use the Batch-Write Topic to Send Multiple Write Requests
slug: manufacturing-connect-edge/use-the-batch-write-topic-to-send-multiple-write-requests
docTags: 
createdAt: 2023-09-27T15:19:30.356Z
---

:::hint{type="info"}
**Notes**:

- You need to follow the following guidelines for topic names: [Subject-Based Messaging](https://docs.nats.io/nats-concepts/subjects).&#x20;
- When publishing structured data such as JSON, you must convert to a byte array (string) first. To do this in a flow, you can use the **json&#x20;**&#x6E;ode.&#x20;
:::

You can use the Batch-Write topic to send multiple write requests simultaneously.&#x20;

:::hint{type="warning"}
**Important**:

- Only Gen 2 drivers can use batch write topics. See the [Industrial Systems Connection Guide](docId\:yQ2ITUsJpvlgkS50KRQ1R) to review available Gen 2 drivers.&#x20;
- If **Enable Alias Topics** is selected in the device configuration, then the *DeviceName&#x20;*&#x61;nd *TagName&#x20;*&#x70;arameters need to be used for setting up batch-write topics. If Enable Alias Topics is not selected, then *deviceID&#x20;*&#x61;nd *registerID&#x20;*&#x6E;eed to be used. See [Connect a Device](docId\:nm1lQfefyA-DSIfFitIty) and [Manage Devices](docId:-4FmeEhFoYMsfb2ZBrX8x) for more information.&#x20;
:::

# User Scenario

Manufacturing Connect Edge collects process data on a PLC, and the setpoint values for the PLC are continuously re-calibrated. These new setpoints and other control values can be collected and sent in one request through the Batch-Write topic.&#x20;

# Set Up and Use the Batch-Write Topic

Complete the following tasks to use the Batch-Write topic.&#x20;

## Before You Begin

We will be using the *DeviceName&#x20;*&#x61;nd *TagName&#x20;*&#x70;arameters to set up the device. If you don't enable Alias topics for the device, you will need to use the *deviceID&#x20;*&#x61;nd *registerID&#x20;*&#x70;arameters. To get the registerIDs, you will need to set up a flow and view the payload of the device.&#x20;

## Step 1: Connect Device

Follow the steps to [Connect a Device](docId\:nm1lQfefyA-DSIfFitIty) and configure the following parameters:

- **Device Type**: Simulator
- **Driver Name**: Generator
- **Enable Alias Topics**: Select the checkbox.&#x20;

## Step 2: Add Tags

After connecting the device, add the following tag. See [Add a Tag](docId\:h5heqIcXrCY3NCH9KBg9I) to learn more.&#x20;

### Tag 1

- **Name**: Select **M - Memory Register**
- **Value Type:** Select **int64**
- **Polling Interval**: Enter **10**
- **Tag Name**: Enter **Tag\_1**
- **Address**: Enter **1**

### Tag 2

- **Name**: Select **M - Memory Register**
- **Value Type:** Select **int64**
- **Polling Interval**: Enter **10**
- **Tag Name**: Enter **Tag\_2**
- **Address**: Enter **2**

### Tag 3

- **Name**: Select **M - Memory Register**
- **Value Type:** Select **int64**
- **Polling Interval**: Enter **10**
- **Tag Name**: Enter **Tag\_3**
- **Address**: Enter **3**

## Step 3: Collect Topic Names

You will need to copy and store the Manage topic and Alias topic for the device. You will use these topic names later on.&#x20;

**To collect the topic names:**

1. Navigate to **DeviceHub&#x20;**> **Devices**.&#x20;
2. In the Generator device tile, click the **Action menu**, click **Copy Topics**, and then select the Manage topic.  This will copy the Manage status topic. Save (paste) this topic somewhere secure.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/dQm5VDUMK_vaanvW88bAI_manage-topic.png" size="80" width="742" height="402" position="center" showCaption="false"}
3. Copy the Alias topic. You will refer to this topic later on. Save (paste) this topic somewhere secure.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/J9pyPUUw4-gl6wcxE59wT_alias-topic.png" size="80" width="742" height="402" position="center" showCaption="false"}

## Step 4: Create Flow

You will now create the Flow that will set up the batch-write topics.&#x20;

**To set up the Flow canvas:**

1. Navigate to **Flows Manager**.&#x20;
2. For a Flows Manager, click the **Go To Flow Definition** icon.&#x20;
   The Flow canvas opens in a new browser tab.&#x20;
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/8efL-pI_X_MfglKKMDl0e_go-to-flow-definitionmce.png" size="80" width="937" height="548" caption="Go To Flow Definition icon" position="center" showCaption="true"}
3. On the Flow canvas, drag the **DataHub Subscribe** node and **debug&#x20;**&#x6E;ode on the canvas and connect them. Then, drag the **inject&#x20;**&#x6E;ode and the **DataHub Publish** node onto the canvas and connect them. &#x20;
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/Shx9UdNx5PcnpI-CzhyQX_batch-write-four-nodes.png" size="80" width="922" height="536" caption="Set up the four nodes for batch write" position="center" showCaption="true"}
4. &#x20;Double-click the **DataHub Subscribe** node.&#x20;
   The *Edit DataHub Subscribe&#x20;*&#x6E;ode dialog box displays.
   - In the **Topic&#x20;**&#x66;ield, paste the Alias topic you copied previously.&#x20;
   - If needed, configure the Datahub Subscribe connection. See the *Step 3: Configure Connector Nodes* section in [Create a Flow](docId\:VeeOD3N3SLCAsdLEedZBr) to learn more.
   - Click **Done**, and then click **Deploy**.&#x20;
5. Double-click the inject node.&#x20;
   - For **msg.payload**, update the **timestamp&#x20;**&#x73;election and select **string**.
   - In the **string&#x20;**&#x66;ield, enter the payload in the following format: `{"TagName_1": value_1, "TagName_2": value_2, "TagName_3": value_3}`. Keep in mind that the order of the register IDs you configure is based on the address values you configured for the tags. `value_1`, `value_2`, `value_3` can be replaced with any value of your choosing.
   - For example, for this use case, the payload will be: `{"Tag_1": 11, "Tag_2": 22, "Tag_3": 33}`. The first register ID is the one configured with **Address&#x20;**&#x31; in the tag configuration, the second register ID is the one configured with **Address&#x20;**&#x32;, and the third register ID is the one configured with **Address&#x20;**&#x33;. `11`, `22`, `33` are values chosen for this example.
   - Click **Done**.&#x20;
6. Double-click the DataHub Publish node.&#x20;
   The *Edit DataHub Publish* node dialog box displays.
   - In the **Topic&#x20;**&#x66;ield, paste the Manage topic you copied previously. Then, replace `manage` in the topic with `batch_write`. For example, `devicehub.manage.simulator` is changed to `devicehub.batch_write.simulator`.
   - Click **Done**, and then click **Deploy**.&#x20;

You can now send the batch data to the device tags.&#x20;

## Step 3: Send Batch Data

**To send the batch data:**

1. Click the **inject&#x20;**&#x62;utton. This sends the data to all the tags configured in the inject node simultaneously. For this use case, the inject node sends the values 11, 22, and 33 to the three device tags.&#x20;
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/9hY_bkZ_RBmCL8J0Igo5i_batch-write-inject-button.png" size="80" width="1564" height="427" caption="The inject node button" position="center" showCaption="true"}
2. Wait up to 10 seconds for the next debug message. The three values display based on the **Address&#x20;**&#x61;nd **value&#x20;**&#x70;arameters you configured previously.&#x20;
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/5fUCh4bpouOO4c-SQosx3_batch-write-messages.png" size="80" width="1920" height="937" caption="The batch write messages" position="center" showCaption="true"}

