committed by
GitHub
3 changed files with 97 additions and 1 deletions
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2025 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.config; |
|||
|
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.scheduling.annotation.EnableAsync; |
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|||
|
|||
import java.util.concurrent.Executor; |
|||
|
|||
@Configuration |
|||
@EnableAsync |
|||
public class AsyncConfig { |
|||
|
|||
@Bean("deviceEventExecutor") |
|||
public Executor deviceEventExecutor() { |
|||
ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor(); |
|||
exec.setCorePoolSize(2); |
|||
exec.setMaxPoolSize(5); |
|||
exec.setQueueCapacity(100); |
|||
exec.setThreadNamePrefix("device-event-"); |
|||
exec.initialize(); |
|||
return exec; |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2025 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.dao.device; |
|||
|
|||
import org.springframework.context.ApplicationEventPublisher; |
|||
import org.springframework.scheduling.annotation.Async; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.cache.device.DeviceCacheEvictEvent; |
|||
import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent; |
|||
|
|||
@Service |
|||
public class AsyncDeviceEventPublisher { |
|||
private final ApplicationEventPublisher publisher; |
|||
public AsyncDeviceEventPublisher(ApplicationEventPublisher publisher) { |
|||
this.publisher = publisher; |
|||
} |
|||
|
|||
@Async("deviceEventExecutor") |
|||
public void publishCacheEvictEventAsync(DeviceCacheEvictEvent event) { |
|||
publisher.publishEvent(event); |
|||
} |
|||
|
|||
@Async("deviceEventExecutor") |
|||
public void publishSaveEventAsync(SaveEntityEvent event) { |
|||
publisher.publishEvent(event); |
|||
} |
|||
} |
|||
|
|||
|
|||
Loading…
Reference in new issue