简体   繁体   English

在Service Fabric Service中启用每个端点的gzip压缩

[英]Enabling gzip compression per-endpoint in Service Fabric Service

Our application uses Service Fabric as its backbone and our microservices are Service Fabric Services. 我们的应用程序使用Service Fabric作为其骨干,而我们的微服务是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. 在前端使用Lighthouse进行了一些审核之后,我看到列出了enable text based compression的建议,并开始研究如何在某些响应中添加gzip

For our Node server, I simply added the compression middleware and used it. 对于我们的Node服务器,我只是添加了compression中间件并使用了它。

For other services, I went inside of the Web.config and added the following: 对于其他服务,我进入了Web.config并添加了以下内容:

<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. 重新加载我的Web应用程序后,我确实注意到响应现在已经压缩了,但是我不想压缩所有响应。

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: 编辑您的ServiceDefinition.csdef文件,以将其包含在WebRole标记中:

<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” 在您的网络角色中,创建一个文本文件并将其另存为“ EnableCompression.cmd”

  2. EnableCompression.cmd should contain this: EnableCompression.cmd应包含以下内容:

    %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. 这个简单的过程将为Azure中Web角色返回的json启用动态压缩。

Source: https://cloudmonix.com/blog/how-to-enable-gzip-http-compression-on-windows-azure-endpoint/ 来源: 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://basecamp.kony.com/s/question/0D56A00000RbtbBSAR/how-to-enable-gzip-compression-in-mobile-fabric

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

How to enable gzip HTTP compression on Windows Azure dynamic content 如何在Windows Azure动态内容上启用gzip HTTP压缩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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