Skip to content

Commit

Permalink
Wiki tweaks
Browse files Browse the repository at this point in the history
Just a few small tweaks to the `Creating Event Consumers` wiki page:
* Corrects some tiny grammitcal errors
* Fixes indentation in one of the examples
* Replaces `sth` with the more verbose `something`
  * It took me a little while to figure out what sth meant
  • Loading branch information
jutonz committed Sep 20, 2018
1 parent c770203 commit cfcad5b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Creating-Event-Consumers.md
@@ -1,8 +1,8 @@
The `event_bus` library comes with an efficient solution to internal process communication. Unlike other event bus implementations, `event_bus` doesn't deliver the event data directly to its subscribers. It delivers the identifier of the event and topic name which can be queued with minimal memory footprint. With this behavior, subscriber query the event data when they are ready to process the event.
The `event_bus` library comes with an efficient solution to internal process communication. Unlike other event bus implementations, `event_bus` doesn't deliver the event data directly to its subscribers. Rather, it delivers the identifier of the event and topic name which can be queued with minimal memory footprint. With this behavior, subscriber query the event data when they are ready to process the event.

### Simple Event Consumer Implementation

All modules that implements `process/1` function can be a consumer for `event_bus` events. Here is a working sample of a simple consumer:
Any module which implements `process/1` can be a consumer for `event_bus` events. Here is a working example of a simple consumer:

```elixir
defmodule MyFirstConsumer do
Expand All @@ -14,7 +14,7 @@ defmodule MyFirstConsumer do
# Fetch event
event = EventBus.fetch(event_shadow)

# Do sth with the event
# Do something with the event
Logger.info("I am handling the event with a Simple module #{__MODULE__}")
Logger.info(fn -> inspect(event) end)

Expand All @@ -35,14 +35,14 @@ defmodule MySecondConsumer do
require Logger

def process({_topic, _id} = event_shadow) do
spawn(fn -> do_sth(event_shadow) end)
spawn(fn -> do_something(event_shadow) end)
end

def do_sth(event_shadow) do
def do_something(event_shadow) do
# Fetch event
event = EventBus.fetch(event_shadow)

# Do sth with the event
# Do something with the event
# Or just log for the sample
Logger.info("I am handling the event with Spawn")
Logger.info(fn -> inspect(event) end)
Expand Down Expand Up @@ -82,7 +82,7 @@ defmodule MyThirdConsumer do
# Fetch event
event = EventBus.fetch_event({topic, id})

# Do sth with the event
# Do something with the event
# Or just log for the sample
Logger.info("I am handling the event with GenServer #{__MODULE__}")
Logger.info(fn -> inspect(event) end)
Expand All @@ -96,7 +96,7 @@ end

### Simple Asynchronous Event Consumer Implementation with GenStage

GenStage and EventBus are the great couples to handle backpressure and also consuming large queues. Here is a simple GenStage consumer for `event_bus` events:
GenStage and EventBus are the great couples for handling backpressure and consuming large queues. Here is a simple GenStage consumer for `event_bus` events:

```elixir
defmodule MyFourthConsumer do
Expand Down Expand Up @@ -168,7 +168,7 @@ defmodule MyFourthConsumer do
# Fetch event
event = EventBus.fetch_event({topic, id})

# Do sth with the event
# Do something with the event
# Or just log for the sample
Logger.info("I am handling the event with GenStage #{__MODULE__}")
Logger.info(fn -> inspect(event) end)
Expand Down Expand Up @@ -217,18 +217,18 @@ defmodule MyFifthConsumer do

@doc false
def handle_cast({:perform, {topic, id}}, state) do
# Fetch event
event = EventBus.fetch_event({topic, id})
# Fetch event
event = EventBus.fetch_event({topic, id})

# Do sth with the event
# Or just log for the sample
Logger.info("I am handling the event with :poolboy #{__MODULE__}")
Logger.info(fn -> inspect(event) end)
# Do sth with the event
# Or just log for the sample
Logger.info("I am handling the event with :poolboy #{__MODULE__}")
Logger.info(fn -> inspect(event) end)

EventBus.mark_as_completed({MyFifthConsumer, topic, id})
EventBus.mark_as_completed({MyFifthConsumer, topic, id})
{:noreply, state}
end
end
```

Congratulations!!! You implemented five different consumers for `event_bus` events. Now, time to [subscribe these consumers to the registered topics](https://github.com/otobus/event_bus/wiki/Subscribing-Consumers-to-Topic(s)).
Congratulations!!! You implemented five different consumers for `event_bus` events. Now, time to [subscribe these consumers to the registered topics](https://github.com/otobus/event_bus/wiki/Subscribing-Consumers-to-Topic(s)).

0 comments on commit cfcad5b

Please sign in to comment.