This commit is contained in:
34
agent/docker/docker-compose-test.yaml
Normal file
34
agent/docker/docker-compose-test.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
version: "3.3"
|
||||
#name: "road_vision"
|
||||
services:
|
||||
mqtt:
|
||||
image: eclipse-mosquitto
|
||||
container_name: mqtt
|
||||
volumes:
|
||||
- ./mosquitto:/mosquitto
|
||||
- ./mosquitto/data:/mosquitto/data
|
||||
- ./mosquitto/log:/mosquitto/log
|
||||
ports:
|
||||
- 1883:1883
|
||||
- 9001:9001
|
||||
networks:
|
||||
mqtt_network:
|
||||
|
||||
|
||||
fake_agent:
|
||||
container_name: agent
|
||||
build: ../
|
||||
depends_on:
|
||||
- mqtt
|
||||
environment:
|
||||
MQTT_BROKER_HOST: "mqtt"
|
||||
MQTT_BROKER_PORT: 1883
|
||||
MQTT_TOPIC: "agent_data_topic"
|
||||
DELAY: 0.1
|
||||
MAX_SENDS: 30
|
||||
networks:
|
||||
mqtt_network:
|
||||
|
||||
|
||||
networks:
|
||||
mqtt_network:
|
||||
@@ -1,4 +1,5 @@
|
||||
name: "road_vision"
|
||||
version: "3.3"
|
||||
#name: "road_vision"
|
||||
services:
|
||||
mqtt:
|
||||
image: eclipse-mosquitto
|
||||
|
||||
@@ -16,3 +16,6 @@ MQTT_TOPIC = os.environ.get("MQTT_TOPIC") or "agent"
|
||||
|
||||
# Delay for sending data to mqtt in seconds
|
||||
DELAY = try_parse(float, os.environ.get("DELAY")) or 1
|
||||
|
||||
# Testing switches for CI/CD
|
||||
MAX_SENDS = try_parse(int, os.environ.get("MAX_SENDS"))
|
||||
|
||||
@@ -24,9 +24,13 @@ def connect_mqtt(broker, port):
|
||||
return client
|
||||
|
||||
|
||||
def publish(client, topic, datasource, delay):
|
||||
def publish(client, topic, datasource, delay, max_sends = None):
|
||||
datasource.startReading()
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
i += 1
|
||||
|
||||
time.sleep(delay)
|
||||
data = datasource.read()
|
||||
msg = AggregatedDataSchema().dumps(data)
|
||||
@@ -39,6 +43,10 @@ def publish(client, topic, datasource, delay):
|
||||
else:
|
||||
print(f"Failed to send message to topic {topic}")
|
||||
|
||||
if max_sends and i >= max_sends:
|
||||
# display test success
|
||||
exit(0)
|
||||
|
||||
|
||||
def run():
|
||||
# Prepare mqtt client
|
||||
@@ -46,7 +54,7 @@ def run():
|
||||
# Prepare datasource
|
||||
datasource = FileDatasource("data/data.csv", "data/gps_data.csv")
|
||||
# Infinity publish data
|
||||
publish(client, config.MQTT_TOPIC, datasource, config.DELAY)
|
||||
publish(client, config.MQTT_TOPIC, datasource, config.DELAY, getattr(config, "MAX_SENDS", None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user