无法在 Azure 容器应用程序中使用 ASB 缩小到零

问题描述 投票:0回答:1

我在容器中有一个 .NET 8.0 控制台应用程序,该应用程序部署到 ACR 并在 ContainerApps 上运行。 应用程序基于 MassTransit 构建,使用 Azure 服务总线队列。 它工作得很好,但即使根本没有请求,我也总是有一个活动副本在运行。

我尝试了两种方法,使用 queueconnection 制定缩放规则,完全没有变化。

这个问题不同,我没有密钥库引用,我的秘密是容器应用程序秘密。 这是我的资源的 JSON:

{
    "id": "<redacted>",
    "name": "<redacted>",
    "type": "Microsoft.App/containerApps",
    "location": "West Europe",
    "tags": {
        "created_by": "cdktf",
        "environment": "Staging"
    },
    "systemData": {
        "createdBy": "1a6afc85-d01a-45ad-8de2-4aa26f74828d",
        "createdByType": "Application",
        "createdAt": "2023-12-12T10:39:02.4044595",
        "lastModifiedBy": "1a6afc85-d01a-45ad-8de2-4aa26f74828d",
        "lastModifiedByType": "Application",
        "lastModifiedAt": "2023-12-19T07:47:57.7108815"
    },
    "properties": {
        "provisioningState": "Succeeded",
        "runningStatus": "Running",
        "managedEnvironmentId": "<redacted>",
        "environmentId": "<redacted>",
        "workloadProfileName": null,
        "outboundIpAddresses": [
            "<redacted>"
        ],
        "latestRevisionName": "<redacted>--8psntt0",
        "latestReadyRevisionName": "<redacted>--8psntt0",
        "latestRevisionFqdn": "",
        "customDomainVerificationId": "<redacted>",
        "configuration": {
            "secrets": [
                {
                    "name": "container-registry-admin-password"
                },
                {
                    "name": "servicebus"
                }
            ],
            "activeRevisionsMode": "Single",
            "ingress": null,
            "registries": [
                {
                    "server": "<redacted>",
                    "username": "<redacted>",
                    "passwordSecretRef": "container-registry-admin-password",
                    "identity": ""
                }
            ],
            "dapr": null,
            "maxInactiveRevisions": null,
            "service": null
        },
        "template": {
            "revisionSuffix": "",
            "terminationGracePeriodSeconds": null,
            "containers": [
                {
                    "image": "<redacted>",
                    "name": "processor",
                    "args": [
                        "dotnet",
                        "Processor.dll"
                    ],
                    "env": [
                        {
                            "name": "DOTNET_ENVIRONMENT",
                            "value": "Staging"
                        }
                    ],
                    "resources": {
                        "cpu": 1,
                        "memory": "2Gi",
                        "ephemeralStorage": "4Gi"
                    },
                    "probes": []
                }
            ],
            "initContainers": null,
            "scale": {
                "minReplicas": null,
                "maxReplicas": 5,
                "rules": [
                    {
                        "name": "order-accepted",
                        "azureQueue": {
                            "queueName": "order-accepted",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "order-fulfilled",
                        "azureQueue": {
                            "queueName": "order-fulfilled",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "order-rejected",
                        "azureQueue": {
                            "queueName": "order-rejected",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "order-state",
                        "azureQueue": {
                            "queueName": "order-state",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "process-order",
                        "azureQueue": {
                            "queueName": "process-order",
                            "queueLength": 5,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "submit-order",
                        "azureQueue": {
                            "queueName": "submit-order",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "validation",
                        "azureQueue": {
                            "queueName": "validation",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    }
                ]
            },
            "volumes": [],
            "serviceBinds": null
        },
        "eventStreamEndpoint": "<redacted>"
    },
    "identity": {
        "type": "None"
    }
}

7 多分钟后,容器仍然存在。

ASB 的 MassTransit

AutoStart = true
是否会导致此行为,或者我的 ContainerApps 配置是否有问题?

azure azureservicebus masstransit azure-container-apps
1个回答
0
投票

Scaler 规则是使用 azureQueue 定义的,它们应该是自定义规则。使用自定义规则重写它们可以解决问题:

 "initContainers": null,
            "scale": {
                "minReplicas": 0,
                "maxReplicas": 5,
                "rules": [
                    {
                        "name": "order-accepted",
                        "custom": {
                            "type": "azure-servicebus",
                            "metadata": {
                                "messageCount": "1",
                                "namespace": "kkdevservicebus",
                                "queueName": "order-accepted"
                            },
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
...
© www.soinside.com 2019 - 2024. All rights reserved.