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.MalformedURLException;
|
||||||
import java.net.URL;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -32,24 +32,27 @@ public class SimulatorStartup implements ApplicationListener<ContextRefreshedEve
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SimulationProperties simulationProperties;
|
private SimulationProperties simulationProperties;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpSenderService spSenderService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DeviceSimulatorRepository repository;
|
private DeviceSimulatorRepository repository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SimulatedDeviceFactory deviceFactory;
|
private SimulatedDeviceFactory deviceFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmqpProperties amqpProperties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(final ContextRefreshedEvent event) {
|
public void onApplicationEvent(final ContextRefreshedEvent event) {
|
||||||
simulationProperties.getAutostarts().forEach(autostart -> {
|
simulationProperties.getAutostarts().forEach(autostart -> {
|
||||||
for (int i = 0; i < autostart.getAmount(); i++) {
|
for (int i = 0; i < autostart.getAmount(); i++) {
|
||||||
final String deviceId = autostart.getName() + i;
|
final String deviceId = autostart.getName() + i;
|
||||||
try {
|
try {
|
||||||
|
if (amqpProperties.isEnabled()) {
|
||||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
|
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
|
||||||
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
|
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
|
||||||
autostart.getGatewayToken()));
|
autostart.getGatewayToken()));
|
||||||
|
}
|
||||||
|
|
||||||
} catch (final MalformedURLException e) {
|
} catch (final MalformedURLException e) {
|
||||||
LOGGER.error("Creation of simulated device at startup failed.", e);
|
LOGGER.error("Creation of simulated device at startup failed.", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user