I have few notes inline.
On 07/28/2011 08:33 PM, Adam Stokes wrote:
- Provided array variable for defining DNS SRV records or
a fqdn:port
- Based on FEDERATED_BROKERS array if DNS SRV record exist
format dns query answer into<fqdn>:<port>, otherwise
process as is.
- Attempt to setup bidirectional communication with all defined
brokers.
- Setup a qpid-route TIMEOUT variable so we aren't waiting longer
than 5 seconds for a broker to respond.
Signed-off-by: Adam Stokes<astokes(a)fedoraproject.org>
---
matahari-broker.init.in | 43 +++++++++++++++++++++++++++++++++++++++++++
matahari-broker.sysconf.in | 8 ++++++++
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/matahari-broker.init.in b/matahari-broker.init.in
index 13a535d..3d53ef2 100755
--- a/matahari-broker.init.in
+++ b/matahari-broker.init.in
@@ -42,6 +42,8 @@ pidfile=@localstatedir(a)/run/matahari-broker.pid
# Turn off automatic systemd redirects
SYSTEMCTL_SKIP_REDIRECT=1
+# Timeout for qpid-route in seconds
+TIMEOUT=5
# Source function library.
. @sysconfdir(a)/rc.d/init.d/functions
@@ -50,6 +52,42 @@ if [ -f @sysconfdir@/sysconfig/matahari-broker ] ; then
fi
RETVAL=0
+# Enable broker federation
+federate() {
+ for (( i=0; i<$1; i++ ));
Maybe better `for name'. `in words' is
optional. See below.
+ do
+ case ${FEDERATED_BROKERS[$i]} in
+ *_matahari-broker._tcp*)
+ RESP=`dig SRV ${FEDERATED_BROKERS[$i]} +short| awk '{print
$4":"$3}'|sed 's/\.:/:/'`
+ array[${#array[*]}]=$RESP
I think it's better to `unset
array' and `declare -a array' in start of
federate function.
+ ;;
+ *)
+ array[${#array[*]}]="${FEDERATED_BROKERS[$i]}"
+ ;;
+ esac
+ done
+
+ for (( i=0; i<${#array[@]}; i++ ));
Hmm, what about `for name in
"${array[@]}"' and use "$name" below?
+ do
+ /usr/bin/qpid-route --timeout=$TIMEOUT dynamic add ${array[$i]} \
+ localhost:$MATAHARI_PORT amq.direct&> /dev/null
I'm not
sure if we need some output here, maybe in future log it somewhere
+
+ /usr/bin/qpid-route --timeout=$TIMEOUT dynamic add localhost:$MATAHARI_PORT \
+ ${array[$i]} amq.direct&> /dev/null
+
+ /usr/bin/qpid-route --timeout=$TIMEOUT dynamic add ${array[$i]} \
+ localhost:$MATAHARI_PORT qmf.default.direct&> /dev/null
+
+ /usr/bin/qpid-route --timeout=$TIMEOUT dynamic add localhost:$MATAHARI_PORT \
+ ${array[$i]} qmf.default.direct&> /dev/null
+
+ /usr/bin/qpid-route --timeout=$TIMEOUT dynamic add ${array[$i]} \
+ localhost:$MATAHARI_PORT qmf.default.topic&> /dev/null
+
+ /usr/bin/qpid-route --timeout=$TIMEOUT dynamic add localhost:$MATAHARI_PORT \
+ ${array[$i]} qmf.default.topic&> /dev/null
+ done
+}
start() {
echo -n $"Starting Matahari broker daemon: "
@@ -64,6 +102,11 @@ start() {
[ -x /sbin/restorecon ]&& /sbin/restorecon $pidfile
runuser -s /bin/sh qpidd -c "/usr/sbin/$prog --check --pid-dir
@localstatedir@/run/matahari $QPIDD_OPTIONS> $pidfile"
fi
+ broker_len=${#FEDERATED_BROKERS[@]}
+ if [ $broker_len -gt 0 ]; then
+ federate $broker_len
What about to call `federate
"${FEDERATED_BROKERS[@]}"' and in federate
function you can use `for name' - without `in words' bash uses "$@".
+ RETVAL=0
+ fi
return $RETVAL
}
diff --git a/matahari-broker.sysconf.in b/matahari-broker.sysconf.in
index 9b1c2b5..4473610 100644
--- a/matahari-broker.sysconf.in
+++ b/matahari-broker.sysconf.in
@@ -11,3 +11,11 @@ fi
QPIDD_OPTIONS="--config @sysconfdir(a)/matahari-broker.conf --port
$MATAHARI_PORT"
+# Federated Broker configuration
+# Takes the following formats:
+#<fqdn>:<port>
+# DNS SRV record format "_matahari-broker._tcp" is REQUIRED
+# _matahari-broker._tcp.<fqdn>
+#
+# A mixture of the above is acceptable.
+# FEDERATED_BROKERS=("broker1.example.com:49000"
"_matahari-broker._tcp.example.com")