Browse Source

msg: let PartitionChangeMsg optionally target specific tenants

PartitionChangeMsg only carried the affected ServiceType, so a
consumer had no way to know which specific tenants (if any) a given
partition change actually affects versus all of them. Add an optional
affectedTenants set: null preserves today's meaning ("could affect
anyone, notify everyone"), a non-null set means only those tenants are
affected. Existing single-arg construction is unchanged and keeps
defaulting to null.
pull/15961/head
Sergey Matvienko 5 months ago
parent
commit
1528864968
  1. 22
      common/message/src/main/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsg.java
  2. 47
      common/message/src/test/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsgTest.java

22
common/message/src/main/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsg.java

@ -3,19 +3,37 @@
package org.thingsboard.server.common.msg.queue;
import lombok.Data;
import lombok.Getter;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.msg.MsgType;
import org.thingsboard.server.common.msg.TbActorMsg;
import java.util.Set;
/**
* @author Andrew Shvayka
*/
@Data
public final class PartitionChangeMsg implements TbActorMsg {
@Getter
private final ServiceType serviceType;
/**
* Tenants whose partition ownership changed. Null means the shared
* (non-isolated) tenant pool itself changed, so every tenant actor must
* re-verify — shared-pool tenants aren't individually tracked as
* queueKeys, so they can't be enumerated here.
*/
private final Set<TenantId> affectedTenants;
public PartitionChangeMsg(ServiceType serviceType) {
this(serviceType, null);
}
public PartitionChangeMsg(ServiceType serviceType, Set<TenantId> affectedTenants) {
this.serviceType = serviceType;
this.affectedTenants = affectedTenants;
}
@Override
public MsgType getMsgType() {
return MsgType.PARTITION_CHANGE_MSG;

47
common/message/src/test/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsgTest.java

@ -0,0 +1,47 @@
/**
* Copyright © 2016-2026 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.queue;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.msg.MsgType;
import java.util.Set;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class PartitionChangeMsgTest {
@Test
public void singleArgConstructor_defaultsAffectedTenantsToNull() {
PartitionChangeMsg msg = new PartitionChangeMsg(ServiceType.TB_RULE_ENGINE);
assertEquals(ServiceType.TB_RULE_ENGINE, msg.getServiceType());
assertNull(msg.getAffectedTenants());
assertEquals(MsgType.PARTITION_CHANGE_MSG, msg.getMsgType());
}
@Test
public void twoArgConstructor_carriesAffectedTenants() {
TenantId tenant = new TenantId(UUID.randomUUID());
PartitionChangeMsg msg = new PartitionChangeMsg(ServiceType.TB_RULE_ENGINE, Set.of(tenant));
assertEquals(ServiceType.TB_RULE_ENGINE, msg.getServiceType());
assertEquals(Set.of(tenant), msg.getAffectedTenants());
}
}
Loading…
Cancel
Save