exns v0.3.3-beta Exns

Communicate with your python nanoservices from Elixir.

Installation

Add exns as a dependency to your project’s mix.exs

def deps do
  [{:exns, "~> 0.3.3"}]
end

Configuration

In your application’s config.exs describe your nanoservices like so:

config :exns, nanoservices: [

[name: :math_service,
 address: "ipc:///tmp/math-service.sock",
 timeout: 5000,
 workers: 10],

[name: :string_service,
 address: "ipc:///tmp/string-service.sock",
 timeout: 5000,
 workers: 10,
 encoder: "msgpack"]]

Communication with a nanoservice

Say you have the following nanoservice in Python:

from nanoservice import Responder

def add(x, y):
    return x+y

s = Responder('ipc:///tmp/math_service.sock')
s.register('add', add)
s.start()

To call your nanoservice from Elixir you’d use:

case Exns.call("math_service", "add", [1,2]) do
    {:ok, result} -> IO.puts "Result is: #{result}"
    {:error, msg} -> IO.puts "Error #{msg}"
end

OR

result = Exns.call!("math_service", "add", [1,2])

Summary

Functions

Call a method on a remote service

Call a method on a remote service, but raise exception if remote endpoint returns an error

Callback implementation for c::application.start/2

Functions

call(service, method, args \\ [])

Call a method on a remote service

call!(service, method, args \\ [])

Call a method on a remote service, but raise exception if remote endpoint returns an error

start(type, args)

Callback implementation for c::application.start/2.