don't generate amqp devices at startup if amqp is disabled
Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.simulator;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
|
||||
import org.eclipse.hawkbit.simulator.amqp.AmqpProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -32,24 +32,27 @@ public class SimulatorStartup implements ApplicationListener<ContextRefreshedEve
|
||||
@Autowired
|
||||
private SimulationProperties simulationProperties;
|
||||
|
||||
@Autowired
|
||||
private SpSenderService spSenderService;
|
||||
|
||||
@Autowired
|
||||
private DeviceSimulatorRepository repository;
|
||||
|
||||
@Autowired
|
||||
private SimulatedDeviceFactory deviceFactory;
|
||||
|
||||
@Autowired
|
||||
private AmqpProperties amqpProperties;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(final ContextRefreshedEvent event) {
|
||||
simulationProperties.getAutostarts().forEach(autostart -> {
|
||||
for (int i = 0; i < autostart.getAmount(); i++) {
|
||||
final String deviceId = autostart.getName() + i;
|
||||
try {
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
|
||||
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
|
||||
autostart.getGatewayToken()));
|
||||
if (amqpProperties.isEnabled()) {
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
|
||||
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
|
||||
autostart.getGatewayToken()));
|
||||
}
|
||||
|
||||
} catch (final MalformedURLException e) {
|
||||
LOGGER.error("Creation of simulated device at startup failed.", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user