项目作者: peburrows

项目描述 :
Google Pub/Sub client for Elixir
高级语言: Elixir
项目地址: git://github.com/peburrows/kane.git
创建时间: 2016-01-22T05:04:37Z
项目社区:https://github.com/peburrows/kane

开源协议:

下载


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:
  1. def deps do
  2. [{:kane, "~> 0.9.0"}]
  3. end
  1. Configure Goth (Kane’s underlying token storage and retrieval library) with your Google JSON credentials.

Usage

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

  1. {:ok, token} = Goth.fetch(MyApp.Goth)
  2. kane = %Kane{
  3. project_id: my_app_gcp_credentials["project_id"],
  4. token: token
  5. }
  6. subscription = %Kane.Subscription{
  7. name: "my-sub",
  8. topic: %Kane.Topic{
  9. name: "my-topic"
  10. }
  11. }
  12. {:ok, messages} = Kane.Subscription.pull(kane, subscription)
  13. Enum.each messages, fn(mess)->
  14. process_message(mess)
  15. end
  16. # acknowledge message receipt in bulk
  17. Kane.Subscription.ack(kane, subscription, messages)

Send message via pre-existing subscription:

  1. topic = %Kane.Topic{name: "my-topic"}
  2. message = %Kane.Message{data: %{"hello": "world"}, attributes: %{"random" => "attr"}}
  3. result = Kane.Message.publish(kane, message, topic)
  4. case result do
  5. {:ok, _return} -> IO.puts("It worked!")
  6. {:error, _reason} -> IO.puts("Should we try again?")
  7. end

Hints:

For more details, see the documentation.