SanRabbit 1.1.1
Provides Easy To Use API, For Rabbit MQ.
License: MIT

# SanRabbit Library

## Dependencies

```bash
1. Install python3 into your local computer
    Please follow Python install instructions mentioned in
    https://www.python.org/downloads/

2. Install rabbit MQ into your local computer
    Please follow the Rabbit MQ installation guide and documentation on how to
    start Rabbit MQ from official webpage given below.
    https://www.rabbitmq.com/download.html#installation-guides

3. Install python module pika.
    pip install python3-pika

```

## Installation

```bash

pip install SanRabbit

```

## Source Code

```bash

Clone the git repository to your local computer.
git clone https://github.ibm.com/santanu-lab/SanRabbit.git

```

## Description

```bash
1. Reding messages from RabbitMQ is often very cumbesome process in python. Devloper has to memorize the steps to deal with Rabbit MQ.

2. SanRabbit library provides simple and easy to use APIs to make the developer life eassy.

3. Within 3 lines of code data from message Queue can be reterived.

4. It provides way to isolate the business logic from MQ access logic.

5. Business logic can be encapsulated in a python function and the function can be passed as callback function to SanRabbit Library.

7. SanRabbit Library takes care of auto configuring your messag Queue, exchange, MQ Channel etc. Hence Devloper or system administrator need to spend their precious time in configuring Rabbit MQ.

```

## Usage

```bash

Step :1: Create configuration JSON.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Configuration file can be created manually with following JSON key.

    {
        "host_name": "localhost",
        "config_items": {
            "exchange_name": "",
            "exchange_type": "",
            "route_key": "",
            "queue_name": ""
        }
    }

Alternatively, the Library has auto create facitliy will try to build one for you, with file name "san-rabbit-config.json".

Step :2: Steps to Use the Library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    i) Import Library to your code
    from SanRabbit.SanRabbitController import SRController

    ii) Create a controller object by passing config JSON
    rabbit = SRController('san-rabbit-config.json')

    iii) Call to connect method from controller class
    rabbit.connectToSanRabbit(callToMyBusinessFunction)

    here , callToMyBusinessFunction() is a Call Back function which should have 
    your business functionality to consume the data read from Rabbit MQ.

    this function should have 4 parameters.

    e.g:
    def callToMyBusiness(ch, method, properties, body):
        print("Message...")
        message = str(body)[1:]
        print(message)

    SanRabbit will create necessary Queue infrastructure for you and will host your 
    message receiver service for you.

    iv) If you are not sure how to create config JSON then call the SRController 
    without any parameter.

    e.g:
    from SanRabbit.SanRabbitController import SRController
    rabbit.SRController()

    The above code will create a sample san-rabbit-config.json for you, and later 
    you can verify  the JSON and modify accordingly.

Step :3: Sample Code
~~~~~~~~~~~~~~~~~~~~~
Please refer SampleSend.py and SampleReceive.py for detailed code.

```

## Known Issues

```bash

Exception handling module need more refinement. I will provide the list ASAP.

```

## License

```bash

MIT License

Copyright (c) 2020 Santanu Mohapatro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

```

## Author

```bash

Santanu Mohapatro
(mksantanu@me.com)
IBMers can contact me via.
Mail: shmohapa@in.ibm.com
SLACK: @mksantanu

```