Code Monkey home page Code Monkey logo

pyqueue_wrapper's Introduction

pyqueue_wrapper documentation

Summary

This a wrapper that standardizes queue services for:

Sometimes there is a need to utilize multiple queue services, but refactoring code is not an option. With pyqueue_wrapper, one can easily switch between the supported queue services with a configuration file.

Setup Instructions

Install:

pip install https://bitbucket.org/imedicare/pyqueue_wrapper/get/master.zip

Create json config file

Config Example:

{
    "BASENAME": "my_queue",
    "ENV_MODE": "dev",
    "TYPE": "ironio",
    "ironio": {
        "TOKEN": "xxxxxxxxx",
        "PROJECT_ID": "yyyyyyyyyy",
        "MSG_EXPIRES": 1800, // seconds
        "MSG_TIMEOUT": 8400 // seconds
    },
    "sqs": {
        "TYPE": "sqs",
        "AWS": {
            "AWS_ACCESS_KEY": "zzzzzz",
            "AWS_SECRET_KEY": "xxxxxx"
        }
    }
}

Config File Details:

The name of the queue depends on two configuration variables:

  1. BASENAME - name of queue
  2. ENV_MODE - environment suffix used on naming of queue

In this example, the full name of the queue would become my_queue_dev

Be sure to specify the TYPE:
TYPE - the queue service to use (eg: 'sqs' for AWS SQS, 'ironio' for iron.io QS)

Example Usage:

import json
import pyqueue_wrapper

### load configuration file
config = json.loads(open('/path/to/config_file.json')) # see configuration example above
q = pyqueue_wrapper.Queue(config)

### methods
new_message = ({'msg1':'this is a test'})
q.put(new_message)

## get

# iterate through queue
for msg in q:
    print(msg) #Note: will contain 'qid' as reference extra field
# get a single message
received_message = q.get()

## delete
qid = received_message['qid']
q.delete(qid) # Note: not required for AWS SQS, because auto deletes

## clear
q.clear() # clear all messages in queue

pyqueue_wrapper's People

Contributors

mhjohnson avatar

Stargazers

Lateef Jackson avatar

Watchers

Flaviu Simihaian avatar  avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.