Code Monkey home page Code Monkey logo

allerdemo's Introduction

Aller Teaching Azure Integration

Morten la Cour

Table of Content

  1. Event Grid Topic Demo
  2. Create Event Grid Topic
  3. Create a Subscription
  4. Submit Events
  5. Api Management
  6. List Resources
  7. Clean up

Event Grid Topic Demo

Create Resource Group

Clear-Host
$rg = New-AzResourceGroup -Name aller_eventgrid_demo -Location westeurope

Back to Top

Create Event Grid Topic

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

Back to Top

Create a Subscription

A simple Subscription (GET-All)

Clear-Host
$endpoint = "https://enuswcsnq5qr.x.pipedream.net/";
New-AzEventGridSubscription  -ResourceGroupName $rg.ResourceGroupName -TopicName $eventgrid_topic.TopicName `
 -EventSubscriptionName subscriptionsimple -Endpoint $endpoint

Only orderEvent Subscription

Clear-Host
$endpoint = "https://en68sphu3z3tq.x.pipedream.net/";
New-AzEventGridSubscription  -ResourceGroupName $rg.ResourceGroupName -TopicName $eventgrid_topic.TopicName `
 -EventSubscriptionName subscriptionordersOnly -Endpoint $endpoint -IncludedEventType @("orderEvent")

Only orderEvents only certain Customers

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") })

Back to Top

Submit Events

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}
}

Back to Top

Api Management

Call Old SOAP Service

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>
  1. Create a blank API, with the Web Service Url
  2. Add an operation (GetCity) GET -> /city/{postnumber}
  3. 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

  1. 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>
  1. Read the Template Parameter instead of the hard-coded value
<pPostNumber>{{context.Request.MatchedParameters["postnumber"]}}</pPostNumber>
  1. 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>
  1. Alter xslt to prettify JSON
<Response value="{//source:GetCityResult}" />

Back to Top

List Resources

Clear-Host
Get-AzResource -ResourceGroupName $rg.ResourceGroupName | select Name, ResourceType, ResourceGroupName

Back to Top

Clean up

Be sure that $rg points at the Resource Group to be deleted!

Clear-Host
Remove-AzResourceGroup -Name $rg.ResourceGroupName -Force

Back to Top

allerdemo's People

Contributors

xemmel avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.