Created
July 13, 2021 14:53
-
-
Save joewashington75/3d2862db22c23e47941e152cea5d9488 to your computer and use it in GitHub Desktop.
Writing to Azure Service Bus using APIM Policy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
IMPORTANT: | |
- Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements. | |
- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element. | |
- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element. | |
- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar. | |
- To remove a policy, delete the corresponding policy statement from the policy document. | |
- Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope. | |
- Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope. | |
- Policies are applied in the order of their appearance, from the top down. | |
- Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope. | |
--> | |
<policies> | |
<inbound> | |
<base /> | |
<set-backend-service base-url="https://sb-apimtoservicebusdemo.servicebus.windows.net" /> | |
<rewrite-uri template="apimqueue/messages" /> | |
<set-header name="Content-Type" exists-action="override"> | |
<value>vnd.microsoft.servicebus.yml</value> | |
</set-header> | |
<set-header name="Authorization" exists-action="override"> | |
<value>{{apimqueuesend}}</value> | |
</set-header> | |
<set-header name="BrokerProperties" exists-action="override"> | |
<value>@{ | |
var json = new JObject(); | |
json.Add("MessageId", context.RequestId); | |
json.Add("Label", "TestData"); | |
return json.ToString(Newtonsoft.Json.Formatting.None); | |
}</value> | |
</set-header> | |
<set-body>@{ | |
JObject json = context.Request.Body.As<JObject>(preserveContent: true); | |
return JsonConvert.SerializeObject(json); | |
}</set-body> | |
</inbound> | |
<backend> | |
<base /> | |
</backend> | |
<outbound> | |
<base /> | |
</outbound> | |
<on-error> | |
<base /> | |
<return-response> | |
<set-status code="200" reason="OK" /> | |
</return-response> | |
</on-error> | |
</policies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment