Skip to content

Commit

Permalink
- Adding documentation 💡
Browse files Browse the repository at this point in the history
  • Loading branch information
fairyhunter13 committed May 13, 2019
1 parent 159908b commit 7ab711b
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ executors:
environment:
RABBITMQ_HOST: localhost
RABBITMQ_ERLANG_COOKIE: testingwrapper
working_directory: /go/src/github.com/fairyhunter13/goamqp-wrapper
working_directory: /go/src/github.com/fairyhunter13/amqpwrapper
commands:
installrabbitmq:
description: "Installing rabbitmq client by setting up the dependencies"
Expand Down Expand Up @@ -60,7 +60,9 @@ jobs:
command: go get -v -t -d ./...
- run:
name: "Getting dependencies for coverage"
command: go get github.com/mattn/goveralls
command: |
go get github.com/mattn/goveralls
go get github.com/stretchr/testify/assert
- run:
name: "Integration testing and generate coverage"
command: go test -v -cover -race -coverprofile=coverage.out -tags=integration ./...
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# goamqp-wrapper
# Amqpwrapper
[![CircleCI](https://circleci.com/gh/fairyhunter13/amqpwrapper/tree/master.svg?style=svg)](https://circleci.com/gh/fairyhunter13/amqpwrapper/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/fairyhunter13/amqpwrapper/badge.svg?branch=master)](https://coveralls.io/github/fairyhunter13/amqpwrapper?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/fairyhunter13/amqpwrapper)](https://goreportcard.com/report/github.com/fairyhunter13/amqpwrapper)

Wrapper library for streadway/amqp in golang.

2 changes: 1 addition & 1 deletion channel.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rabbitmq
package amqpwrapper

import "github.com/streadway/amqp"

Expand Down
2 changes: 1 addition & 1 deletion channel_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build integration

package rabbitmq
package amqpwrapper

import (
"errors"
Expand Down
10 changes: 10 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Package amqpwrapper manage the connection and channel from streadway/amqp.
Amqpwrapper wraps the connection and channel from streadway/amqp.
This package manages auto reconnection and channel lifecycle.
This package ensures two connection will be initialized for each type (producers and consumers).
This has to be done because initialization of tcp connection is very costly and slowing performance greatly in production.
*/
package amqpwrapper
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rabbitmq
package amqpwrapper

import "errors"

Expand Down
62 changes: 62 additions & 0 deletions example_manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package amqpwrapper

import (
"log"

"github.com/streadway/amqp"
)

func ExampleNewManager() {
_, err := NewManager("amqp://guest:guest@localhost:5672/", amqp.Config{})
if err != nil {
log.Fatalf("Error in creating new connection manager: %s", err)
}
}

func ExampleConnectionManager_CreateChannel() {
manager, err := NewManager("amqp://guest:guest@localhost:5672/", amqp.Config{})
if err != nil {
log.Fatalf("Error in creating new connection manager: %s", err)
}
prodChan, err := manager.CreateChannel(Producer)
if err != nil {
log.Fatalf("Error in creating new channel: %s", err)
}
defer prodChan.Close()
}

func ExampleConnectionManager_GetChannel() {
manager, err := NewManager("amqp://guest:guest@localhost:5672/", amqp.Config{})
if err != nil {
log.Fatalf("Error in creating new connection manager: %s", err)
}
prodChan, err := manager.GetChannel("Already Initialized Channel", Producer)
if err != nil {
log.Fatalf("Error in getting the channel: %s", err)
}
defer prodChan.Close()
}

func ExampleConnectionManager_InitChannel() {
manager, err := NewManager("amqp://guest:guest@localhost:5672/", amqp.Config{})
if err != nil {
log.Fatalf("Error in creating new connection manager: %s", err)
}
prodChan, err := manager.CreateChannel(Producer)
if err != nil {
log.Fatalf("Error in creating new channel: %s", err)
}
initChannel := func(amqpChan *amqp.Channel) (err error) {
err = amqpChan.ExchangeDeclare("hello", "topic", true, false, false, false, nil)
return
}
args := InitArgs{
Channel: prodChan,
Key: "New Producer",
TypeChan: Consumer,
}
err = manager.InitChannel(initChannel, args)
if err != nil {
log.Fatalf("Error in initializing the channel: %s", err)
}
}
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build integration

package rabbitmq
package amqpwrapper

import (
"flag"
Expand Down
10 changes: 5 additions & 5 deletions manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rabbitmq
package amqpwrapper

import (
"sync"
Expand All @@ -9,7 +9,7 @@ import (

type (

//IConnectionManager defines the contract for the ConnectionManager.
//IConnectionManager defines the contract to manage connection in this package.
IConnectionManager interface {
GetChannel(key string, typeChan uint64) (channel *amqp.Channel, err error)
CreateChannel(typeChan uint64) (channel *amqp.Channel, err error)
Expand Down Expand Up @@ -44,8 +44,7 @@ type (
}
)

//NewManager defines the manager for producer.
//This NewManager need to be tested with integration test.
//NewManager creates connection manager to be used to manage the lifecycle of connections.
func NewManager(url string, config amqp.Config) (manager IConnectionManager, err error) {
if config.Heartbeat <= 0 {
config.Heartbeat = DefaultHeartbeat
Expand Down Expand Up @@ -78,7 +77,8 @@ func NewManager(url string, config amqp.Config) (manager IConnectionManager, err
return
}

//CreateChannel creates the channel with connection from inside the map.
//CreateChannel creates the channel with connection that has been initialized before.
//CreateChannel initialize channel based on type of channel in the input.
func (p *ConnectionManager) CreateChannel(typeChan uint64) (channel *amqp.Channel, err error) {
switch typeChan {
case Producer:
Expand Down
2 changes: 1 addition & 1 deletion manager_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build integration

package rabbitmq
package amqpwrapper

import (
"errors"
Expand Down
4 changes: 3 additions & 1 deletion mock_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package rabbitmq
// +build integration

package amqpwrapper

import amqp "github.com/streadway/amqp"
import mock "github.com/stretchr/testify/mock"
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rabbitmq
package amqpwrapper

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rabbitmq
package amqpwrapper

func isNotValidTypeChan(typeChan uint64) bool {
return typeChan == 0 || typeChan > 2
Expand Down

0 comments on commit 7ab711b

Please sign in to comment.