ARTEMIS-2934 Add option to suppress SESSION notifications

This commit is contained in:
AntonRoskvist 2022-02-09 11:22:51 +01:00 committed by Justin Bertram
parent 7ea5010d04
commit 99b9d87bfd
No known key found for this signature in database
GPG Key ID: F41830B875BB8633
10 changed files with 87 additions and 0 deletions

View File

@ -647,6 +647,9 @@ public final class ActiveMQDefaultConfiguration {
// How often (in ms) to scan for expired MQTT sessions
private static long DEFAULT_MQTT_SESSION_SCAN_INTERVAL = 500;
// If SESSION-notifications should be suppressed or not
public static boolean DEFAULT_SUPPRESS_SESSION_NOTIFICATIONS = false;
/**
* If true then the ActiveMQ Artemis Server will make use of any Protocol Managers that are in available on the classpath. If false then only the core protocol will be available, unless in Embedded mode where users can inject their own Protocol Managers.
*/
@ -1772,4 +1775,9 @@ public final class ActiveMQDefaultConfiguration {
public static long getMqttSessionScanInterval() {
return DEFAULT_MQTT_SESSION_SCAN_INTERVAL;
}
public static boolean getDefaultSuppressSessionNotifications() {
return DEFAULT_SUPPRESS_SESSION_NOTIFICATIONS;
}
}

View File

@ -1393,4 +1393,12 @@ public interface Configuration {
*/
long getMqttSessionScanInterval();
/**
* Returns whether suppression of session-notifications is enabled for this server. <br>
* Default value is {@link org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration#DEFAULT_SUPPRESS_SESSION_NOTIFICATIONS}.
*/
boolean isSuppressSessionNotifications();
Configuration setSuppressSessionNotifications(boolean suppressSessionNotifications);
}

View File

@ -387,6 +387,7 @@ public class ConfigurationImpl implements Configuration, Serializable {
private long mqttSessionScanInterval = ActiveMQDefaultConfiguration.getMqttSessionScanInterval();
private boolean suppressSessionNotifications = ActiveMQDefaultConfiguration.getDefaultSuppressSessionNotifications();
/**
* Parent folder for all data folders.
@ -2690,6 +2691,17 @@ public class ConfigurationImpl implements Configuration, Serializable {
return this;
}
@Override
public boolean isSuppressSessionNotifications() {
return suppressSessionNotifications;
}
@Override
public Configuration setSuppressSessionNotifications(boolean suppressSessionNotifications) {
this.suppressSessionNotifications = suppressSessionNotifications;
return this;
}
// extend property utils with ability to auto-fill and locate from collections
// collection entries are identified by the name() property
private static class CollectionAutoFillPropertiesUtil extends PropertyUtilsBean {

View File

@ -323,6 +323,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
private static final String ENABLE_INGRESS_TIMESTAMP = "enable-ingress-timestamp";
private static final String SUPPRESS_SESSION_NOTIFICATIONS = "suppress-session-notifications";
private boolean validateAIO = false;
@ -769,6 +770,8 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
config.setPageSyncTimeout(getInteger(e, "page-sync-timeout", config.getJournalBufferTimeout_NIO(), Validators.GE_ZERO));
config.setSuppressSessionNotifications(getBoolean(e, "suppress-session-notifications", config.isSuppressSessionNotifications()));
parseAddressSettings(e, config);
parseResourceLimits(e, config);

View File

@ -474,6 +474,9 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
}
private void sendSessionNotification(final CoreNotificationType type) throws Exception {
if (server.getConfiguration().isSuppressSessionNotifications()) {
return;
}
final TypedProperties props = new TypedProperties();
if (this.getConnectionID() != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_CONNECTION_NAME, SimpleString.toSimpleString(this.getConnectionID().toString()));

View File

@ -1000,6 +1000,16 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="suppress-session-notifications" type="xsd:boolean" default="false" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Whether or not to suppress SESSION_CREATED and SESSION_CLOSED notifications.
Set to true to reduce notification overhead. However, these are required to
enforce unique client ID utilization in a cluster for MQTT clients.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="security-settings" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>

View File

@ -136,6 +136,7 @@ public class FileConfigurationTest extends ConfigurationImplTest {
Assert.assertEquals("somedir", conf.getBindingsDirectory());
Assert.assertEquals(false, conf.isCreateBindingsDir());
Assert.assertEquals(true, conf.isAmqpUseCoreSubscriptionNaming());
Assert.assertEquals(false, conf.isSuppressSessionNotifications());
Assert.assertEquals("max concurrent io", 17, conf.getPageMaxConcurrentIO());
Assert.assertEquals(true, conf.isReadWholePage());

View File

@ -67,6 +67,7 @@
<critical-analyzer-check-period>333</critical-analyzer-check-period>
<critical-analyzer-timeout>777</critical-analyzer-timeout>
<critical-analyzer>false</critical-analyzer>
<suppress-session-notifications>false</suppress-session-notifications>
<remoting-incoming-interceptors>
<class-name>org.apache.activemq.artemis.tests.unit.core.config.impl.TestInterceptor1</class-name>
<class-name>org.apache.activemq.artemis.tests.unit.core.config.impl.TestInterceptor2</class-name>

View File

@ -723,6 +723,21 @@ configured in `broker.xml`:
By default, the address is `activemq.notifications`.
#### Suppressing Session Notifications
Some messaging patterns can generate a lot of `SESSION_CREATED` and
`SESSION_CLOSED` notifications. In a clustered environment this will come with
some computational overhead. If these notifications are not otherwise used they
can be disabled through:
```xml
<suppress-session-notifications>true</suppress-session-notifications>
```
The only time these notifications are *required* is in a cluster with MQTT
clients where unique client ID utilization needs to be enforced. Default value
is `false`
#### Receiving Notification Messages
Apache ActiveMQ Artemis's Core JMS Client can be used to receive notifications:

View File

@ -193,6 +193,32 @@ public class NotificationTest extends ActiveMQTestBase {
session.deleteQueue(queue);
}
@Test
public void testSuppressSessionNotifications() throws Exception {
server.getConfiguration().setSuppressSessionNotifications(false);
ClientSessionFactory sf = createSessionFactory(locator);
NotificationTest.flush(notifConsumer);
ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
mySession.start();
ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
Assert.assertEquals(SESSION_CREATED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
mySession.close();
notifications = NotificationTest.consumeMessages(1, notifConsumer);
Assert.assertEquals(SESSION_CLOSED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
NotificationTest.flush(notifConsumer);
server.getConfiguration().setSuppressSessionNotifications(true);
mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
mySession.start();
NotificationTest.consumeMessages(0, notifConsumer);
mySession.close();
NotificationTest.consumeMessages(0, notifConsumer);
}
@Test
public void testCONSUMER_CLOSED() throws Exception {
ClientSessionFactory sf = createSessionFactory(locator);