Commit dfb118f5 authored by 吴文龙's avatar 吴文龙

fix

parent ef630c32
global
daemon
maxconn 256
defaults
mode tcp
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend mqtt_frontend
bind *:1883
mode tcp
default_backend mqtt_backend
backend mqtt_backend
mode tcp
balance roundrobin
option tcp-check
tcp-check send-binary 303c01000004000000000000
tcp-check expect binary 200201000004000000000000
tcp-check send-binary 100000016d7174742f04020000000c6d7174742d737461747573
tcp-check expect binary 20020001000c6d7174742d737461747573
server mqtt_server1 192.168.1.101:1883 check inter 5s rise 2 fall 3
server mqtt_server2 192.168.1.102:1883 check inter 5s rise 2 fall 3
server mqtt_server3 192.168.1.103:1883 check inter 5s rise 2 fall 3
lua-load /etc/haproxy/mqtt_health_check.lua
core.register_action("mqtt_health_check", {"tcp-req"}, function(txn)
txn:set_var(txn.TXN_CHECK_STATUS, "L7OK")
txn:set_var(txn.TXN_CHECK_CODE, "200")
txn:set_var(txn.TXN_CHECK_PAYLOAD, "")
if txn.f:has_subscribers() then
local ok, err = txn.f:publish("mqtt_health_check", "PINGREQ")
if not ok then
txn:set_var(txn.TXN_CHECK_STATUS, "L7FAIL")
txn:set_var(txn.TXN_CHECK_CODE, "503")
end
end
end)
core.register_subscriber("mqtt_health_check", function(applet)
applet:set_status(200)
applet:add_header("Content-Type", "text/plain")
applet:start_response()
applet:send("PONG\n")
end)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment