43 changed files with 340 additions and 159 deletions
@ -0,0 +1,58 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 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.queue.housekeeper; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.data.housekeeper.HousekeeperTask; |
||||
|
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
||||
|
import org.thingsboard.server.common.msg.housekeeper.HousekeeperClient; |
||||
|
import org.thingsboard.server.gen.transport.TransportProtos; |
||||
|
import org.thingsboard.server.gen.transport.TransportProtos.ToHousekeeperServiceMsg; |
||||
|
import org.thingsboard.server.queue.TbQueueProducer; |
||||
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
||||
|
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class DefaultHousekeeperClient implements HousekeeperClient { |
||||
|
|
||||
|
private final TbQueueProducer<TbProtoQueueMsg<ToHousekeeperServiceMsg>> producer; |
||||
|
private final TopicPartitionInfo submitTpi; |
||||
|
|
||||
|
public DefaultHousekeeperClient(TbQueueProducerProvider producerProvider) { |
||||
|
this.producer = producerProvider.getHousekeeperMsgProducer(); |
||||
|
this.submitTpi = TopicPartitionInfo.builder().topic(producer.getDefaultTopic()).build(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void submitTask(HousekeeperTask task) { |
||||
|
log.trace("[{}][{}][{}] Submitting task: {}", task.getTenantId(), task.getEntityId().getEntityType(), task.getEntityId(), task.getTaskType()); |
||||
|
/* |
||||
|
* using msg key as entity id so that msgs related to certain entity are pushed to same partition, |
||||
|
* e.g. on tenant deletion (entity id is tenant id), we need to clean up tenant entities in certain order |
||||
|
* */ |
||||
|
producer.send(submitTpi, new TbProtoQueueMsg<>(task.getEntityId().getId(), ToHousekeeperServiceMsg.newBuilder() |
||||
|
.setTask(TransportProtos.HousekeeperTaskProto.newBuilder() |
||||
|
.setValue(JacksonUtil.toString(task)) |
||||
|
.setTs(task.getTs()) |
||||
|
.setAttempt(0) |
||||
|
.build()) |
||||
|
.build()), null); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 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.queue.provider; |
||||
|
|
||||
|
import org.thingsboard.server.gen.transport.TransportProtos.ToHousekeeperServiceMsg; |
||||
|
import org.thingsboard.server.queue.TbQueueProducer; |
||||
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
||||
|
|
||||
|
public interface HousekeeperClientQueueFactory { |
||||
|
|
||||
|
TbQueueProducer<TbProtoQueueMsg<ToHousekeeperServiceMsg>> createHousekeeperMsgProducer(); |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue