访问服务器 request.getheader(origin)为null_Wowza技术:如何停止向到达负载极限的edge服务器重定向?...

2cd640f8041f39947d4995050c6ba764.png

这个模块安装在一个edge服务器上,当这台edge服务器到达负载极限时,它会停止向Load Balancer listener发送自己的状态信息。这样新的客户连接请求就不会重定向到这台edge服务器上。 

这个edge服务器不会限制客户端对它的直接访问,只是不会再有重定向到它的连接请求。 注意: 这个模块是针对LoadBalancer 2.0版本的附加模块,这个服务器必须按照如何获得Wowza的动态负载均衡模块的介绍,被配置为Load Balancer Listener edge服务器。 

packagecom.wowza.wms.plugin.collection.module;

//com.wowza.wms.plugin.collection.module.ModuleLoadBalancerEdgeLimitConnections

importcom.wowza.wms.amf.AMFDataList;

importcom.wowza.wms.application.IApplicationInstance;

importcom.wowza.wms.client.ConnectionCounter;

importcom.wowza.wms.client.IClient;

importcom.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.HTTPStreamerSessionCupertino;

importcom.wowza.wms.httpstreamer.sanjosestreaming.httpstreamer.HTTPStreamerSessionSanJose;

importcom.wowza.wms.httpstreamer.smoothstreaming.httpstreamer.HTTPStreamerSessionSmoothStreamer;

importcom.wowza.wms.logging.WMSLoggerIDs;

importcom.wowza.wms.module.ModuleBase;

importcom.wowza.wms.plugin.loadbalancer.LoadBalancerSender;

importcom.wowza.wms.plugin.loadbalancer.ServerListenerLoadBalancerSender;

importcom.wowza.wms.request.RequestFunction;

importcom.wowza.wms.rtp.model.RTPSession;

importcom.wowza.wms.server.Server;

publicclass ModuleLoadBalancerEdgeLimitConnections extends ModuleBase

{

         static final public int MAXCONNECTIONS= 200;

         private ConnectionCounter counter;

         private int maxEdgeConnections =MAXCONNECTIONS;

         private LoadBalancerSenderloadBalancerSender;

         public voidonAppStart(IApplicationInstance appInstance)

         {

                   this.counter =appInstance.getConnectionCounter();

                   this.maxEdgeConnections =appInstance.getProperties().getPropertyInt("maxEdgeConnections",maxEdgeConnections);

                   loadBalancerSender =(LoadBalancerSender)Server.getInstance().getProperties().get(ServerListenerLoadBalancerSender.PROP_LOADBALANCERSENDER);

                   getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsmaxEdgeConnections: " + maxEdgeConnections);

         }

         public void changeLimitEdge(IClientclient, RequestFunction function,

                            AMFDataList params){

                   Integer newLimit =params.getInt(PARAM1);

                   this.maxEdgeConnections =newLimit;

                   getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsNew Limit: " + newLimit);

         }

         private void addConnection() {

                   loadBalancerSender =(LoadBalancerSender)Server.getInstance().getProperties().get(ServerListenerLoadBalancerSender.PROP_LOADBALANCERSENDER);

                   if (loadBalancerSender ==null)

                   {

                            getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsError (addConnection): Load Balancer Sender is not installed",WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);

                            return;

                   }

                   long count =counter.getCurrent();

                   if ((count+1) >this.maxEdgeConnections)

                   {

                            loadBalancerSender.pause();

                            getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsPause", WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);

                   }

                   getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsCount: " + count, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);

         }

         private void removeConnection() {

                   loadBalancerSender =(LoadBalancerSender)Server.getInstance().getProperties().get(ServerListenerLoadBalancerSender.PROP_LOADBALANCERSENDER);

                   if (loadBalancerSender ==null)

                   {

                            getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsError (removeConnection): Load Balancer Sender is not installed",WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);

                            return;

                   }

                   long count =counter.getCurrent();

                   if ((count-1)

                   {

                            loadBalancerSender.unpause();

                            getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsUnPause", WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);

                   }

                   getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsCount: " + count, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);

         }

         public void onConnect(IClient client,RequestFunction function, AMFDataList params)

         {                

                   addConnection();

         }

         public void onDisconnect(IClientclient) {

                   removeConnection();

         }

         public voidonHTTPSmoothStreamingSessionCreate(HTTPStreamerSessionSmoothStreamer httpSmoothStreamingSession)

         {

                   addConnection();              

         }

         public voidonHTTPSmoothStreamingSessionDestroy(HTTPStreamerSessionSmoothStreamerhttpSmoothStreamingSession)

         {

                   removeConnection();                

         }

         public voidonHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertinohttpCupertinoStreamingSession)

         {

                   addConnection();              

         }

         public voidonHTTPCupertinoStreamingSessionDestroy(HTTPStreamerSessionCupertinohttpCupertinoStreamingSession)

         {

                   removeConnection();                

         }

         public void onHTTPSanjoseStreamingSessionCreate(HTTPStreamerSessionSanJosehttpSanJoseStreamingSession)

         {

                   addConnection();

         }

         public voidonHTTPSanjoseStreamingSessionDestroy(HTTPStreamerSessionSanJosehttpSanJoseStreamingSession)

         {

                   removeConnection();

         }

         public voidonRTPSessionCreate(RTPSession rtpSession)

         {

                   addConnection();    

         }

         public voidonRTPSessionDestroy(RTPSession rtpSession)

         {

                   removeConnection();

         }

}

这个模块编译后的版本已经被包含在Wowza的可选自定义模块。下载并解压缩后,将/lib/wms-plugin-collection.jar拷贝到Wowza安装目录下的 /lib 文件夹下。然后重启Wowza。 在/conf/[app-name]/Application.xml文件的模块列表的最后添加下面的模块。 

ModuleLoadBalancerEdgeLimitConnections

Limit connects to an edge

com.wowza.wms.plugin.collection.module.ModuleLoadBalancerEdgeLimitConnections

将下面的属性参数添加到属性列表中(在模块列表的下面) 

maxEdgeConnections

200

Wowza Streaming Engine 4是业界功能强大、API接口丰富的流媒体Server产品,采用它作为流媒体服务器产品的案例很多,直播、在线教育、IPTV都有它的用武之地。

公司名称:北京哲想软件有限公司

北京哲想软件官方网站:www.cogitosoft.com

北京哲想软件微信公众平台账号:cogitosoftware

北京哲想软件微博:哲想软件

北京哲想软件邮箱:sales@cogitosoft.com

销售(俞先生)联系方式:+86(010)68421378

微信:18610247936     QQ:368531638

fc1caf74395dc6caf8dd6b17e07f681f.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值