config

package module
v3.0.0 Latest Latest
Warning

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

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

README

Gogix - Golang HTTP client

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 Reconnection rabbitmq nonssl

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 Reconnection 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.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 wabbit.Channel wapper

func (*Channel) IsClosed

func (ch *Channel) IsClosed() bool

This function is function to Close connection

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 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