Skip to content

Commit

Permalink
Add Upgrade Guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ulissesalmeida committed Nov 16, 2022
1 parent 36a4f61 commit 105c781
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 17 deletions.
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,35 @@ def deps do
end
```

2. Configure [Goth](https://github.com/peburrows/goth) (Kane's underlying token storage and retrieval library) with your Google JSON credentials:

```elixir
config :goth,
json: "path/to/google/json/creds.json" |> File.read!
```

3. Ensure Kane is started before your application:

```elixir
def application do
[applications: [:kane]]
end
```
2. Configure [Goth](https://github.com/peburrows/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:

```elixir
{:ok, token} = Goth.fetch(MyApp.Goth)

kane = %Kane{
project_id: my_app_gcp_credentials["project_id"],
token: token
}

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

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

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

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

Send message via pre-existing subscription:
Expand All @@ -59,7 +53,7 @@ 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)
result = Kane.Message.publish(kane, message, topic)

case result do
{:ok, _return} -> IO.puts("It worked!")
Expand Down
53 changes: 53 additions & 0 deletions UPGRADE_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Upgrading from Kane 0.9

Earlier versions of Kane relied on global application environment configuration which is deprecated in favour of a more direct and explicit approach in Kane vX.X+. Kane is following the same principle changes of [Goth 1.3+](https://github.com/peburrows/goth/blob/master/UPGRADE_GUIDE.md).

Below is a step-by-step upgrade path from Goth 0.x to X.X:

Upgrade Goth to [1.3+](https://github.com/peburrows/goth/blob/master/UPGRADE_GUIDE.md). Previous versions of Kane, heavily depended on the global configuration of Goth.

So, your `mix.exs` should be looking like this:

```elixir
def deps do
[
{:goth, "~> 1.3"},
{:kane, "~> X.X"}
]
end
```

You might have a code similar to this:


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

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

Now you need explicity fetch the token and the project's id:

```elixir
defmodule MyApp do
def kane do
{:ok, token} = Goth.fetch(MyApp.Goth)
project_id = Application.fetch_env!(:my_app, :gcp_credentials)["project_id"]

%Kane{
project_id: project_id,
token: token
}
end
end

# then
{:ok, messages} = Kane.Subscription.pull(MyApp.kane(), subscription)
```

For more information on earlier versions of Kane, [see v0.9.0 documentation on hexdocs.pm](https://hexdocs.pm/kane/0.9.0).

0 comments on commit 105c781

Please sign in to comment.