-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
686bafb
commit 3b2a8a3
Showing
8 changed files
with
854 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
description: >- | ||
Volta is a handy library for quickly building asynchronys microservices using | ||
RabbitMQ in Golang. | ||
--- | ||
|
||
# ❤ Welcome | ||
|
||
### Installation | ||
|
||
```bash | ||
go get github.com/volta-dev/volta | ||
``` | ||
|
||
### Hello, World! | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/volta-dev/volta" | ||
) | ||
|
||
func main() { | ||
app := volta.New(volta.Config{ | ||
RabbitMQ: "amqp://guest:guest@localhost:5672/", | ||
}) | ||
|
||
app.AddExchanges(volta.Exchange{Name: "test", Type: "topic"}) | ||
app.AddQueue(volta.Queue{Name: "test", RoutingKey: "test", Exchange: "test"}) | ||
|
||
app.AddConsumer("test", Handler) | ||
|
||
app.Listen() | ||
} | ||
|
||
func Handler(ctx *volta.Ctx) error { | ||
return ctx.Reply([]body("Hello, World!")) | ||
} | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Table of contents | ||
|
||
* [❤ Welcome](README.md) | ||
|
||
## API | ||
|
||
* [📦 Volta](api/volta.md) | ||
* [⚙ App](api/app.md) | ||
* [🧠 Ctx](api/ctx.md) | ||
* [🧬 Middleware](api/middleware/README.md) | ||
* [Recover](api/middleware/recover.md) | ||
|
||
## Guide | ||
|
||
* [⚡ Make Volta Faster](guide/make-volta-faster.md) |
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 |
---|---|---|
@@ -0,0 +1,242 @@ | ||
# ⚙ App | ||
|
||
## AddExchanges | ||
|
||
Function to add exchanges to the app. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) AddExchanges(exchange ...Exchange) | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
app.AddExchanges( | ||
volta.Exchange{ | ||
Name: "testing", // Name of the exchange. | ||
Type: "fanout", // Type of the exchange. | ||
Durable: false, // Durability of the exchange when the server restarts. | ||
AutoDelete: false, // Auto delete the exchange when there are no more queues bound to it. | ||
Internal: false, // If true, messages cannot be published directly to the exchange. | ||
NoWait: false, // If true, declare without waiting for a confirmation from the server. | ||
}, | ||
) | ||
``` | ||
{% endcode %} | ||
|
||
## AddQueue | ||
|
||
Function to add queues to the app. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) AddQueue(queue ...Queue) | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
app.AddQueue( | ||
volta.Queue{ | ||
Name: "testing.12", // Name of the queue. | ||
RoutingKey: "testing.12", // Routing key of the queue. | ||
Exchange: "testing", // Exchange to bind the queue to. | ||
Durable: false, // Durability of the queue when the server restarts. | ||
AutoDelete: false, // Auto delete the queue when there are no more consumers subscribed to it. | ||
Exclusive: false, // If true, only one consumer can consume from the queue. | ||
NoWait: false, // If true, declare without waiting for a confirmation from the server. | ||
}, | ||
) | ||
``` | ||
{% endcode %} | ||
|
||
## AddConsumer | ||
|
||
Function to add consumers to the app. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) AddConsumer(consumer ...Handler) | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
app.AddConsumer("testing", func(ctx *volta.Ctx) error { | ||
fmt.Println(ctx.Body()) | ||
return ctx.Ack(false) | ||
}) | ||
``` | ||
{% endcode %} | ||
|
||
## PurgeExchange | ||
|
||
Function to purge exchanges from the app. | ||
|
||
If force is true, the exchange will be deleted even if it is in use | ||
|
||
If force is false, the exchange will be deleted only if it is not in use | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) PurgeExchange(name string, force bool) error | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
if err := app.PurgeExchange("testing", false); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
## PurgeQueue | ||
|
||
Function to purge queues from the app. | ||
|
||
If force is true, the queue will be deleted even if it is in use | ||
|
||
If force is false, the queue will be deleted only if it is not in use | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) PurgeQueue(name string, force bool) error | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
if err := app.PurgeQueue("testing.12", false); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
## Publish | ||
|
||
Function to publish a message to an exchange without response awaiting. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) Publish(name, exchange string, body []byte) error | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
if err := app.Publish("testing.12", "testing", []byte("Hello, World!")); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
## PublishJSON | ||
|
||
Function to publish a message to an exchange without response awaiting. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) PublishJSON(name, exchange string, body interface{}) error | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
if err := app.PublishJSON("testing.12", "testing", volta.Map{"name": "World"}); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
## Request | ||
|
||
Function to publish a message to an exchange with response awaiting. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) Request(routingKey string, body []byte) ([]byte, error) | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
if response, err := app.Request("testing.12", []byte("Hello, World!")); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
## RequestJSON | ||
|
||
Function to publish a message to an exchange with response awaiting. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) RequestJSON(name string, body interface{}, response interface{}) error | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
var response volta.Map | ||
if response, err := app.RequestJSON( | ||
"testing.12", | ||
volta.Map{"name": "World"}, | ||
&response, | ||
); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
## Use | ||
|
||
Function to add global middlewares to the app. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) Use(middleware ...Handler) | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
app.Use(func(ctx *volta.Ctx) error { | ||
fmt.Println("Before") | ||
return ctx.Next() | ||
}) | ||
app.AddConsumer("testing", func(ctx *volta.Ctx) error { | ||
fmt.Println("Handler") | ||
return ctx.Ack(false) | ||
}) | ||
if err := app.Listen(); err != nil { | ||
... | ||
} | ||
// Output: | ||
// Before | ||
// Handler | ||
``` | ||
{% endcode %} | ||
|
||
## Listen | ||
|
||
Function to initialize all the exchanges and queues and start listening for messages. | ||
|
||
{% code title="Signature" lineNumbers="true" %} | ||
```go | ||
func (m *App) Listen() error | ||
``` | ||
{% endcode %} | ||
|
||
{% code title="Example" lineNumbers="true" %} | ||
```go | ||
if err := app.Listen(); err != nil { | ||
... | ||
} | ||
``` | ||
{% endcode %} |
Oops, something went wrong.