Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1411732%22%20slang%3D%22en-US%22%3EAPI%20Management%20Integration%20with%20Service%20Fabric%20Backend%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1411732%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22lia-align-justify%22%3EThe%20APIM%20instance%20will%20act%20as%20the%20gateway%20to%20the%20Service%20Fabric%20backend.%20The%20SF%20application%20used%20in%20this%20example%20can%20be%20found%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fhakashya%2FAPIM-with-Service-Fabric%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fhakashya%2FAPIM-with-Service-Fabric%3C%2FA%3E.%20You%20may%20clone%20the%20repository%20to%20replicate%20the%20results%20for%20your%20reference.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECertificate%20Handling%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EThe%20certificate%20used%20for%20creating%20the%20Service%20Fabric%20cluster%20is%20called%20the%20cluster%20certificate.%20In%20this%20example%2C%20this%20is%20a%20self-signed%20certificate.%20For%20the%20API%20Management%20instance%20to%20communicate%20with%20the%20service%20fabric%20backend%2C%20we%20need%20the%20cluster%20certificate%20to%20be%20uploaded%20to%20the%20API%20Management%20instance.%20The%20steps%20to%20do%20that%20is%20as%20follows%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ELocate%20the%20certificate%20on%20your%20machine%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22CertScreenshot.png%22%20style%3D%22width%3A%20703px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193913iA410E460427375BC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22CertScreenshot.png%22%20alt%3D%22CertScreenshot.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3ENavigate%20to%20the%20Certificates%20blade%20on%20the%20Azure%20Portal%20for%20the%20APIM%20instance%20of%20interest%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_1-1590156848548.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193902i2E8479EC5BB63B52%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_1-1590156848548.png%22%20alt%3D%22HarshaKashyap_1-1590156848548.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EClick%20on%20the%20%E2%80%9CAdd%E2%80%9D%20button%2C%20marked%20as%20the%203%3CSUP%3Erd%3C%2FSUP%3E%20step.%20Once%20this%20button%20is%20clicked%2C%20a%20wizard%20opens%20on%20the%20right%2C%20where%20the%20certificate%20can%20be%20uploaded.%20Select%20the%20right%20.pfx%20file%20that%20was%20located%20at%20the%20beginning%20of%20this%20section.%20Also%2C%20enter%20the%20password%20which%20protects%20the%20certificate.%20Once%20this%20is%20completed%2C%20click%20on%20the%20%E2%80%9CAdd%E2%80%9D%20button%20on%20the%20bottom%20right%20corner%20marked%20as%20the%205%3CSUP%3Eth%3C%2FSUP%3E%20step.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EOnce%20the%20certificate%20is%20uploaded%20to%20the%20APIM%20instance%2C%20it%20can%20be%20used%20by%20the%20APIM%20instance%20for%20accessing%20the%20back%20end%20that%20is%20protected%20by%20the%20certificate.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EConfiguring%20the%20Backend%20Service%20for%20API%20Management%20Instance%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EWe%20will%20be%20adding%20a%20transformation%20policy%20for%20the%20API%20Management%20instance%20to%20redirect%20the%20calls%20towards%20the%20Service%20Fabric%20backend.%20To%20do%20this%2C%20the%20prerequisite%20is%20that%20a%20backend%20entity%20must%20be%20added%20to%20the%20API%20Management%20instance.%20As%20of%20now%2C%20it%20can%20only%20be%20done%20using%20REST%20APIs%20and%20PowerShell.%20Below%20is%20an%20example%20using%20REST%20API.%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDetails%20about%20the%20Service%20Fabric%20backend%20service%20used%20in%20this%20example%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EBackend%20is%20a%20RESTful%20service%3C%2FLI%3E%0A%3CLI%3EManagement%20Endpoint%3A%20-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fservicefabricbackend.eastus.cloudapp.azure.com%3A19080%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fservicefabricbackend.eastus.cloudapp.azure.com%3A19080%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ECertificate%20thumbprint%3A%2076E97E3A746CB85AB83E431BDEB01C6DB168244B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20REST%20API%20reference%20for%20creating%20a%20backend%20entity%20is%20here%3A%20-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fapimanagement%2F2019-12-01%2Fbackend%2Fcreateorupdate%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fapimanagement%2F2019-12-01%2Fbackend%2Fcreateorupdate%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EThe%20API%20takes%20subscription%20ID%2C%20resource%20group%20name%2C%20API%20Management%20service%20name%2C%20and%20an%20identifier%20for%20the%20backend%20entity%20(which%20is%20equivalent%20to%20the%20name%20of%20the%20backend%20entity).%20Please%20note%20that%20the%20backend%20entity%20is%20just%20a%20representation%20of%20the%20Service%20Fabric%20application%20in%20API%20Management%2C%20but%20it%20is%20not%20the%20actual%20Service%20Fabric%20service%20itself.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20body%20of%20the%20PUT%20request%2C%20for%20this%20example%2C%20is%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%22properties%22%3A%20%7B%0A%20%20%22description%22%3A%20%22Service%20Fabric%20Backend%20for%20APIM%22%2C%0A%20%20%22protocol%22%3A%20%22http%22%2C%0A%20%20%22url%22%3A%20%22fabric%3A%2FSFBackendForAPIM%2FWebAPI_Backend%22%2C%0A%20%20%22resourceId%22%3A%20%22https%3A%2F%2Fservicefabricbackend.eastus.cloudapp.azure.com%3A19080%2F%22%2C%0A%20%20%22tls%22%3A%20%7B%0A%20%20%20%22validateCertificateChain%22%3A%20%22false%22%0A%20%20%7D%2C%0A%20%20%22properties%22%3A%20%7B%0A%20%20%20%22serviceFabricCluster%22%3A%20%7B%0A%20%20%20%20%22managementEndpoints%22%3A%20%5B%0A%20%20%20%20%20%22https%3A%2F%2Fservicefabricbackend.eastus.cloudapp.azure.com%3A19080%22%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22clientCertificatethumbprint%22%3A%20%2276E97E3A746CB85AB83E431BDEB01C6DB168244B%22%2C%0A%20%20%20%20%22serverCertificateThumbprints%22%3A%20%5B%0A%20%20%20%20%20%2276E97E3A746CB85AB83E431BDEB01C6DB168244B%22%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22maxPartitionResolutionRetries%26nbsp%3B%22%3A%205%0A%20%20%20%7D%0A%20%20%7D%0A%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20protocol%20specifies%20whether%20the%20backend%20is%20RESTful%20service%20(http)%20or%20SOAP%20service%20(soap).%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20url%20specifies%20that%20the%20call%20should%20go%20to%20fabric%3A%2F%3CSFSERVICENAME%3E%2F%3CSFAPPLICATION%3E.%20The%20fabric%3A%2F%20is%20a%20call%20made%20to%20the%20naming%20service%20of%20the%20Service%20Fabric%20cluster.%20This%20url%20returns%20one%20partition%20with%20its%20listeners%20for%20the%20Application%20that%20was%20specified.%20We%20then%20make%20a%20call%20to%20this%20partition%20after%20resolution.%20In%20this%20example%2C%20the%20service%20name%20is%20SFBackendForAPIM%2C%20and%20the%20Application%20Name%20is%20WebAPI_Backend%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22HarshaKashyap_2-1590156848551.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193901i6944A8AD8D262CDC%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22HarshaKashyap_2-1590156848551.png%22%20alt%3D%22HarshaKashyap_2-1590156848551.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FSFAPPLICATION%3E%3C%2FSFSERVICENAME%3E%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20resource%20ID%20is%20the%20same%20as%20the%20management%20endpoint.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20tls%20section%20elaborates%20the%20security%20features.%20In%20this%20example%2C%20since%20the%20certificate%20that%20is%20being%20used%20is%20self-signed%2C%20we%20are%20not%20validating%20the%20certificate%20chain.%20For%20a%20production%20cluster%2C%20it%20is%20recommended%20that%20validateCertificateChain%20is%20set%20to%20true%2C%20for%20security%20purposes.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20management%20endpoint%20belongs%20to%20the%20Service%20Fabric%20backend.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3E-ERR%3AREF-NOT-FOUND-maxPartitionResolutionRetries%20property%20is%20used%20to%20inform%20the%20APIM%20service%20that%20it%20should%20attempt%20partition%20resolution%20exercise%20up%20to%205%20times%20per%20partition%20(or%20instances%2C%20in%20case%20of%20stateless%20services).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20response%20for%20the%20above%20request%20is%20as%20follows%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%22id%22%3A%20%22%2Fsubscriptions%2Fcbxxxxxx-xxxx-xxxx-ac0f-99e4b64d2634%2FresourceGroups%2FSFCluster-RG%2Fproviders%2FMicrosoft.ApiManagement%2Fservice%2Fapimservicefabric%2Fbackends%2Fsfbackend%22%2C%0A%20%22type%22%3A%20%22Microsoft.ApiManagement%2Fservice%2Fbackends%22%2C%0A%20%22name%22%3A%20%22sfbackend%22%2C%0A%20%22properties%22%3A%20%7B%0A%20%20%22title%22%3A%20null%2C%0A%20%20%22description%22%3A%20%22Service%26nbsp%3BFabric%26nbsp%3BBackend%26nbsp%3Bfor%26nbsp%3BAPIM%22%2C%0A%20%20%22url%22%3A%20%22fabric%3A%2FSFBackendForAPIM%2FWebAPI_Backend%22%2C%0A%20%20%22protocol%22%3A%20%22http%22%2C%0A%20%20%22resourceId%22%3A%20%22https%3A%2F%2Fservicefabricbackend.eastus.cloudapp.azure.com%3A19080%2F%22%2C%0A%20%20%22properties%22%3A%20%7B%0A%20%20%20%22serviceFabricCluster%22%3A%20%7B%0A%20%20%20%20%22managementEndpoints%22%3A%20%5B%0A%20%20%20%20%20%22https%3A%2F%2Fservicefabricbackend.eastus.cloudapp.azure.com%3A19080%22%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22clientCertificateThumbprint%22%3A%20%2276E97E3A746CB85AB83E431BDEB01C6DB168244B%22%2C%0A%20%20%20%20%22serverCertificateThumbprints%22%3A%20%5B%0A%20%20%20%20%20%2276E97E3A746CB85AB83E431BDEB01C6DB168244B%22%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22maxPartitionResolutionRetries%22%3A%205%0A%20%20%20%7D%0A%20%20%7D%2C%0A%20%20%22tls%22%3A%20%7B%0A%20%20%20%22validateCertificateChain%22%3A%20false%0A%20%20%7D%0A%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EIn%20case%20you%20do%20not%20know%20certain%20specifics%20about%20the%20Service%20Fabric%20cluster%2C%20you%20can%20always%20use%20the%20PowerShell%20cmdlet%20Get-AzServiceFabricCluster%20(-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.servicefabric%2FGet-AzServiceFabricCluster%3Fview%3Dazps-3.8.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.servicefabric%2FGet-AzServiceFabricCluster%3Fview%3Dazps-3.8.0%3C%2FA%3E)%20to%20gather%20information.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20use%20any%20REST%20client%20to%20do%20this.%20The%20request%20with%20Postman%20would%20look%20something%20like%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_3-1590156848558.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193905i52E0CD429426BF38%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_3-1590156848558.png%22%20alt%3D%22HarshaKashyap_3-1590156848558.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EConfiguring%20an%20API%20in%20APIM%20to%20access%20the%20backend%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EWe%20are%20all%20set%20to%20make%20use%20of%20the%20backend%20that%20we%20set%20up%20in%20the%20previous%20few%20sections.%20Now%20we%20shall%20create%20an%20API%20on%20the%20APIM%20instance%2C%20that%20could%20call%20the%20created%20backend%20service.%20The%20steps%20are%20as%20follows%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ENavigate%20to%20the%20APIs%20blade%20on%20the%20API%20Management%20instance%2C%20and%20click%20on%20%E2%80%9CBlank%20API%E2%80%9D%20card%2C%20as%20shown%20below%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_4-1590156848562.png%22%20style%3D%22width%3A%20880px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193904i643F0D7C7F7708BF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_4-1590156848562.png%22%20alt%3D%22HarshaKashyap_4-1590156848562.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3EFill%20in%20the%20details%20for%20the%20Blank%20API%20as%20follows%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_5-1590156848563.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193903i7BD62EC5CF4E0931%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_5-1590156848563.png%22%20alt%3D%22HarshaKashyap_5-1590156848563.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EClick%20on%20the%20%22Add%20operation%22%20button.%20Since%20this%20sample%20application%20is%20configured%20to%20receive%20simple%20GET%20requests%2C%20I%20am%20configuring%20a%20GET%20operation.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_6-1590156848567.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193906i4333F5BFF586A1FD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_6-1590156848567.png%22%20alt%3D%22HarshaKashyap_6-1590156848567.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EThe%20GET%20URL%20would%20be%20the%20path%20to%20access%20our%20service.%20In%20this%20example%2C%20the%20controller%20in%20the%20application%20maps%20the%20route%20to%20%2Fapi%2Fvalues%2C%20therefore%2C%20that%20route%20is%20given%20to%20the%20GET%20URL%20as%20the%20path.%20As%20the%20APIM%20instance%20and%20the%20SF%20Cluster%20are%20on%20the%20same%20VNet%2C%20they%20can%20communicate%20using%20private%20IP%20address.%20When%20a%20call%20is%20made%20to%20the%20naming%20service%2C%20it%20returns%20the%20private%20IPs%20for%20the%20listeners.%20The%20GET%20URL%20would%20then%20be%20appended%20to%20form%20the%20actual%20URL%20that%20is%20called.%20For%20example%2C%20if%20the%20naming%20service%20returns%2010.0.0.5%3A20001%20as%20the%20private%20IP%20of%20the%20instance%20serving%20our%20request%2C%20then%20the%20final%20URL%20which%20is%20called%20by%20the%20APIM%20is%20-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22http%3A%2F%2F10.0.0.5%3A20001%2Fapi%2Fvalues.%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2F10.0.0.5%3A20001%2Fapi%2Fvalues.%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAPIM%20Policy%20Definition%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EThis%20the%20crucial%20step%20of%20action.%20The%20calls%20coming%20to%20the%20API%20management%20is%20redirected%20based%20on%20the%20policy%20we%20set.%20We%20will%20be%20using%20the%20set-backend%20policy%20(-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapi-management%2Fapi-management-transformation-policies%23SetBackendService%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapi-management%2Fapi-management-transformation-policies%23SetBackendService%3C%2FA%3E).%20The%20steps%20are%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EClick%20on%20the%20%20icon%20on%20the%20%E2%80%9CInbound%20Processing%E2%80%9D%2C%20as%20shown%20in%20this%20screenshot%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_7-1590156848569.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193907i19AFC34FCC75C67E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_7-1590156848569.png%22%20alt%3D%22HarshaKashyap_7-1590156848569.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3EThe%20set-backend%20policy%20is%20placed%20in%20the%20inbound%20section%2C%20as%20shown%20here%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_8-1590156848573.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193908i791E74E45CB10E7F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_8-1590156848573.png%22%20alt%3D%22HarshaKashyap_8-1590156848573.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20policy%20statement%20is%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%3CSET-BACKEND-SERVICE%20backend-id%3D%22sfbackend%22%20sf-resolve-condition%3D%22%40((int)context.Response.StatusCode%20!%3D%20200%20%7C%7C%20context.LastError%3F.Reason%20%3D%3D%20%22%20backendconnectionfailure%3D%22%22%3E%3C%2FSET-BACKEND-SERVICE%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EOnce%20the%20policy%20is%20saved%2C%20the%20integration%20between%20the%20Service%20Fabric%20cluster%20and%20API%20Management%20is%20complete.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CU%3EUnderstanding%20the%20policy%3A%3C%2FU%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EWhen%20the%20request%20hits%20the%20API%20Management%20service%2C%20it%20must%20pass%20through%20all%20the%20levels%20of%20APIM%20policies.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EWhen%20we%20use%20the%20set-backend%20policy%20in%20the%20inbound%20section%2C%20we%20are%20changing%20the%20backend%20service%20to%20the%20one%20mentioned%20in%20the%20policy%20rather%20than%20the%20actual%20backend%20that%20was%20configured%20while%20creating%20the%20API.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EIn%20this%20example%2C%20we%20did%20not%20create%20an%20actual%20backend%20during%20the%20API%20creation%2C%20but%20we%20set%20the%20backend%20for%20all%20the%20inbound%20requests%20using%20the%20set-backend%20policy.%20As%20shown%20in%20the%20previous%20section%3A%20%3CEM%3EConfiguring%20the%20Backend%20Service%20for%20API%20Management%20Instance%3C%2FEM%3E%2C%20the%20name%20of%20the%20backend%20was%20%E2%80%9Csfbackend%E2%80%9D.%20This%20is%20the%20same%20name%20that%20is%20given%20as%20a%20value%20to%20the%20APIM%20policy%20as%20well.%20It%20means%20that%20the%20APIM%20instance%20picks%20up%20the%20details%20from%20the%20created%20backend%20entity.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20sf-resolve-condition%20refers%20to%20the%20retry%20condition.%20We%20had%20set%20the%20number%20of%20retries%20to%205%2C%20when%20we%20created%20the%20backend.%20Therefore%2C%20it%20ensures%20that%20if%20the%20sf-resolve-condition%20is%20met%2C%20there%20is%20an%20attempt%20to%20retry%20the%20partition%20resolution.%20In%20this%20case%2C%20the%20resolve%20condition%20is%20met%20if%20the%20response%20code%20from%20the%20backend%20is%20not%20200%2C%20or%20if%20there%20is%20a%20Backend%20Connection%20Failure%2C%20or%20a%20Timeout%20while%20receiving%20a%20response%20from%20the%20backend.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3ESf-listener-name%20indicates%20that%20when%20the%20naming%20service%20returns%20a%20list%20of%20listeners%20for%20a%20machine%20on%20the%20SF%20cluster%20serving%20our%20request%2C%20the%20listener%20with%20the%20name%20HttpServiceEndpoint%20must%20be%20chosen%20to%20make%20the%20request.%20Essentially%2C%20the%20name%20of%20the%20listener%20mentioned%20in%20the%20policy%20is%20the%20name%20of%20the%20listener%20chosen%20for%20making%20the%20request.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EValidating%20the%20Set%20Up%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EFor%20any%20process%2C%20validation%20is%20necessary%20and%20crucial.%20For%20testing%20out%20if%20the%20set-up%20works%2C%20we%20can%20navigate%20to%20the%20%E2%80%9CTest%E2%80%9D%20tab%20on%20the%20Azure%20Portal%20for%20the%20APIM%2C%20for%20that%20Operation%20under%20the%20API.%20Below%20is%20the%20elaboration%20of%20the%20process%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3ENavigate%20to%20the%20test%20tab%2C%20and%20click%20on%20the%20API%20Operation%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EHit%20the%20send%20button%20at%20the%20bottom.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20response%20seen%20has%20been%20received%20by%20the%20APIM%20instance.%20The%20response%20on%20your%20test%20tab%20should%20look%20like%20the%20following%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22HarshaKashyap_9-1590156848577.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193909iFC532531AFF7BEB5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22HarshaKashyap_9-1590156848577.png%22%20alt%3D%22HarshaKashyap_9-1590156848577.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EUnderstanding%20the%20Trace%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EThe%20trace%20section%20of%20the%20API%20call%20gives%20detailed%20insight%20into%20the%20process%20that%20takes%20place%20from%20the%20moment%20you%20hit%20send%2C%20till%20the%20moment%20you%20see%20the%20response%20on%20your%20screen.%20This%20allows%20us%20to%20perform%20analysis%2C%20debug%20our%20API%2C%20troubleshoot%20any%20issues%2C%20with%20the%20help%20of%20the%20trace.%20The%20trace%20for%20this%20example%20is%20available%20here%3A%20-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fhakashya%2FAPIM-with-Service-Fabric%2Fmaster%2FWebAPI_Backend%2Fapimtrace-sfbackend.json%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fraw.githubusercontent.com%2Fhakashya%2FAPIM-with-Service-Fabric%2Fmaster%2FWebAPI_Backend%2Fapimtrace-sfbackend.json%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-justify%22%3EAn%20interesting%20thing%20to%20note%20is%20that%2C%20although%20we%20have%20specified%20that%20the%20maxPartitionResolutionRetries%20values%20for%20the%20APIM%20backend%20entity%20as%205%2C%20the%20number%20of%20resolution%20calls%20are%2018%20in%20this%20trace.%20The%20explanation%20for%20the%20same%20is%20as%20follows%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20SF%20Cluster%20used%20for%20in%20this%20example%20has%203%20nodes.%20Each%20retry%20involves%20trying%20to%20elicit%20a%20response%20from%20all%20the%20machines%20until%20one%20of%20them%20successfully%20responds%20where%20the%20retry%20condition%20fails.%20If%20the%20retry%20condition%20succeeds%2C%20then%20there%20shall%20be%20another%20attempt%20to%20retry.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20retry%20condition%20fails%20if%20the%20response%20status%20code%20received%20is%20200.%20If%20it%20is%20anything%20else%2C%20there%20will%20be%20more%20attempts%20at%20retrying%20until%20the%20desirable%20response%20is%20received%20or%20if%20it%20exceeds%20the%20max%20retry%20count.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3ESince%20this%20sample%20application%20responds%20with%20status%20code%20204%20always%2C%20the%20APIM%20instance%20exceeds%20the%20max%20retry%20count%20and%20returns%20the%20last%20response%20it%20received%20(successful%20or%20unsuccessful).%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThe%20first%20time%2C%20it%20attempts%20to%20get%20status%20code%20of%20200%20from%20the%20machine%20with%20IP%2010.0.0.4.%20But%20it%20receives%20204.%20So%2C%20it%20attempts%20to%20elicit%20the%20response%20from%2010.0.0.5%2C%20and%2010.0.0.6%20successfully.%20When%20all%20these%20machines%20respond%20with%20204%2C%20the%20APIM%20instance%20must%20evaluate%20the%20retry%20logic.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3ESince%20the%20first%20attempt%20is%20not%20a%20retry%2C%20the%20second%20attempt%20is%20considered%20the%20first%20retry.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThis%20means%20that%20it%20will%20retry%20all%20the%20machines%20in%20the%20cluster%20running%20the%20application%20in%20each%20retry%20attempt.%20Since%20I%20have%203%20machines%2C%20and%20max%20retry%20count%20is%205%2C%20I%20shall%20have%203%20x%205%20%3D%2015%20retries.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThis%20means%20that%20I%20shall%20have%203%20first%20attempts%20and%2015%20retries%2C%20therefore%2C%20I%20will%20have%20a%20total%20of%2018%20attempts%20to%20get%20the%20response%20code%20of%20204.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EThis%20number%20can%20be%20cut%20short%20if%20the%20total%20resolution%20timeout%20is%20reached.%20It%20is%20not%20unheard%20of%20to%20see%20lesser%20than%2018%20attempts.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAdditional%20Points%20to%20Note%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EFor%20the%20SF%20application%20to%20return%20multiple%20endpoints%2C%20you%20will%20have%20to%20configure%20your%20%3CAPPLICATION%3E.cs%20file%20and%20ServiceManifest%20file%20appropriately.%20For%20ensuring%20that%20one%20of%20the%20endpoint%20is%20HTTPS%2C%20you%20may%20follow%20the%20document%3A%20-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-fabric%2Fservice-fabric-tutorial-dotnet-app-enable-https-endpoint%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-fabric%2Fservice-fabric-tutorial-dotnet-app-enable-https-endpoint%3C%2FA%3E.%3C%2FAPPLICATION%3E%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3ESince%20the%20APIM%20acts%20as%20a%20gateway%20to%20the%20Service%20Fabric%20application%20in%20the%20backend%2C%20the%20APIM%20is%20put%20on%20the%20External%20VNet%20mode.%20You%20may%20choose%20to%20put%20the%20APIM%20on%20internal%20VNet%2C%20and%20expose%20the%20APIM%20endpoints%20using%20Application%20Gateway.%20The%20documentation%20for%20the%20same%20is%3A%20-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-paas-developer-blog%2Fintegrating-api-management-with-app-gateway%2Fba-p%2F1241650%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-paas-developer-blog%2Fintegrating-api-management-with-app-gateway%2Fba-p%2F1241650%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3EAPIM%20is%20used%20as%20a%20gateway%2Fingress%20point%20in%20front%20of%20stateless%20service.%20The%20following%20questions%20provide%20more%20clarity%20into%20the%20relation%20between%20APIM%20and%20SF%3A%0A%3CUL%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3E%3CSTRONG%3EHow%20APIM%20forwarding%20in%20response%20to%20instances%20changes%20of%20stateless%20service%2C%20specifically%2C%20how%20soon%20can%20it%20react%20to%20instance%20change%3F%3C%2FSTRONG%3E%3CBR%20%2F%3EAs%20soon%20as%20one%20of%20the%20request%20fails%20with%20error%20triggering%20re-resolve%20condition.%20By%20default%20it%E2%80%99s%20a%20failure%20to%20connect%20to%20instance%20IP%3APort%20but%20more%20conditions%20can%20be%20added%20through%20APIM%20policy.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3E%3CSTRONG%3EHow%20soon%20can%20a%20new%20instance%20added%20get%20traffic%3F%3C%2FSTRONG%3E%3CBR%20%2F%3EAPIM%20has%20sliding%20expiration%20cache%20of%20partition%20information%20with%2010%20minutes%20timeout%20which%20is%20invalidated%20by%20re-resolve.%20So%2C%20as%20long%20as%20all%20existing%20instances%20are%20up%20and%20healthy%20and%20requests%20targeting%20given%20partition%20come%20at%20least%20every%2010%20minutes%2C%20new%20nodes%20will%20not%20be%20added%20to%20the%20rotation.%20Cache%20is%20in%20memory%20and%20getting%20cleaned%20when%20APIM%20restarts%20but%20this%20is%20not%20predictable%20and%20cannot%20be%20triggered%20by%20the%20user.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3E%3CSTRONG%3EHow%20soon%20can%20forwarding%20to%20an%20old%20instance%20stop%3F%3C%2FSTRONG%3E%3CBR%20%2F%3EIt%20is%20the%20same%20situation%20as%20when%20a%20new%20instance%20is%20added.%20When%20the%20request%20to%20this%20old%20instance%20fails%2C%20it%20triggers%20the%20re-resolve%20condition%2C%20and%20stops%20the%20traffic%20flowing%20to%20the%20old%20instance.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-align-justify%22%3E%3CSTRONG%3EDoes%20it%20provide%20its%20own%20probe%20mechanism%20in%20addition%20to%20relying%20on%20SF%20naming%3F%3C%2FSTRONG%3E%3CBR%20%2F%3EToday%2C%20APIM%20doesn%E2%80%99t%20have%20probes%20and%20is%20not%20subscribed%20for%20address%20change%20notifications.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EAppendix%20A%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24cert%20%3D%20New-SelfSignedCertificate%20-DnsName%20servicefabricbackend.eastus.cloudapp.azure.com%20-CertStoreLocation%20%22cert%3A%5CLocalMachine%5CMy%22%20-KeyLength%202048%20-KeySpec%20%22KeyExchange%22%0A%0A%24password%20%3D%20ConvertTo-SecureString%20-String%20%22qwerty%22%20-Force%20-AsPlainText%0A%0AExport-PfxCertificate%20-Cert%20%24cert%20-FilePath%20%22.%5Capimsfcert.pfx%22%20-Password%20%24password%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1411732%22%20slang%3D%22en-US%22%3E%3CP%3EA%20walkthrough%20on%20adding%20API%20Management%20as%20a%20gateway%20to%20the%20Service%20Fabric%20backend.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1411732%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20API%20Management%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Service%20Fabric%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

The APIM instance will act as the gateway to the Service Fabric backend. The SF application used in this example can be found here: https://github.com/hakashya/APIM-with-Service-Fabric. You may clone the repository to replicate the results for your reference.

Certificate Handling:

The certificate used for creating the Service Fabric cluster is called the cluster certificate. In this example, this is a self-signed certificate. For the API Management instance to communicate with the service fabric backend, we need the cluster certificate to be uploaded to the API Management instance. The steps to do that is as follows:

  • Locate the certificate on your machine:
    CertScreenshot.png

     

  • Navigate to the Certificates blade on the Azure Portal for the APIM instance of interest:
    HarshaKashyap_1-1590156848548.png

     

  • Click on the “Add” button, marked as the 3rd step. Once this button is clicked, a wizard opens on the right, where the certificate can be uploaded. Select the right .pfx file that was located at the beginning of this section. Also, enter the password which protects the certificate. Once this is completed, click on the “Add” button on the bottom right corner marked as the 5th step.
  • Once the certificate is uploaded to the APIM instance, it can be used by the APIM instance for accessing the back end that is protected by the certificate.

Configuring the Backend Service for API Management Instance:

We will be adding a transformation policy for the API Management instance to redirect the calls towards the Service Fabric backend. To do this, the prerequisite is that a backend entity must be added to the API Management instance. As of now, it can only be done using REST APIs and PowerShell. Below is an example using REST API.

 

Details about the Service Fabric backend service used in this example:

The REST API reference for creating a backend entity is here: https://docs.microsoft.com/en-us/rest/api/apimanagement/2019-12-01/backend/createorupdate.

 

The API takes subscription ID, resource group name, API Management service name, and an identifier for the backend entity (which is equivalent to the name of the backend entity). Please note that the backend entity is just a representation of the Service Fabric application in API Management, but it is not the actual Service Fabric service itself.

 

The body of the PUT request, for this example, is:

 

 

{
	"properties": {
		"description": "Service Fabric Backend for APIM",
		"protocol": "http",
		"url": "fabric:/SFBackendForAPIM/WebAPI_Backend",
		"resourceId": "https://servicefabricbackend.eastus.cloudapp.azure.com:19080/",
		"tls": {
			"validateCertificateChain": "false"
		},
		"properties": {
			"serviceFabricCluster": {
				"managementEndpoints": [
					"https://servicefabricbackend.eastus.cloudapp.azure.com:19080"
				],
				"clientCertificatethumbprint": "76E97E3A746CB85AB83E431BDEB01C6DB168244B",
				"serverCertificateThumbprints": [
					"76E97E3A746CB85AB83E431BDEB01C6DB168244B"
				],
				"maxPartitionResolutionRetries ": 5
			}
		}
	}
}

 

 

  • The protocol specifies whether the backend is RESTful service (http) or SOAP service (soap).
  • The url specifies that the call should go to fabric:/<SFServiceName>/<SFApplication>. The fabric:/ is a call made to the naming service of the Service Fabric cluster. This url returns one partition with its listeners for the Application that was specified. We then make a call to this partition after resolution. In this example, the service name is SFBackendForAPIM, and the Application Name is WebAPI_Backend:
    HarshaKashyap_2-1590156848551.png

     

  • The resource ID is the same as the management endpoint.
  • The tls section elaborates the security features. In this example, since the certificate that is being used is self-signed, we are not validating the certificate chain. For a production cluster, it is recommended that validateCertificateChain is set to true, for security purposes.
  • The management endpoint belongs to the Service Fabric backend.
  • maxPartitionResolutionRetries property is used to inform the APIM service that it should attempt partition resolution exercise up to 5 times per partition (or instances, in case of stateless services).

The response for the above request is as follows:

 

 

{
	"id": "/subscriptions/cbxxxxxx-xxxx-xxxx-ac0f-99e4b64d2634/resourceGroups/SFCluster-RG/providers/Microsoft.ApiManagement/service/apimservicefabric/backends/sfbackend",
	"type": "Microsoft.ApiManagement/service/backends",
	"name": "sfbackend",
	"properties": {
		"title": null,
		"description": "Service Fabric Backend for APIM",
		"url": "fabric:/SFBackendForAPIM/WebAPI_Backend",
		"protocol": "http",
		"resourceId": "https://servicefabricbackend.eastus.cloudapp.azure.com:19080/",
		"properties": {
			"serviceFabricCluster": {
				"managementEndpoints": [
					"https://servicefabricbackend.eastus.cloudapp.azure.com:19080"
				],
				"clientCertificateThumbprint": "76E97E3A746CB85AB83E431BDEB01C6DB168244B",
				"serverCertificateThumbprints": [
					"76E97E3A746CB85AB83E431BDEB01C6DB168244B"
				],
				"maxPartitionResolutionRetries": 5
			}
		},
		"tls": {
			"validateCertificateChain": false
		}
	}
}

 

 

In case you do not know certain specifics about the Service Fabric cluster, you can always use the PowerShell cmdlet Get-AzServiceFabricCluster (https://docs.microsoft.com/en-us/powershell/module/az.servicefabric/Get-AzServiceFabricCluster?view=...) to gather information.

 

You may use any REST client to do this. The request with Postman would look something like the following:

HarshaKashyap_3-1590156848558.png

 

 

Configuring an API in APIM to access the backend:

We are all set to make use of the backend that we set up in the previous few sections. Now we shall create an API on the APIM instance, that could call the created backend service. The steps are as follows:

  • Navigate to the APIs blade on the API Management instance, and click on “Blank API” card, as shown below:
    HarshaKashyap_4-1590156848562.png

     

  • Fill in the details for the Blank API as follows:
    HarshaKashyap_5-1590156848563.png

     

  • Click on the "Add operation" button. Since this sample application is configured to receive simple GET requests, I am configuring a GET operation.
    HarshaKashyap_6-1590156848567.png

     

The GET URL would be the path to access our service. In this example, the controller in the application maps the route to /api/values, therefore, that route is given to the GET URL as the path. As the APIM instance and the SF Cluster are on the same VNet, they can communicate using private IP address. When a call is made to the naming service, it returns the private IPs for the listeners. The GET URL would then be appended to form the actual URL that is called. For example, if the naming service returns 10.0.0.5:20001 as the private IP of the instance serving our request, then the final URL which is called by the APIM is http://10.0.0.5:20001/api/values

 

APIM Policy Definition:

This the crucial step of action. The calls coming to the API management is redirected based on the policy we set. We will be using the set-backend policy (https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetBack...). The steps are:

  • Click on the </> icon on the “Inbound Processing”, as shown in this screenshot:
    HarshaKashyap_7-1590156848569.png

     

  • The set-backend policy is placed in the inbound section, as shown here:
    HarshaKashyap_8-1590156848573.png

The policy statement is:

 

 

<set-backend-service backend-id="sfbackend" sf-resolve-condition="@((int)context.Response.StatusCode != 200 || context.LastError?.Reason == "BackendConnectionFailure" || context.LastError?.Reason == "Timeout")" sf-listener-name= "HttpServiceEndpoint" />

 

 

  • Once the policy is saved, the integration between the Service Fabric cluster and API Management is complete.

Understanding the policy:

  • When the request hits the API Management service, it must pass through all the levels of APIM policies.
  • When we use the set-backend policy in the inbound section, we are changing the backend service to the one mentioned in the policy rather than the actual backend that was configured while creating the API.
  • In this example, we did not create an actual backend during the API creation, but we set the backend for all the inbound requests using the set-backend policy. As shown in the previous section: Configuring the Backend Service for API Management Instance, the name of the backend was “sfbackend”. This is the same name that is given as a value to the APIM policy as well. It means that the APIM instance picks up the details from the created backend entity.
  • The sf-resolve-condition refers to the retry condition. We had set the number of retries to 5, when we created the backend. Therefore, it ensures that if the sf-resolve-condition is met, there is an attempt to retry the partition resolution. In this case, the resolve condition is met if the response code from the backend is not 200, or if there is a Backend Connection Failure, or a Timeout while receiving a response from the backend.
  • Sf-listener-name indicates that when the naming service returns a list of listeners for a machine on the SF cluster serving our request, the listener with the name HttpServiceEndpoint must be chosen to make the request. Essentially, the name of the listener mentioned in the policy is the name of the listener chosen for making the request.

 

Validating the Set Up:

For any process, validation is necessary and crucial. For testing out if the set-up works, we can navigate to the “Test” tab on the Azure Portal for the APIM, for that Operation under the API. Below is the elaboration of the process:

  • Navigate to the test tab, and click on the API Operation
  • Hit the send button at the bottom.
  • The response seen has been received by the APIM instance. The response on your test tab should look like the following:
    HarshaKashyap_9-1590156848577.png

     

Understanding the Trace:

The trace section of the API call gives detailed insight into the process that takes place from the moment you hit send, till the moment you see the response on your screen. This allows us to perform analysis, debug our API, troubleshoot any issues, with the help of the trace. The trace for this example is available here: https://raw.githubusercontent.com/hakashya/APIM-with-Service-Fabric/master/WebAPI_Backend/apimtrace-....

 

An interesting thing to note is that, although we have specified that the maxPartitionResolutionRetries values for the APIM backend entity as 5, the number of resolution calls are 18 in this trace. The explanation for the same is as follows:

  • The SF Cluster used for in this example has 3 nodes. Each retry involves trying to elicit a response from all the machines until one of them successfully responds where the retry condition fails. If the retry condition succeeds, then there shall be another attempt to retry.
  • The retry condition fails if the response status code received is 200. If it is anything else, there will be more attempts at retrying until the desirable response is received or if it exceeds the max retry count.
  • Since this sample application responds with status code 204 always, the APIM instance exceeds the max retry count and returns the last response it received (successful or unsuccessful).
  • The first time, it attempts to get status code of 200 from the machine with IP 10.0.0.4. But it receives 204. So, it attempts to elicit the response from 10.0.0.5, and 10.0.0.6 successfully. When all these machines respond with 204, the APIM instance must evaluate the retry logic.
  • Since the first attempt is not a retry, the second attempt is considered the first retry.
  • This means that it will retry all the machines in the cluster running the application in each retry attempt. Since I have 3 machines, and max retry count is 5, I shall have 3 x 5 = 15 retries.
  • This means that I shall have 3 first attempts and 15 retries, therefore, I will have a total of 18 attempts to get the response code of 204.
  • This number can be cut short if the total resolution timeout is reached. It is not unheard of to see lesser than 18 attempts.

 

Additional Points to Note:

  • For the SF application to return multiple endpoints, you will have to configure your <Application>.cs file and ServiceManifest file appropriately. For ensuring that one of the endpoint is HTTPS, you may follow the document: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-tutorial-dotnet-app-enable-http....
  • Since the APIM acts as a gateway to the Service Fabric application in the backend, the APIM is put on the External VNet mode. You may choose to put the APIM on internal VNet, and expose the APIM endpoints using Application Gateway. The documentation for the same is: https://techcommunity.microsoft.com/t5/azure-paas-developer-blog/integrating-api-management-with-app....
  • APIM is used as a gateway/ingress point in front of stateless service. The following questions provide more clarity into the relation between APIM and SF:
    • How APIM forwarding in response to instances changes of stateless service, specifically, how soon can it react to instance change?
      As soon as one of the request fails with error triggering re-resolve condition. By default it’s a failure to connect to instance IP:Port but more conditions can be added through APIM policy.
    • How soon can a new instance added get traffic?
      APIM has sliding expiration cache of partition information with 10 minutes timeout which is invalidated by re-resolve. So, as long as all existing instances are up and healthy and requests targeting given partition come at least every 10 minutes, new nodes will not be added to the rotation. Cache is in memory and getting cleaned when APIM restarts but this is not predictable and cannot be triggered by the user.
    • How soon can forwarding to an old instance stop?
      It is the same situation as when a new instance is added. When the request to this old instance fails, it triggers the re-resolve condition, and stops the traffic flowing to the old instance.
    • Does it provide its own probe mechanism in addition to relying on SF naming?
      Today, APIM doesn’t have probes and is not subscribed for address change notifications.

Appendix A:

 

$cert = New-SelfSignedCertificate -DnsName servicefabricbackend.eastus.cloudapp.azure.com -CertStoreLocation "cert:\LocalMachine\My" -KeyLength 2048 -KeySpec "KeyExchange"

$password = ConvertTo-SecureString -String "qwerty" -Force -AsPlainText

Export-PfxCertificate -Cert $cert -FilePath ".\apimsfcert.pfx" -Password $password