matehat / kane

Google Pub/Sub client for Elixir

Home Page:http://hexdocs.pm/kane

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Kane

Kane. Citizen Kane. Charles Foster Kane, to be exact, Publisher extraordinaire. Rosebud.

Kane is for publishing and subscribing to topics using Google Cloud Pub/Sub.

Installation

  1. Add Kane to your list of dependencies in mix.exs:
def deps do
  [{:kane, "~> 0.7.0"}]
end
  1. Configure Goth (Kane's underlying token storage and retrieval library) with your Google JSON credentials:
config :goth,
  json: "path/to/google/json/creds.json" |> File.read!
  1. Ensure Kane is started before your application:
def application do
  [applications: [:kane]]
end

Usage

Pull, process and acknowledge messages via a pre-existing subscription:

subscription = %Kane.Subscription{
                  name: "my-sub",
                  topic: %Kane.Topic{
                    name: "my-topic"
                  }
                }

{:ok, messages} = Kane.Subscription.pull(subscription)

Enum.each messages, fn(mess)->
  process_message(mess)
end

# acknowledge message receipt in bulk
Kane.Subscription.ack(subscription, messages)

Send message via pre-existing subscription:

topic   = %Kane.Topic{name: "my-topic"}
message = %Kane.Message{data: %{"hello": "world"}, attributes: %{"random" => "attr"}}

result  = Kane.Message.publish(message, topic)

case result do
  {:ok, _return}    -> IO.puts("It worked!")
  {:error, _reason} -> IO.puts("Should we try again?")
end

Hints:

For more details, see the documentation.

About

Google Pub/Sub client for Elixir

http://hexdocs.pm/kane


Languages

Language:Elixir 100.0%