Weddell is an Elixir client for Google Pub/Sub.
- Add Weddell and Goth to your list of dependencies in
mix.exs
:
def deps do
[
{:weddell, "~> 0.4"},
{:goth, "~> 0.11"},
]
end
- Configure Weddell and Goth with your GCP service account credentials:
config :weddell,
project: "gcp-project-name"
config :goth,
json: {:system, "GCP_CREDENTIALS_JSON"}
By default Weddell will start a client and connect on application start.
This can be disabled by setting :no_connect_on_start
in the application config.
Clients can then be started with Weddell.Client.start_link/3
.
Weddell.create_topic("topic-name")
Weddell.create_subscription("subscription-name", "topic-name")
# In your application code
defmodule MyApp.Consumer do
use Weddell.Consumer
def handle_messages(messages) do
%{true => processed_messages, false => failed_messages} =
Enum.group_by(messages, &process_message/1)
# Delay failed messages for at least 60 seconds
delay_messages =
Enum.map(failed_messages, fn msg -> {msg, 60} end)
{:ok, ack: processed_messages, delay: delay_messages}
end
def process_message(message) do
...
end
end
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec
children = [
{MyApp.Consumer, "subscription-name"}
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
"data"
|> Weddell.publish("topic-name")
%{foo: "bar"}
|> Poison.encode!()
|> Weddell.publish("topic-name")
{"data", %{attr1: "value1"}}
|> Weddell.publish("topic-name")
%{attr1: "value1"}
|> Weddell.publish("topic-name")
["message1", "message2", "message3"]
|> Weddell.publish("topic-name")
[{"message1", %{attr1: "value1"}},
{"message2", %{attr2: "value2"}},
{"message3", %{attr3: "value3"}}]
|> Weddell.publish("topic-name")
- Integration tests
- Update topics
- Update subscriptions
- Modify ack deadline (non-streaming)
- GRPC stream error handling
- Snapshots?
Weddell uses Pub/Sub's GRPC API which is still in beta. It also makes use of streaming APIs that are considered experimental. If the beta/experimental status of Weddell worries you Kane may be a better choice. It uses the more mature Pub/Sub REST API.