- Event Grid Topic Demo
- Create Event Grid Topic
- Create a Subscription
- Submit Events
- Api Management
- List Resources
- Clean up
Clear-Host
$rg = New-AzResourceGroup -Name aller_eventgrid_demo -Location westeurope
Clear-Host
$eventgrid_topic = New-AzEventGridTopic -ResourceGroupName $rg.ResourceGroupName -Name mytopic1314 -Location $rg.Location
$event_topic_url = $eventgrid_topic.Endpoint;
$event_topic_key = ($eventgrid_topic | Get-AzEventGridTopicKey).Key1
Clear-Host
$endpoint = "https://enuswcsnq5qr.x.pipedream.net/";
New-AzEventGridSubscription -ResourceGroupName $rg.ResourceGroupName -TopicName $eventgrid_topic.TopicName `
-EventSubscriptionName subscriptionsimple -Endpoint $endpoint
Clear-Host
$endpoint = "https://en68sphu3z3tq.x.pipedream.net/";
New-AzEventGridSubscription -ResourceGroupName $rg.ResourceGroupName -TopicName $eventgrid_topic.TopicName `
-EventSubscriptionName subscriptionordersOnly -Endpoint $endpoint -IncludedEventType @("orderEvent")
Clear-Host
$endpoint = "https://ensla6u2xaiqp.x.pipedream.net/";
New-AzEventGridSubscription -ResourceGroupName $rg.ResourceGroupName -TopicName $eventgrid_topic.TopicName `
-EventSubscriptionName subscriptionordersandcustomersOnly -Endpoint $endpoint -IncludedEventType @("orderEvent") `
-AdvancedFilter @(@{operator="StringIn"; key="data.customer"; Values=@("Aller","Egmont") })
Clear-Host
"Aller Egmont DS Coop IBM MS".Split() |
foreach {
$body = @"
[
{
"subject" : "testSubject",
"eventType" : "testEvent",
"id" : "$((New-Guid).Guid)",
"eventTime" : "$((Get-Date).ToString("yyyy-MM-ddTHH:mm:ss"))",
"data" : {
"customer" : "$_"
}
},
{
"subject" : "testSubject",
"eventType" : "orderEvent",
"id" : "$((New-Guid).Guid)",
"eventTime" : "$((Get-Date).ToString("yyyy-MM-ddTHH:mm:ss"))",
"data" : {
"customer" : "$_"
}
}
]
"@
curl -Uri $event_topic_url -Method Post -Body $body -Headers @{"aeg-sas-key" = $event_topic_key}
}
Url: https://postnumbers.azurewebsites.net/Service.asmx Method: Post Headers:
SOAPAction: http://tempuri.org/GetCity
Content-Type: text/xml
Body:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetCity xmlns="http://tempuri.org/">
<postnumber>8200</postnumber>
</GetCity>
</Body>
</Envelope>
- Create a blank API, with the Web Service Url
- Add an operation (GetCity) GET -> /city/{postnumber}
- Call the API operation https://aller.azure-api.net/postnumbers/city/{postnumber}
PostNumber = 5000 You will get a 401 Access Denied
Ocp-Apim-Subscription-Key: 529a799a71254c23aa66e54fecc68ec5;product=starter
500 Internal Error Trace will tell that http://xemmel.com/webservices/postnumber.asmx/city/5000 was called
- Set the following policies on operation level
<inbound>
<base />
<rewrite-uri template="?op=GetCity" copy-unmatched-params="false" />
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>text/xml</value>
</set-header>
<set-body template="liquid">
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetCity xmlns="http://tempuri.org/">
<pPostNumber>4000</pPostNumber>
</GetCity>
</Body>
</Envelope>
</set-body>
</inbound>
- Read the Template Parameter instead of the hard-coded value
<pPostNumber>{{context.Request.MatchedParameters["postnumber"]}}</pPostNumber>
- Change outbound policies*
<outbound>
<base />
<xsl-transform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:source="http://tempuri.org/" exclude-result-prefixes="source">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<Response>
<xsl:value-of select="//source:GetCityResult" />
</Response>
</xsl:template>
</xsl:stylesheet>
</xsl-transform>
<xml-to-json kind="javascript-friendly" apply="always" consider-accept-header="true" />
</outbound>
- Alter xslt to prettify JSON
<Response value="{//source:GetCityResult}" />
Clear-Host
Get-AzResource -ResourceGroupName $rg.ResourceGroupName | select Name, ResourceType, ResourceGroupName
Be sure that $rg points at the Resource Group to be deleted!
Clear-Host
Remove-AzResourceGroup -Name $rg.ResourceGroupName -Force