聊聊artemis的ResourceLimitSettings
ResourceLimitSettings
activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/ResourceLimitSettings.java
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
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
以上是 聊聊artemis的ResourceLimitSettings 的全部内容, 来源链接: utcz.com/z/513684.html