diff --git a/compose/mqtt-task-common.yml b/compose/mqtt-task-common.yml index 194254f3..9d59002b 100644 --- a/compose/mqtt-task-common.yml +++ b/compose/mqtt-task-common.yml @@ -2,7 +2,7 @@ services: mqtt-task: build: ../ env_file: ../.env - command: bundle exec rake mqtt:sub + command: ./mqtt_subscriber.sh restart: always volumes: - "../log:/app/log" diff --git a/compose/mqtt-task.yml b/compose/mqtt-task.yml index 03c982d0..ab83109b 100644 --- a/compose/mqtt-task.yml +++ b/compose/mqtt-task.yml @@ -18,7 +18,7 @@ services: file: mqtt-task-common.yml service: mqtt-task environment: - MQTT_CLIENT_ID: "smartcitizen-api-staging-secondary-${HOSTNAME}" + MQTT_CLIENT_ID: "smartcitizen-api-staging-secondary" MQTT_CLEAN_SESSION: true deploy: mode: replicated diff --git a/lib/tasks/mqtt_subscriber.rake b/lib/tasks/mqtt_subscriber.rake index 56529a49..83460187 100644 --- a/lib/tasks/mqtt_subscriber.rake +++ b/lib/tasks/mqtt_subscriber.rake @@ -10,8 +10,14 @@ namespace :mqtt do mqtt_port = ENV.has_key?('MQTT_PORT') ? ENV['MQTT_PORT'] : 1883 mqtt_ssl = ENV.has_key?('MQTT_SSL') ? ENV['MQTT_SSL'] : false mqtt_shared_subscription_group = ENV.fetch("MQTT_SHARED_SUBSCRIPTION_GROUP", nil) + mqtt_topics_string = ENV.fetch('MQTT_TOPICS', '') mqtt_topics = mqtt_topics_string.include?(",") ? mqtt_topics_string.split(",") : [ mqtt_topics_string ] + + if mqtt_shared_subscription_group && mqtt_clean_session + mqtt_client_id += "-#{ENV.fetch("HOSTNAME")}" + end + mqtt_log = Logger.new("log/mqtt-#{mqtt_client_id}.log", 5, 100.megabytes) mqtt_log.info('MQTT TASK STARTING') mqtt_log.info("clean_session: #{mqtt_clean_session}") diff --git a/mqtt_subscriber.sh b/mqtt_subscriber.sh new file mode 100755 index 00000000..481d728e --- /dev/null +++ b/mqtt_subscriber.sh @@ -0,0 +1,2 @@ +#!/bin/bash +bundle exec rake mqtt:sub