diff --git a/.gitignore b/.gitignore index 9db5135..d28f4dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ # exclude binary -rio +rabbitio -# exclude dirs +# exclude build and example files/dirs data/ build/ vendor/ +message* diff --git a/LICENSE b/LICENSE index d645695..86892c6 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2018 Meltwater Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index 34bb763..34ec517 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION := $(shell git describe --tags) BUILD_DIR?=$(shell pwd)/build -NAME=rio +NAME=rabbitio DIRECTORIES=./ ./cmd ./rmq ./file all: tools deps test diff --git a/README.md b/README.md index c61ed83..6d1713c 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,94 @@ -# Rabbit IO - Work in Progress -This is a tool to support backup and restoring of RabbitMQ messages, currently work in progress and might not be functional +# Rabbit IO +This is a tool to support backup and restoring of RabbitMQ messages -## Requirements +## Installing -You will need following to build `rabbitio` locally: +#### Download binary +Pick your archtype from [Releases](https://github.com/meltwater/rabbitio/releases) and download, in addition you'll need to set the binary to be executable. -- [Golang](https://golang.org/dl/) -- [dep](https://github.com/golang/dep) +Example with `linux-amd64` and version `v0.5.1`: +``` +wget https://github.com/meltwater/rabbitio/releases/download/v0.5.1/rio-v0.5.1-linux-amd64 -O rabbitio +chmod +755 rabbitio +``` -## Getting started +#### Using `go get` +``` +go get -u github.com/meltwater/rabbitio +``` -If you plan to work on `rabbitio` you will need to: +## How to use RabbitIO -1. Create directories +After installing rabbitio, you can quickly test out `rabbitio` by using [docker-compose](https://docs.docker.com/compose/install/) + +Included is a docker-compose file to set up local rabbitmq. ``` -mkdir -p $GOPATH/src/github.com/meltwater +cd $GOPATH/src/github.com/meltwater +docker-compose up -d +``` +Go to your now running [local rabbit](http://localhost:15672) and create example exchange: `rabbitio-exchange` and queue `rabbitio-queue`, +then bind the queue to the exchange. + +#### Publish your first message +``` +echo "My first message" > message && tar cfz message.tgz message # creates message.tgz +rabbitio in -e rabbitio -q rabbitio -f message.tgz +``` +This will publish your first message into `rabbitio-exchange` and you'll see your message in the queue `rabbitio-queue` + +#### Consume your first message +``` +$ mkdir data +$ rabbitio out -e rabbitio-exchange -q rabbitio-queue -d data/ +2018/03/15 15:37:35 RabbitMQ connected: amqp://guest:guest@localhost:5672/ +2018/03/15 15:37:35 Bind to Exchange: "rabbitio-exchange" and Queue: "rabbitio-queue", Messaging waiting: 1 +^C Interruption, saving last memory bits.. +2018/03/15 15:37:45 Wrote 203 bytes to data/1_messages_1.tgz +2018/03/15 15:37:45 tarball writer closing ``` +We interrupt when the queue is empty by directly using a combination of `CTRL + C` once. This will save the last bits and ack the message. + + +## Detailed Usage +``` +$ rabbitio +Rabbit IO will help backup and restore your messages in RabbitMQ + +Usage: + rabbitio [command] + +Available Commands: + help Help about any command + in Publishes documents from tarballs into RabbitMQ exchange + out Consumes data out from RabbitMQ and stores to tarballs + version Prints the version of Rabbit IO + +Flags: + -e, --exchange string Exchange to connect to + -h, --help help for rabbitio + -p, --prefetch int Prefetch for batches (default 100) + -q, --queue string Queue to connect to + -r, --routingkey string Routing Key, if specified will override tarball routing key configuration (default "#") + -t, --tag string AMQP Client Tag (default "Rabbit IO Connector ") + -u, --uri string AMQP URI, uri to for instance RabbitMQ (default "amqp://guest:guest@localhost:5672/") + +Use "rabbitio [command] --help" for more information about a command. -2. Clone `rabbitio`: ``` + + +## Contributing + +If you plan to work on `rabbitio` you will need [Golang](https://golang.org/dl/). PRs are welcome as well as implementation discussions. + +**Clone `rabbitio`** +``` +mkdir -p $GOPATH/src/github.com/meltwater cd $GOPATH/src/github.com/meltwater git clone git@github.com:meltwater/rabbitio.git ``` -3. Make: +#### Building ``` cd rabbitio make && make build @@ -35,6 +100,7 @@ For any bug reports or change requests, please create a Github issue or submit a Also feel free to drop a line to the maintainers: -- Joel ([@vorce](https://github.com/vorce), [joel.carlbark@meltwater.com](mailto:joel.carlbark@meltwater.com)) -- Stian ([@stiangrindvoll](https://github.com/stiangrindvoll), [stian.grindvoll@meltwater.com](mailto:stian.grindvoll@meltwater.com)) +- Joel ([@vorce](https://github.com/vorce)) +- Stian ([@stiangrindvoll](https://github.com/stiangrindvoll)) - Team Blacksmiths ([all.blacksmiths@meltwater.com](mailto:all.blacksmiths@meltwater.com)) +2 \ No newline at end of file diff --git a/cmd/in.go b/cmd/in.go index cf199be..3ee84af 100644 --- a/cmd/in.go +++ b/cmd/in.go @@ -16,6 +16,7 @@ package cmd import ( "sync" + "errors" "github.com/meltwater/rabbitio/file" "github.com/meltwater/rabbitio/rmq" @@ -31,8 +32,11 @@ var inCmd = &cobra.Command{ Use: "in", Short: "Publishes documents from tarballs into RabbitMQ exchange", Long: `Specify a directory or file and tarballs will be published.`, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { + if fileInput == "" { + return errors.New("please specify a tarball or directory with tarballs using the -f flag") + } channel := make(chan rmq.Message, prefetch) var wg sync.WaitGroup @@ -45,10 +49,11 @@ var inCmd = &cobra.Command{ go rabbit.Publish(channel, override) path.Send(channel) rabbit.Close() + return nil }, } func init() { RootCmd.AddCommand(inCmd) - inCmd.Flags().StringVarP(&fileInput, "file", "f", ".", "File is specified as either file or directory to restore into RabbitMQ") + inCmd.Flags().StringVarP(&fileInput, "file", "f", "", "File is specified as either file or directory to restore into RabbitMQ") } diff --git a/cmd/root.go b/cmd/root.go index b6095e2..e2965f7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,7 +29,7 @@ var ( // RootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ - Use: "rio", + Use: "rabbitio", Short: "Rabbit IO will help backup and restore your messages in RabbitMQ", // Uncomment the following line if your bare application // has an action associated with it: