I have deployed ActiveMQ brokers pod with statefulset object. The configuration of activeMQ is the following:
<networkConnectors>
<networkConnector uri="multicast://default" dynamicOnly="true" networkTTL="3" duplex="true" prefetchSize="1" decreaseNetworkConsumerPriority="false" />
</networkConnectors>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600&wireFormat.allowNonSaslConnections=true" discoveryUri="multicast://default"/>
</transportConnectors>
For testing there are just 2 pods, activemq-0 and activemq-1. Analysing packets with Wireshark show that multicast discovery is working. But brokers don't forward message between them. Here is the log for activemq-0 :
2020-07-14 09:17:32,943 | INFO | Establishing network connection from vm://localhost to amqp://activemq-1.activemqsvc.default.svc.cluster.local:5672 | org.apache.activemq.network.DiscoveryNetworkConnector | Notifier-MulticastDiscoveryAgent-listener:DiscoveryNetworkConnector:NC:BrokerService[localhost]
2020-07-14 09:18:02,463 | WARN | Transport Connection to: tcp://172.17.0.7:37174 failed: org.apache.activemq.transport.InactivityIOException: Channel was inactive for too (>30000) long: tcp://172.17.0.7:37174 | org.apache.activemq.broker.TransportConnection.Transport | AmqpInactivityMonitor Async Task: java.util.concurrent.ThreadPoolExecutor$Worker@54f96489[State = -1, empty queue]
Not all CNI plugins support multicast.
The one CNI I know that supports it is WeaveNet so you may want to consider using it.
Other method is to use:
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
as suggested in this SO answer.