Messages
Use message properties in your simulation file to define outgoing messages. Each message needs to contain all information that your service requires.
This topic lists all message properties and includes examples that show how to use them.
|
Message property |
Description |
Example |
|---|---|---|
|
Reference a message by its name. |
Message 1 |
|
|
Time in milliseconds that the simulation waits before it sends a response. |
500 |
|
|
encoding |
Sets the character encoding. |
UTF-8 |
|
Additional information that you send with the message, such as the content type. Define each header with a name and a value. To set a header with a dynamic value, use an insert rule with the type Header instead. For an example, check out Example - message with headers. |
name: Content-Type value: application/json |
|
|
messagingProperties |
Additional information that you send with the message. Only messaging technologies support this property, for example IBM MQ. |
my property: 10 |
|
HTTP method that the message uses. Use GET, POST, PUT, DELETE, or PATCH. |
PUT |
|
|
name |
Name of the message. |
Message 2 |
|
Content of the message. This is the data that two services exchange. |
Text |
|
|
payloadBase64 |
You can use this property as an alternative to payload if the payload contains special characters that YAML doesn't support. The value must be BASE64 encoded. |
aGVsbG8gd29ybGQh |
|
payloadFile |
You can use this property as an alternative to payload if you want to send the payload in a separate file. The value must be a file path, either absolute or relative to the simulation file. |
..\simulator\payload.txt |
|
HTTP status code of a response message. Enter the number, or the number and a description. |
401 Unauthorized |
This is an example of how a virtual service could look like. It specifies the following:
-
The name of the virtual service is Service01 and it is a request response pair.
-
The inbound step trigger waits for a message with a uri property that contains any value. If an incoming message meets this condition, API simulation sends a response.
-
The outbound property message sends the value Hello world! to a service with the connection port 54545.
schema: SimV1
name: default
services:
- name: Service01
steps:
- direction: In
trigger:
- uri: '*'
- direction: Out
message:
payload: Hello world!
connections:
- port: 54545
This example sends a response with the following headers:
-
The headers property in the message adds the header Content-Type with the fixed value application/json.
-
The insert rule with the type Header adds the header dynamic. Its value is the dynamic date and time value {DATE}, which the simulation evaluates for each response.
- direction: Out
insert:
- type: Header
name: dynamic
value: "{DATE}"
message:
headers:
- name: Content-Type
value: application/json
payload: minimal