Git Product home page Git Product logo

akka_akka-dns's Introduction

Build status Download

akka-dns

A fully asynchronous DNS resolver for Akka.

Usage

Add a dependency to your build.sbt:

libraryDependencies += "ru.smslv.akka" %% "akka-dns" % "2.4.2"

Configure akka-dns in application.conf. If you can rely on /etc/resolv.conf being available (which should be the case for most flavors of Unix):

akka.io.dns {
  resolver = async-dns
  async-dns.resolv-conf = on
}

Alternatively you can also configure the nameservers explicitly:

akka.io.dns {
  resolver = async-dns
  async-dns {
    nameservers = ["8.8.8.8", "8.8.4.4"]
  }
}

Note that you can declare both resolv-conf and nameservers in which case the latter will be used in the case where /etc/resolv.conf cannot be found/parsed.

Advanced configuration

There are some other tunables, too, here are their defaults:

akka.io.dns {
  async-dns {
    min-positive-ttl = 0s
    max-positive-ttl = 1d
    negative-ttl = 10s

    resolve-ipv4 = true
    resolve-ipv6 = true
    resolve-srv  = false

    # How often to sweep out expired cache entries.
    # Note that this interval has nothing to do with TTLs
    cache-cleanup-interval = 120s
  }
}

To actually resolve addresses using akka-dns:

// send dns request
IO(Dns) ! Dns.Resolve("a-single.test.smslv.ru")

// wait for Dns.Resolved
def receive = {
  case Dns.Resolved(name, ipv4, ipv6) =>
    ...
}

// just to try it out synchronously
val answer = Await.result(IO(Dns) ? Dns.Resolve("a-single.test.smslv.ru"), duration).asInstanceOf[Dns.Resolved]

You can also resolve SRV records if you enable a config option:

akka.io.dns.async-dns.resolve-srv = true

The only difference with ordinary usage is that you send a regular Dns.Resovle request with a domain name that starts with _ and wait for a SrvResolved message instead of a Dns.Resolved one, like this:

// send dns request
IO(Dns) ! Dns.Resolve("_http._tcp.smslv.ru")

// wait for SrvResolved
def receive = {
  case SrvResolved(name, records: immutable.Seq[SRVRecord]) =>
    ...
}

// just to try it out synchronously
val answer = Await.result(IO(Dns) ? Dns.Resolve("_http._tcp.smslv.ru"), duration).asInstanceOf[SrvResolved]

akka_akka-dns's People

Contributors

ilya-epifanov avatar huntc avatar

Watchers

James Cloos avatar Andrei Pozolotin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.