-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,79 @@ | ||
# OffBroadway.EMQTT | ||
|
||
## Building | ||
 | ||
[](https://hexdocs.pm/off_broadway_emqtt/readme.html) | ||
|
||
By default, `:emqtt` compiles the `Quic` library. It is possible to build without by setting the environment variable | ||
`BUILD_WITHOUT_QUIC=1`. | ||
An MQTT connector based on [emqtt](https://github.com/emqx/emqtt) for [Broadway](https://github.com/dashbitco/broadway). | ||
|
||
``` shell | ||
BUILD_WITHOUT_QUIC=1 mix compile | ||
``` | ||
## Usage | ||
|
||
``` elixir | ||
defmodule MyBroadway do | ||
use Broadway | ||
alias Broadway.Message | ||
def start_link(_opts) do | ||
Broadway.start_link(__MODULE__, | ||
name: __MODULE__, | ||
producer: [ | ||
module: {OffBroadway.EMQTT.Producer, | ||
buffer_size: 10_000, | ||
buffer_overflow_strategy: :drop_head, | ||
topics: [ | ||
{"test/topic1", :exactly_once}, | ||
{"test/topic2", :at_most_once}, | ||
{"test/topic3", :at_least_once}, | ||
], | ||
config: [ | ||
host: "test.mosquitto.org", | ||
port: 1884, | ||
username: "rw", | ||
password: "readwrite" | ||
] | ||
}, | ||
concurrency: 5 | ||
], | ||
processors: [ | ||
default: [concurrency: 10] | ||
], | ||
batchers: [ | ||
default: [ | ||
batch_size: 200, | ||
concurrency: 5 | ||
] | ||
] | ||
) | ||
end | ||
|
||
@impl true | ||
def handle_message(_, %Message{} = message, _) do | ||
IO.inspect(message, label: "Handled message from producer") | ||
end | ||
|
||
def handle_batch(_, messages, _, _) do | ||
IO.inspect("Received a batch of #{length(messages)} messages", label: "Handled batch from producer") | ||
messages | ||
end | ||
end | ||
``` | ||
|
||
**TODO: Add description** | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
This package is [available in Hex](https://hex.pm/packages/off_broadway_emqtt), and can be installed | ||
by adding `off_broadway_emqtt` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
{:off_broadway_emqtt, "~> 0.1.0", system_env: [{"BUILD_WITHOUT_QUIC", "1"}]} | ||
{:off_broadway_emqtt, "~> 0.1.0"} | ||
] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at <https://hexdocs.pm/off_broadway_emqtt>. | ||
By default, `:emqtt` compiles the `Quic` library. It is possible to build without by setting the environment variable | ||
`BUILD_WITHOUT_QUIC=1`. | ||
|
||
``` shell | ||
BUILD_WITHOUT_QUIC=1 mix deps.compile | ||
``` | ||
|