config

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Go Mq Reconnect - Rabbitmq Reconnect for golang

Description

The problem face when using rabbitmq in golang is when rabbitmq down, with some reason it will happen.if that happen , we must restart our services that use rabbitmq , and also make our business stop temporary after the service restarted. Go-Mq-Reconnect is a Rabbitmq Recoonect for Golang that will make connection after rabbitmq down .whit this library , no worry rabbit mq restarted,because our service will re-connect to rabbit mq . This Library is based on Wabbit , so after connect the rabbit-mq, the syntax will be same with wabbit . Go-Mq-Reconnect will can handle :

  • Create reconect rabbitmq non ssl
  • Create reconect rabbitmq ssl

Installation

go get -u github.com/platogo/go-amqp-reconnect

Then Import it :

import reConnect "github.com/doniantoro/go-mq-reconnect"

Usage

Making a simple Reconection rabbitmq non-ssl

The below example will Connect to rabbitmq non-ssl:

// Create a new connection of non-ssl connection rabbit mq
conn, err := reConnect.NewRabbitMqConfig().Rabbitmq("amqp://127.0.0.1:5672")
if err != nil{
	panic(err)
}

Making a simple Reconection rabbitmq ssl

The below example will Connect to rabbitmq ssl,ssl key can generate on Openssl:

// Create a new connection of ssl connection rabbit mq
conn, err := reConnect.NewRabbitMqConfig().RabbitmqSsl("amqp://127.0.0.1:5673", "server.crt", "server.key", "ca.crt")
	if err != nil {
		log.Panic(err)
	}

How to run example

to run example,you can run rabbitmq first, if dont have rabbit mq , can use my docker compose , with command :

  • non-ssl

    //go to directory
    cd demo/non-ssl/
    
    //optional if you dont have rabbitmq
    docker-compose.yml up -d
    
    //if you run with your own rabbitmq , you need change port on demo/non-ssl/main.go ,
    // default usually 5672,then run the program with command
    go run demo/non-ssl/main.go
    
  • ssl

    //go to directory
    cd demo/ssl/
    
    //optional if you dont have rabbitmq
    docker-compose -f ./demo/ssl/docker-compose.yml up -d
    
    //if you run with your own rabbitmq , you need change port on demo/ssl/main.go,
    // default usually 5672,then run the program with command
    go run demo/ssl/main.go
    

Help and docs

We use GitHub issues only to discuss bugs and new features. For support please refer to:

License


Copyright 2023, Doni Antoro

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	wabbit.Channel
	// contains filtered or unexported fields
}

Channel amqp.Channel wapper

func (*Channel) Consume added in v0.0.3

func (ch *Channel) Consume(queue, consumer string, opt wabbit.Option) (<-chan wabbit.Delivery, error)

Consume wrap amqp.Channel.Consume, the returned delivery will end only when channel closed by developer

func (*Channel) IsClosed

func (ch *Channel) IsClosed() bool

IsClosed indicate closed by developer

type Config added in v0.0.3

type Config struct {
	Connection Connection
	Channel    Channel
}

type Connection

type Connection struct {
	wabbit.Conn
}

Connection amqp.Connection wrapper

func NewRabbitMqConfig

func NewRabbitMqConfig() *Connection

func (*Connection) Channel

func (c *Connection) Channel() (*Channel, error)

This function is function to re-create channel , after reconnect connection to rabbitmq This function need to be called to re-create channel This function owned by Connection,and will return Connection it self. before call this function , need call NewRabbitMqConfig This function will retry to reconnect every 3 seconds

func (*Connection) Rabbitmq

func (c *Connection) Rabbitmq(uri string) (*Connection, error)

This function is function to reconnect rabbitmq non ssl , this function need parameter rabbit mq host This function owned by Connection,and will return Connection it self. before call this function , need call NewRabbitMqConfig This function will retry to reconnect every 3 seconds

func (*Connection) RabbitmqSsl

func (c *Connection) RabbitmqSsl(uri, certFile, keyFile, caCert, serverName string) (*Connection, error)

This function is function to reconnect rabbitmq ssl , this function need some parameter : - Uri = rabbit mq host - certFile = public key of ssl certificate - keyFile = private key of ssl certificate - caCert = caCert of ssl certificate - serverName= server name that will config in tls This function owned by Connection,and will return Connection it self. before call this function , need call NewRabbitMqConfig This function will retry to reconnect every 3 seconds

Directories

Path Synopsis
demo
ssl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL