A Quarkus extension allowing use of Multicast DNS or mDNS to expose service advertisement as well as discover other services on your network. It is based on the JmDNS libary.
mDNS is sometimes also called ZeroConf/Bonjour/Avahi/Rendezvous and can work in conjunction with DNS Service Discovery (DNS-SD), a companion zero-configuration networking technique specified separately in RFC 6763.
Note
Quarkus mDNS is an ideal companion if you are writing an IoT (Internet of Things) application as many IoT devices use mDNS for service discovery and advertising.
Read the full mDNS documentation.
Create a new mdns project (with a base mdns starter code):
- With code.quarkus.io
- With the Quarkus CLI:
quarkus create app mdns-app -x=io.quarkiverse.mdns:quarkus-mdnsOr add to you pom.xml directly:
<dependency>
<groupId>io.quarkiverse.mdns</groupId>
<artifactId>quarkus-mdns</artifactId>
<version>{project-version}</version>
</dependency>mDNS by default will advertise your Quarkus server for HTTP discovery.
quarkus.http.host=0.0.0.0
quarkus.http.port=8081
quarkus.application.name=integrationWill expose your server on mDNS as http://integration.local:8081 as an HTTP service type _http._tcp.local..
Important
quarkus.http.host must be set to 0.0.0.0 for the local URL http://integration.local:8081 to work properly. In dev/test mode this defaults to localhost which means the mDNS URL will not work.
Or you can inject it manually and expose any service you like. For example, this would expose it as supporting Apple TouchRemote.
@Inject
JmDNS jmdns;
public void advertise() {
Map<String, String> props = new HashMap<>();
props.put("DvNm", "Quarkus Client");
props.put("RemV", "10000");
props.put("DvTy", "iPod");
props.put("RemN", "Remote");
props.put("txtvers", "1");
ServiceInfo serviceInfo = ServiceInfo.create("_touch-remote._tcp", hostName, 1024, 0, 0, props);
jmdns.registerService(serviceInfo);
}You may also use mDNS to discover other services on your network by using the injectable component. For example if you wanted to discover all the Apple Airport devices on your local network.
@Inject
JmDNS jmdns;
public void listServices() {
ServiceInfo[] infos = jmdns.list("_airport._tcp.local.");
for (ServiceInfo info : infos) {
System.out.println(info);
}
}| mDNS version | Quarkus version |
|---|---|
| 1.4.x | 3.27.1+ |
| 4.x | 4.0.0.Beta1+ |
4.x targets Quarkus 4 and requires JDK 21. If you are still on Quarkus 3, stay on 1.4.x, which is maintained from the 1.x branch.
- Contribution is the best way to support and get involved in community!
- Please, consult our Code of Conduct policies for interacting in our community.
- Contributions to
quarkus-mdnsPlease check our CONTRIBUTING.md
Thanks goes to these wonderful people (emoji key):
Melloware 🚧 |
Fred Bricon 🤔 💻 |
Max Rydahl Andersen 🤔 |
Holly Cummins 📖 |
Kai Kreuzer 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
