Fix Rule Engine consumers init when tenant becomes managed
This commit is contained in:
parent
492dc5916e
commit
e806c1c86e
@ -193,7 +193,9 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod
|
||||
boolean result = ruleNode == null || !ruleNode.isSingletonMode()
|
||||
|| systemContext.getDiscoveryService().isMonolith()
|
||||
|| defaultCtx.isLocalEntity(ruleNode.getId());
|
||||
log.trace("[{}][{}] Is not my node partition", tenantId, entityId);
|
||||
if (!result) {
|
||||
log.trace("[{}][{}] Is not my node partition", tenantId, entityId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ public class TenantActor extends RuleChainManagerActor {
|
||||
return;
|
||||
}
|
||||
TbMsg tbMsg = msg.getMsg();
|
||||
if (getApiUsageState().isReExecEnabled()) {
|
||||
if (getApiUsageState().isReExecEnabled() && ruleChainsInitialized) {
|
||||
if (tbMsg.getRuleChainId() == null) {
|
||||
if (getRootChainActor() != null) {
|
||||
getRootChainActor().tell(msg);
|
||||
@ -207,7 +207,7 @@ public class TenantActor extends RuleChainManagerActor {
|
||||
}
|
||||
|
||||
private void onRuleChainMsg(RuleChainAwareMsg msg) {
|
||||
if (getApiUsageState().isReExecEnabled()) {
|
||||
if (getApiUsageState().isReExecEnabled() && ruleChainsInitialized) {
|
||||
getOrCreateActor(msg.getRuleChainId()).tell(msg);
|
||||
}
|
||||
}
|
||||
@ -233,7 +233,7 @@ public class TenantActor extends RuleChainManagerActor {
|
||||
if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) {
|
||||
if (systemContext.getPartitionService().isManagedByCurrentService(tenantId)) {
|
||||
if (!ruleChainsInitialized) {
|
||||
log.info("Tenant {} is already managed by this service, initializing rule chains", tenantId);
|
||||
log.info("Tenant {} is now managed by this service, initializing rule chains", tenantId);
|
||||
initRuleChains();
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -100,7 +100,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
|
||||
for (Queue configuration : queues) {
|
||||
if (partitionService.isManagedByCurrentService(configuration.getTenantId())) {
|
||||
QueueKey queueKey = new QueueKey(ServiceType.TB_RULE_ENGINE, configuration);
|
||||
getOrCreateConsumer(queueKey).init(configuration);
|
||||
createConsumer(queueKey, configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,11 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
|
||||
protected void onTbApplicationEvent(PartitionChangeEvent event) {
|
||||
event.getPartitionsMap().forEach((queueKey, partitions) -> {
|
||||
if (partitionService.isManagedByCurrentService(queueKey.getTenantId())) {
|
||||
getOrCreateConsumer(queueKey).update(partitions);
|
||||
var consumer = getConsumer(queueKey).orElseGet(() -> {
|
||||
Queue config = queueService.findQueueByTenantIdAndName(queueKey.getTenantId(), queueKey.getQueueName());
|
||||
return createConsumer(queueKey, config);
|
||||
});
|
||||
consumer.update(partitions);
|
||||
}
|
||||
});
|
||||
consumers.keySet().stream()
|
||||
@ -190,9 +194,9 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
|
||||
QueueKey queueKey = new QueueKey(ServiceType.TB_RULE_ENGINE, queueName, tenantId);
|
||||
Queue queue = queueService.findQueueById(tenantId, queueId);
|
||||
|
||||
TbRuleEngineQueueConsumerManager consumerManager = getOrCreateConsumer(queueKey);
|
||||
Queue oldQueue = consumerManager.getQueue();
|
||||
consumerManager.update(queue);
|
||||
var consumer = getConsumer(queueKey).orElseGet(() -> createConsumer(queueKey, queue));
|
||||
Queue oldQueue = consumer.getQueue();
|
||||
consumer.update(queue);
|
||||
|
||||
if (oldQueue == null || queue.getPartitions() != oldQueue.getPartitions()) {
|
||||
partitionsChanged = true;
|
||||
@ -235,8 +239,15 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
|
||||
}
|
||||
}
|
||||
|
||||
private TbRuleEngineQueueConsumerManager getOrCreateConsumer(QueueKey queueKey) {
|
||||
return consumers.computeIfAbsent(queueKey, key -> new TbRuleEngineQueueConsumerManager(ctx, key));
|
||||
private Optional<TbRuleEngineQueueConsumerManager> getConsumer(QueueKey queueKey) {
|
||||
return Optional.ofNullable(consumers.get(queueKey));
|
||||
}
|
||||
|
||||
private TbRuleEngineQueueConsumerManager createConsumer(QueueKey queueKey, Queue queue) {
|
||||
var consumer = new TbRuleEngineQueueConsumerManager(ctx, queueKey);
|
||||
consumers.put(queueKey, consumer);
|
||||
consumer.init(queue);
|
||||
return consumer;
|
||||
}
|
||||
|
||||
private Optional<TbRuleEngineQueueConsumerManager> removeConsumer(QueueKey queueKey) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user