前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >聊聊artemis的ResourceLimitSettings

聊聊artemis的ResourceLimitSettings

作者头像
code4it
发布2020-02-26 15:48:14
4070
发布2020-02-26 15:48:14
举报
文章被收录于专栏:码匠的流水账

本文主要研究一下artemis的ResourceLimitSettings

ResourceLimitSettings

activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/ResourceLimitSettings.java

代码语言:javascript
复制
public class ResourceLimitSettings implements Serializable, EncodingSupport {

   private static final long serialVersionUID = -110638321333856932L;

   public static final SimpleString DEFAULT_MATCH = null;

   public static final Integer DEFAULT_MAX_CONNECTIONS = -1;

   public static final Integer DEFAULT_MAX_QUEUES = -1;

   SimpleString match = null;

   Integer maxConnections = null;

   Integer maxQueues = null;

   //......
}
  • ResourceLimitSettings定义了maxConnections、maxQueues属性

ActiveMQServerImpl

activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java

代码语言:javascript
复制
public class ActiveMQServerImpl implements ActiveMQServer {

   //......

   private void checkSessionLimit(String username) throws Exception {
      if (configuration.getResourceLimitSettings() != null && configuration.getResourceLimitSettings().containsKey(username)) {
         ResourceLimitSettings limits = configuration.getResourceLimitSettings().get(username);

         if (limits.getMaxConnections() == -1) {
            return;
         } else if (limits.getMaxConnections() == 0 || getSessionCountForUser(username) >= limits.getMaxConnections()) {
            throw ActiveMQMessageBundle.BUNDLE.sessionLimitReached(username, limits.getMaxConnections());
         }
      }
   }

   private int getSessionCountForUser(String username) {
      int sessionCount = 0;

      for (Entry<String, ServerSession> sessionEntry : sessions.entrySet()) {
         if (sessionEntry.getValue().getUsername().equals(username)) {
            sessionCount++;
         }
      }

      return sessionCount;
   }

   public void checkQueueCreationLimit(String username) throws Exception {
      if (configuration.getResourceLimitSettings() != null && configuration.getResourceLimitSettings().containsKey(username)) {
         ResourceLimitSettings limits = configuration.getResourceLimitSettings().get(username);

         if (limits.getMaxQueues() == -1) {
            return;
         } else if (limits.getMaxQueues() == 0 || getQueueCountForUser(username) >= limits.getMaxQueues()) {
            throw ActiveMQMessageBundle.BUNDLE.queueLimitReached(username, limits.getMaxQueues());
         }
      }
   }

   public int getQueueCountForUser(String username) throws Exception {
      Map<SimpleString, Binding> bindings = postOffice.getAllBindings();

      int queuesForUser = 0;

      for (Binding binding : bindings.values()) {
         if (binding instanceof LocalQueueBinding && ((LocalQueueBinding) binding).getQueue().getUser().equals(SimpleString.toSimpleString(username))) {
            queuesForUser++;
         }
      }

      return queuesForUser;

   }

   //......
}
  • ActiveMQServerImpl的checkSessionLimit方法会获取指定username的ResourceLimitSettings,若getSessionCountForUser大于等于limits.getMaxConnections()或者limits.getMaxConnections()为0,则抛出ActiveMQMessageBundle.BUNDLE.sessionLimitReached;checkQueueCreationLimit方法会获取指定username的ResourceLimitSettings,若getQueueCountForUser大于等于limits.getMaxQueues()或者limits.getMaxQueues() == 0,则抛出ActiveMQMessageBundle.BUNDLE.queueLimitReached

小结

ResourceLimitSettings定义了maxConnections、maxQueues属性;artemis在createSession的时候会执行checkSessionLimit方法,在createQueue的时候会执行checkQueueCreationLimit方法

doc

  • ResourceLimitSettings
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-02-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ResourceLimitSettings
  • ActiveMQServerImpl
  • 小结
  • doc
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档