Skip to content

Commit

Permalink
[456899] Broker: Add bridge_attempt_unsubscribe option.
Browse files Browse the repository at this point in the history
The bridge_attempt_unsubscribe option has been added, to allow the sending
of UNSUBSCRIBE requests to be disabled for topics with "out" direction.

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=456899
  • Loading branch information
ralight committed Jan 7, 2015
1 parent 778bd4c commit 1757948
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Expand Up @@ -48,6 +48,9 @@ Broker:
and has been fixed so the broker no longer asks.
- When using syslog logging on non-Windows OSs, it is now possible to specify
the logging facility to one of local0-7 instead of the default "daemon".
- The bridge_attempt_unsubscribe option has been added, to allow the sending
of UNSUBSCRIBE requests to be disabled for topics with "out" direction.
Closes bug #456899.

Clients:
- Both clients can now load default configuration options from a file.
Expand Down
15 changes: 15 additions & 0 deletions man/mosquitto.conf.5.xml
Expand Up @@ -1220,6 +1220,21 @@ topic clients/total in 0 test/mosquitto/org $SYS/broker/
<para>The following options are available for all bridges to
configure SSL/TLS support.</para>
<variablelist>
<varlistentry>
<term><option>bridge_attempt_unsubscribe</option> [ true | false ]</term>
<listitem>
<para>If a bridge has topics that have "out" direction,
the default behaviour is to send an unsubscribe
request to the remote broker on that topic. This
means that changing a topic direction from "in" to
"out" will not keep receiving incoming messages.
Sending these unsubscribe requests is not always
desirable, setting
<option>bridge_attempt_unsubscribe</option> to
<replaceable>false</replaceable> will disable
sending the unsubscribe request.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>bridge_cafile</option> <replaceable>file path</replaceable></term>
<listitem>
Expand Down
8 changes: 8 additions & 0 deletions mosquitto.conf
Expand Up @@ -631,6 +631,14 @@
#address <host>[:<port>] [<host>[:<port>]]
#topic <topic> [[[out | in | both] qos-level] local-prefix remote-prefix]

# If a bridge has topics that have "out" direction, the default behaviour is to
# send an unsubscribe request to the remote broker on that topic. This means
# that changing a topic direction from "in" to "out" will not keep receiving
# incoming messages. Sending these unsubscribe requests is not always
# desirable, setting bridge_attempt_unsubscribe to false will disable sending
# the unsubscribe request.
#bridge_attempt_unsubscribe true

# If the bridge has more than one address given in the address/addresses
# configuration, the round_robin option defines the behaviour of the bridge on
# a failure of the bridge connection. If round_robin is false, the default
Expand Down
12 changes: 12 additions & 0 deletions src/conf.c
Expand Up @@ -681,6 +681,17 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(_conf_attempt_resolve(config->default_listener.host, "bind_address", MOSQ_LOG_ERR, "Error")){
return MOSQ_ERR_INVAL;
}
}else if(!strcmp(token, "bridge_attempt_unsubscribe")){
#ifdef WITH_BRIDGE
if(reload) continue; // FIXME
if(!cur_bridge){
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
if(_conf_parse_bool(&token, "bridge_attempt_unsubscribe", &cur_bridge->attempt_unsubscribe, saveptr)) return MOSQ_ERR_INVAL;
#else
_mosquitto_log_printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_cafile")){
#if defined(WITH_BRIDGE) && defined(WITH_TLS)
if(reload) continue; // FIXME
Expand Down Expand Up @@ -1007,6 +1018,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
cur_bridge->restart_timeout = 30;
cur_bridge->threshold = 10;
cur_bridge->try_private = true;
cur_bridge->attempt_unsubscribe = true;
}else{
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Empty connection value in configuration.");
return MOSQ_ERR_INVAL;
Expand Down
1 change: 1 addition & 0 deletions src/mosquitto_broker.h
Expand Up @@ -300,6 +300,7 @@ struct _mqtt3_bridge{
int restart_timeout;
int threshold;
bool lazy_reconnect;
bool attempt_unsubscribe;
#ifdef WITH_TLS
char *tls_cafile;
char *tls_capath;
Expand Down
12 changes: 7 additions & 5 deletions src/read_handle_client.c
Expand Up @@ -74,11 +74,13 @@ int mqtt3_handle_connack(struct mosquitto_db *db, struct mosquitto *context)
return 1;
}
}else{
if(_mosquitto_send_unsubscribe(context, NULL, context->bridge->topics[i].remote_topic)){
/* direction = inwards only. This means we should not be subscribed
* to the topic. It is possible that we used to be subscribed to
* this topic so unsubscribe. */
return 1;
if(context->bridge->attempt_unsubscribe){
if(_mosquitto_send_unsubscribe(context, NULL, context->bridge->topics[i].remote_topic)){
/* direction = inwards only. This means we should not be subscribed
* to the topic. It is possible that we used to be subscribed to
* this topic so unsubscribe. */
return 1;
}
}
}
}
Expand Down

0 comments on commit 1757948

Please sign in to comment.