APIM背后的Azure服务总线



我正试图通过APIM向服务总线队列发送消息。我已经阅读了几篇文章,但没有成功https://connectedcircuits.blog/2018/09/25/exposing-azure-service-bus-through-apim-generating-a-sas-token-and-setting-the-session-id/https://www.serverlessnotes.com/docs/load-article/docs/en/expose-service-bus-queue-through-api-management

现在的问题是,当我尝试发送消息时,而不是通常创建的201,我只收到一个200 OK,没有消息到达队列。请注意,直接对着有问题的服务巴士运行很好。

以下是我目前使用的政策

<policies>
<inbound>
<set-header name="Authorization" exists-action="override">
<value>@{
// Load variables
string resourceUri = "xxxxx.servicebus.windows.net/apimqueue/messages";
string sasKeyName = "";
string sasKey = "";
// Set the token lifespan
System.TimeSpan sinceEpoch = System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1));
var expiry = System.Convert.ToString((int)sinceEpoch.TotalSeconds + 60); //1 minute
string stringToSign = System.Uri.EscapeDataString(resourceUri) + "n" + expiry;
System.Security.Cryptography.HMACSHA256 hmac = new System.Security.Cryptography.HMACSHA256(System.Text.Encoding.UTF8.GetBytes(sasKey));
var signature = System.Convert.ToBase64String(hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(stringToSign)));
// Format the sas token
var sasToken = String.Format("SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}",
System.Uri.EscapeDataString(resourceUri), System.Uri.EscapeDataString(signature), expiry, sasKeyName);
return sasToken;
}</value>
</set-header>
</inbound>
<backend>
<!-- base: Begin Product scope -->
<!-- base: Begin Global scope -->
<forward-request />
<!-- base: End Global scope -->
<!-- base: End Product scope -->
</backend>
<outbound />
<on-error />
</policies>

再次执行POST调用时得到的响应https://apimtestbus.azure-api.net/azurebustest21243.servicebus.windows.net/apimqueue/messages

HTTP://1.1 200 OK

content-length: 0

日期:2021年5月23日星期日06:02:25 GMTocp-apim-apiid:servicebusocp-apim operationid:发送消息ocp-apim subscriptionid:masterocp-apim跟踪位置:https://apimstdebros05i5mtudswoa.blob.core.windows.net/apiinspectorcontainer/cHcJa9krxa3PhOTGYwgFgw2-37?sv=2019-07-07;sr=b&sig=uh6Y%2BVekeFU%2BZ5G1t8dXt6gVp6sQku5Mp25OTagJUts%3D&se=2021-05-24T06%3A02%3A26Z&sp=r&traceId=8097b06294bd49a0bc95cf1979ac7448变化:原始

如有任何帮助,将不胜感激

问题是我在API级别确认了一个策略,但操作级别的另一个策略正在覆盖它。删除操作级别策略后,它起作用了。

相关内容

最新更新