Skip to content

botsunit/wok

Repository files navigation

Microservice framework for Erlang

Copyright (c) 2015 Grégoire Lejeune, 2015 G-Corp

Version: 0.0.1

Authors: Gregoire Lejeune ([email protected]), Gregoire Lejeune ([email protected]).

Create a microservice with wok

Erlang

  1. Add wok in your dependencies :

{wok, ".*", {git, "[email protected]:msaas/wok.git", {branch, "master"}}}

  1. Create your services and routes.

  2. Reference your services and routes in the config file (see Configuration)

  3. Start your service :


application:ensure_all_started(wok).

Elixir

Ruby

Python

Javascript

Configuration

Messages configuration

  • handler :: atom() : handler used to create and parse messages. See wok_message_handler for more informations.

  • services :: list() : Services configuration

  • consumer_group :: binary() | random | {random, [{prefix, term()}]} : Name of the Kafka' consumer group

  • local_queue_name :: binary() : Name of the pipette' queue

  • local_consumer_group :: binary() | random | {random, [{prefix, term()}]} : Name of the pipette' consumer group

  • max_services_fork :: integer() : Maximum number of messages in parallel

  • topics :: list() : Topics configuration

  • from_beginning :: true | false : Start consuming from beginning (default true)

REST configuration

  • port :: integer() : Port to use for the REST API (default: 8080)

  • ip :: list() : IP to use for the REST API (default: 0.0.0.0)

  • max_conn :: integer() : Max number of connexions (default: 100)

  • routes :: list() : Routes configuration

Services configuration


{<<"my_service">>, {my_service_module, my_service_function}}

Services configuration


{<<"topic">>, [{fetch_frequency, 5000}, {max_bytes, 10485760}]}

Routes configuration


{'GET', "/path", {route_module, route_function}}

Dependencies

Call tree

Start Kafka

Update docker-compose.yml and change KAFKA_ADVERTISED_HOST_NAME to the IP of your docker0 interface.


docker-compose up -d
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic test
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic repl
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic service
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic public
...
docker-compose stop

Licence

Wok is available for use under the following license, commonly known as the 3-clause (or "modified") BSD license:

Copyright (c) 2015, G-Corp
Copyright (c) 2015, 2016, 2017 BotsUnit

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Modules

wok
wok_message
wok_message_handler
wok_producer