I am having two tomcat servers running same web application. Both the web applications subscribe to topic 1 in MQTT server. Whenever message is received in topic 1 both the applications receive the message. But I want only one server to process the request instead of both. The worst case I have to do condition check at both the web applications to allow one time processing. Any suggestions for this case ?
You need to use a MQTT broker that supports Shared Subscriptions1
This feature allows you to have multiple clients subscribed to the same topic and the broker will deliver them in a round-robin fashion to all the clients (e.g. first message to client 1, second to client 2, 3rd to client 1, 4th to client 2...)
1 Shared Subscriptions was a feature a number of brokers implemented at v3 but with different mechanisms so they were not always compatible, as of v5 of the MQTT spec Shared Subscriptions is an optional component the broker can support and all brokers that implement the feature should behave the same.
来源:https://stackoverflow.com/questions/54202424/mqtt-with-load-balanced-applicaiton-server