简体   繁体   中英

Enabling gzip compression per-endpoint in Service Fabric Service

Our application uses Service Fabric as its backbone and our microservices are Service Fabric Services. After running some auditing using Lighthouse on the front-end, I saw that the recommendation to enable text based compression was listed and began investigating how I can add gzip to some of my responses.

For our Node server, I simply added the compression middleware and used it.

For other services, I went inside of the Web.config and added the following:

<urlCompression doStaticCompression="true" doDynamicCompression="true"/>

<httpCompression>
  <dynamicTypes>
    <clear />
    <add enabled="true"  mimeType="application/json"/>
  </dynamicTypes>
  <staticTypes>
    <clear />
    <add enabled="true"  mimeType="application/json"/>
  </staticTypes>
</httpCompression>

Upon reloading my web app, I did notice that the responses were now coming in compressed, but I do not want to necessarily compress all responses.

When I setup any of my endpoints, I follow the following format:

[HttpGet]
[Route("{customer}/items")]
[Authorize]
public Task<ItemsModel> Get()
{
    return _itemsService.GetAsync();
}

Is there a way to enable compression on a per-endpoint basis instead of per-service?

Here is the process;

  1. Edit your ServiceDefinition.csdef file to contain this in the WebRole tag:

<Startup> <Task commandLine="EnableCompression.cmd" executionContext="elevated" taskType="simple"></Task> </Startup>

  1. In your web-role, create a text file and save it as “EnableCompression.cmd”

  2. EnableCompression.cmd should contain this:

    %windir%\\system32\\inetsrv\\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost %windir%\\system32\\inetsrv\\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost

This simple process will enable dynamic compression for the json returned by the web-role in Azure.

Source: https://cloudmonix.com/blog/how-to-enable-gzip-http-compression-on-windows-azure-endpoint/

You can see also these:

https://basecamp.kony.com/s/question/0D56A00000RbtbBSAR/how-to-enable-gzip-compression-in-mobile-fabric

https://code.i-harness.com/en/q/2a58dd

How to enable gzip HTTP compression on Windows Azure dynamic content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM