Git Product home page Git Product logo

slackmq's Introduction

SlackMQ

Slack can do the heavy lifting of a simple Message Queue. When a message is received, it is "locked" while being processed. This keeps other worker bots from processing the message simultaneously.

SlackMQ is suited to high latency message queuing applications due to rate limiting. For a minimalist architecture, leverage the power of SlackMQ and a Slack bot becomes highly available out of the box.

To install:

pip install slackmq

The Slack API allows pins to be added once per message per channel. Also, reactions and stars can be added to a message once per bot. For example, a person or bot cannot pin a message that has already been pinned. A user or bot cannot give a post a thumbs up twice. In the UI, if you try, the action is revoked. In the API, an exception is thrown.

SlackMQ workflow

Slack can be made to behave like a basic Message Queuing system by using pins to acknowledge (lock) and unacknowledge a message, as demonstrated in the diagram above. Using pins is ideal as this allows "unlimited" bot workers. The Slack RTM API also allows a bot to connect multiple times. With this account concurrency, this method limits the bot to 16 concurrent workers. You may find using a combination of pins, stars and reactions more reliable for low latency messages.

To use SlackMQ, wrap the post acknowledgement around a bot action. Below is an example of how a bot (using the slackbot library) uses SlackMQ to pull from the "queue", i.e, the channel.

from slackmq import slackmq
from slackbot.bot import listen_to
import socket

API_TOKEN = 'SLACK-BOT-API-TOKEN'


@listen_to('hello')
def helloworld(message):
    post = slackmq(API_TOKEN,
                   message.body['channel'], 
                   message.body['ts'])
    if post.ack():
        message.send('Hello from {}.'.format(socket.gethostname()))
        post.unack()

Implementation Examples

Troupe, which is a group of Slack bots working together to control and operate a smart home implements SlackMQ.

Another implementation of SlackMQ is to perform DevOps manoeuvres, such as Remote Management, Continuous Delivery, Canary Deployments and Rolling Updates. In the Troupe example, a Federation of Slack bots can self-update with zero downtime using the SlackMQ library. Watch The Travelling DevOps Troupe in action:

The Travelling DevOps Troupe

slackmq's People

Contributors

meltaxa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

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