Buffer values
Use dynamic buffer values for your step properties to generate them at runtime. If you need values of message elements within your virtual service more than once, use the Buffer property to temporarily save them. You can read these buffer values within the virtual service and insert them into another message element.
Create buffer values
To buffer a value, you need the following:
-
The buffer property with a buffer name to find the buffer values again. Buffer names aren't case-sensitive.
-
Optionally, you can use step rules properties to specify the part of a value that you want to reuse. For example, this could be a specific dynamic value, or it could be part of a path.
The buffer named myBuffer stores the value of the Path property. The property range specifies that you want to store only characters 1 through 5 of the Path property.
- name: Service02
steps:
- direction: In
trigger:
- uri: '*'
buffer:
- type: Path
name: myBuffer
range: 1..5
Read buffered values
To reuse a buffered value for a message element, use the Insert step property with the value {B[<buffer name>]}.
In this example, you run a service named Service02:
-
The inbound step contains two properties:
-
The trigger property to wait for a message containing any value as the value of the Path property.
-
The buffer property to create a buffer named myBuffer, which stores the value of the Path property. The range property specifies that you only want to store characters 1 to 5 of the Path property.
-
-
The outbound step property insert writes the value of the buffer named myBuffer into the payload.
schema: SimV1
name: buffer
description: set buffer and readout bufferd value
connections:
- name: myConnection
port: 8080
services:
- name: Service02
steps:
- direction: In
trigger:
- uri: '*'
buffer:
- type: Path
name: myBuffer
range: 1..5
- direction: Out
insert:
- value: '{B[myBuffer]}'
Read buffered values into the payload of a message
Typically, you need a path to insert a buffered value into a specific section of the message that you want to send. This can be a challenge with complex payloads, especially those with many special characters.
However, you can read a buffered value and insert it directly into the payload of a message using the payload property with the %{<buffer name>} syntax. You can insert the syntax anywhere in the payload text.
In this example, you run a service named Service02:
-
The inbound step contains two properties:
-
The trigger property to wait for a message containing any value as the value of the Path property.
-
The buffer property to create a buffer named myDate, which stores the value of the current date.
-
-
The outbound step writes the value of the buffer named myDate directly to the payload.
schema: SimV1
name: buffer
description: set buffer and readout bufferd value
connections:
- name: myConnection
port: 8080
services:
- name: Service02
steps:
- direction: In
trigger:
- uri: '*'
buffer:
- name: myDate
value: "{DATE}"
- direction: Out
message:
payload: |-
"{
"a": {
"c:" %{myDate}
}
}"
Use multiple buffer values
You can split the value of a message element and buffer it separately. Typically, these are values from a table or database divided by a separator. API simulation creates a separate buffer with consecutive numbers for each partial value.
Create multiple buffer values
To split a value and store it as a buffer, you need the following:
-
The buffer property with a buffer name to find the buffer values again
-
A value with the syntax {SPLITBUFFER[<Separator>]} to identify the individual parts of a value
Read buffered partial values
Reuse a buffered partial value for a message element using the syntax {B[<Buffer name><number>]}. You need the buffer name along with the corresponding buffer value number and the Insert property.
In this example, you run a service named Service04:
-
The inbound step contains two properties:
-
The trigger property to wait for a message that contains any value as the value of the Path property.
-
The buffer property to create a split buffer named myBuffer, which stores the value of the message payload. For each value separated by a semicolon, API simulation creates a separate buffer with consecutive numbers. For example, if the payload is 123;456;789;ABC, you get the following buffers: MyBuffer1 with the value 123, MyBuffer2 with 456, MyBuffer3 with 789, and MyBuffer4 with ABC.
-
-
The insert outbound step property writes the value of the buffer named myBuffer1 to the payload: 123.
schema: SimV1
- name: Service04
steps:
- direction: In
trigger:
- uri: '*'
buffer:
- name: myBuffer
value: '{SPLITBUFFER[;]}'
- direction: Out
insert:
- value: '{B[myBuffer1]}'
Use a dynamic buffer value
You can store a dynamic value within a static string as a buffer. For example, this could be a data string where only the ID changes and you want to reuse that ID.
Create dynamic buffer values
To buffer a value within a string, use the buffer property with the value <string>{XB[<Buffer name>]}<string>.
Read buffered values
Reuse dynamic buffer values in the same way as buffer values.
In this example, you run a service named Service03:
-
The inbound step contains two properties:
-
The trigger property to wait for a message that contains any value as the value of the Path property.
-
The buffer property to create two XBuffers named OrderID and CustomerID to store the values of the message payload. API simulation buffers the OrderID, which is located between Transfer order and has been created. It also buffers the CustomerID, which is located after for customer.
-
-
The insert outbound step property writes the value of the buffer named OrderID to the payload.
schema: SimV1
- name: Service03
steps:
- direction: In
trigger:
- uri: '*'
buffer:
- value: Transfer order {XB[OrderID]} has been created for customer {XB[CustomerID]}
- direction: Out
insert:
- value: '{B[OrderID]}'