- 若要启动模拟器,请为要使用的实体提供配置。 在本地将以下 JSON 文件保存为 config.json:
{
"UserConfig": {
"Namespaces": [
{
"Name": "sbemulatorns",
"Queues": [
{
"Name": "queue.1",
"Properties": {
"DeadLetteringOnMessageExpiration": false,
"DefaultMessageTimeToLive": "PT1H",
"DuplicateDetectionHistoryTimeWindow": "PT20S",
"ForwardDeadLetteredMessagesTo": "",
"ForwardTo": "",
"LockDuration": "PT1M",
"MaxDeliveryCount": 3,
"RequiresDuplicateDetection": false,
"RequiresSession": false
}
}
],
"Topics": [
{
"Name": "topic.1",
"Properties": {
"DefaultMessageTimeToLive": "PT1H",
"DuplicateDetectionHistoryTimeWindow": "PT20S",
"RequiresDuplicateDetection": false
},
"Subscriptions": [
{
"Name": "subscription.1",
"Properties": {
"DeadLetteringOnMessageExpiration": false,
"DefaultMessageTimeToLive": "PT1H",
"LockDuration": "PT1M",
"MaxDeliveryCount": 3,
"ForwardDeadLetteredMessagesTo": "",
"ForwardTo": "",
"RequiresSession": false
},
"Rules": [
{
"Name": "app-prop-filter-1",
"Properties": {
"FilterType": "Correlation",
"CorrelationFilter": {
"ContentType": "application/text",
"CorrelationId": "id1",
"Label": "subject1",
"MessageId": "msgid1",
"ReplyTo": "someQueue",
"ReplyToSessionId": "sessionId",
"SessionId": "session1",
"To": "xyz"
}
}
}
]
},
{
"Name": "subscription.2",
"Properties": {
"DeadLetteringOnMessageExpiration": false,
"DefaultMessageTimeToLive": "PT1H",
"LockDuration": "PT1M",
"MaxDeliveryCount": 3,
"ForwardDeadLetteredMessagesTo": "",
"ForwardTo": "",
"RequiresSession": false
},
"Rules": [
{
"Name": "user-prop-filter-1",
"Properties": {
"FilterType": "Correlation",
"CorrelationFilter": {
"Properties": {
"prop1": "value1"
}
}
}
}
]
},
{
"Name": "subscription.3",
"Properties": {
"DeadLetteringOnMessageExpiration": false,
"DefaultMessageTimeToLive": "PT1H",
"LockDuration": "PT1M",
"MaxDeliveryCount": 3,
"ForwardDeadLetteredMessagesTo": "",
"ForwardTo": "",
"RequiresSession": false
}
},
{
"Name": "subscription.4",
"Properties": {
"DeadLetteringOnMessageExpiration": false,
"DefaultMessageTimeToLive": "PT1H",
"LockDuration": "PT1M",
"MaxDeliveryCount": 3,
"ForwardDeadLetteredMessagesTo": "",
"ForwardTo": "",
"RequiresSession": false
},
"Rules": [
{
"Name": "sql-filter-1",
"Properties": {
"FilterType": "Sql",
"SqlFilter": {
"SqlExpression": "sys.MessageId = '123456' AND userProp1 = 'value1'"
},
"Action" : {
"SqlExpression": "SET sys.To = 'Entity'"
}
}
}
]
}
]
}
]
}
],
"Logging": {
"Type": "File"
}
}
}
2. 若要启动服务总线模拟器的容器,请将以下 .yaml 文件保存为 docker-compose.yaml
注意
默认情况下,服务总线模拟器使用端口 5672。 如果将配置自定义为使用其他端口,请更新 YAML 文件中的端口设置。
name: microsoft-azure-servicebus-emulator
services:
emulator:
container_name: "servicebus-emulator"
image: mcr.microsoft.com/azure-messaging/servicebus-emulator:latest
pull_policy: always
volumes:
- "${CONFIG_PATH}:/ServiceBus_Emulator/ConfigFiles/Config.json"
ports:
- "5672:5672"
- "5300:5300"
environment:
SQL_SERVER: mssql
MSSQL_SA_PASSWORD: "${MSSQL_SA_PASSWORD}" # Password should be same as what is set for SQL Server Linux
ACCEPT_EULA: ${ACCEPT_EULA}
SQL_WAIT_INTERVAL: ${SQL_WAIT_INTERVAL} # Optional: Time in seconds to wait for SQL to be ready (default is 15 seconds)
depends_on:
- mssql
networks:
sb-emulator:
aliases:
- "sb-emulator"
mssql:
container_name: "mssql"
image: "mcr.microsoft.com/mssql/server:2022-latest"
networks:
sb-emulator:
aliases:
- "mssql"
environment:
ACCEPT_EULA: ${ACCEPT_EULA}
MSSQL_SA_PASSWORD: "${MSSQL_SA_PASSWORD}" # To be filled by user as per policy : https://free.blessedness.top/en-us/sql/relational-databases/security/strong-passwords?view=sql-server-linux-ver16
networks:
sb-emulator:
- 创建 .env 文件以声明服务总线模拟器的环境变量,并确保设置了以下所有环境变量。
# Environment file for user defined variables in docker-compose.yml
# 1. CONFIG_PATH: Path to Config.json file
# Ex: CONFIG_PATH="C:\\Config\\Config.json"
CONFIG_PATH="<Replace with path to Config.json file>"
# 2. ACCEPT_EULA: Pass 'Y' to accept license terms for SQL Server Linux and Azure Service Bus emulator.
# Service Bus emulator EULA : https://github.com/Azure/azure-service-bus-emulator-installer/blob/main/EMULATOR_EULA.txt
# SQL Server Linux EULA : https://go.microsoft.com/fwlink/?LinkId=746388
ACCEPT_EULA="N"
# 3. MSSQL_SA_PASSWORD to be filled by user as per policy
MSSQL_SA_PASSWORD=""
重要说明
通过将值“Y”传递给环境变量“ACCEPT_EULA”,可以确认并接受 Azure 服务总线模拟器 和 SQL Server Linux 的最终用户许可协议(EULA)条款和条件。
确保将 .env 文件与 docker-compose.yaml 文件置于同一目录中。
将 MSSQL_SA_PASSWORD 环境变量设置为至少包含八个字符的强密码,以满足密码要求。
在 Windows 中指定文件路径时,请使用双反斜杠 (\\) 而不是单反斜杠 (\),以避免转义字符出现问题。
- 若要运行模拟器,请执行以下命令:
docker compose -f <PathToDockerComposeFile> up -d