GithubHelp home page GithubHelp logo

cymadigan / rabbitmqtools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ramblingcookiemonster/rabbitmqtools

0.0 1.0 0.0 188 KB

PowerShell module containing cmdlets to manage RabbitMQ.

Home Page: http://ramblingcookiemonster.github.io/RabbitMQ-Intro/

License: MIT License

PowerShell 100.00%

rabbitmqtools's Introduction

Build status

RabbitMQTools

This module provides a set of cmdlets to manage RabbitMQ through the REST API. It was originally written by @mariuszwojcik, with slight modifications from @ramblingcookiemonster.

A brief walk through on some basic components of this module are included in the RabbitMQ and PowerShell post.

Instructions

Download, unblock, and copy the module folder to a valid module path.

# Download RabbitMqTools
# https://github.com/RamblingCookieMonster/RabbitMQTools/archive/master.zip
# Unblock the archive
# Copy the RabbitMQTools module to one of your module paths ($env:PSModulePath -split ";")

# Alternatively, with PowerShell 5, or PowerShellGet:
    Install-Module RabbitMQTools

#Import the module
    Import-Module RabbitMQTools -force

#Get commands from the module
    Get-Command -module RabbitMQTools

#Get help for a command
    Get-Help Get-RabbitMQOverview
   
#Can you hit the server?
    Get-RabbitMQOverview -BaseUri "https://rabbitmq.contoso.com:15671" -Credential (Get-Credential)

Example

#Import the module
    Import-Module RabbitMQTools -force

#Define some credentials.  You need an account on RabbitMQ server before we can do this
    $credRabbit = Get-Credential
 
#Convenience - tab completion support for BaseUri
    Register-RabbitMQServer -BaseUri "https://rabbitmq.contoso.com:15671"
 
#I don't want to keep typing those common parameters... we'll splat them
    $Params = @{
        BaseUri = "https://rabbitmq.contoso.com:15671"
        Credential = $credRabbit
    }
 
#Can you hit the server?
    Get-RabbitMQOverview @params
 
#This shows how to create an Exchange and a Queue
#Think of the Exchange as the Blue USPS boxes, and a queue as the individual mailboxes the Exchanges route messages to
    $ExchangeName = "TestFanExc"
    $QueueName = 'TestQueue'
 
#Create an exchange
    Add-RabbitMQExchange @params -name $ExchangeName -Type fanout -Durable -VirtualHost /
 
#Create a queue for the exchange - / is a vhost initialized with install
    Add-RabbitMQQueue @params -Name $QueueName -Durable -VirtualHost /
 
#Bind them
    Add-RabbitMQQueueBinding @params -ExchangeName $ExchangeName -Name $QueueName -VirtualHost / -RoutingKey TestQueue
 
#Add a message to the exchange
    $message = [pscustomobject]@{samaccountname='cmonster';home='\\server\cmonster$'} | ConvertTo-Json
    Add-RabbitMQMessage @params -VirtualHost / -ExchangeName $ExchangeName -RoutingKey TestQueue -Payload $Message
 
#View your changes:
    Get-RabbitMQExchange @params
    Get-RabbitMQQueue @params
    Get-RabbitMQQueueBinding @params -Name $QueueName
 
#View the message we added:
    Get-RabbitMQMessage @params -VirtualHost / -Name $QueueName
    <#
 
        # = the number in the queue
        Queue = name of the queue
        R = whether we've read it (blank when you first read it, * if something has read it)
        Payload = your content.  JSON is helpful here.
 
              # Queue                R Payload
            --- -----                - -------
              1 TestQueue            * {...
    #>
 
#View the payload for the message we added:
    Get-RabbitMQMessage @params -VirtualHost / -Name $QueueName | Select -ExpandProperty Payload

    <#
        JSON output:

        {
            "samaccountname":  "cmonster",
            "home":  "\\\\server\\cmonster$"
        }
    #>

#Example processing the message
    $Incoming = Get-RabbitMQMessage @params -VirtualHost / -Name $QueueName -count 1 -Remove
    $IncomingData = $Incoming.payload | ConvertFrom-Json
    #If something fails, add the message back, or handle with other logic...

    #It's gone
    Get-RabbitMQMessage @params -VirtualHost / -Name $QueueName -count 1
 
    #We have our original data back...
    $IncomingData
 
    #There are better ways to handle this, illustrative purposes only : )
 
#Remove the Queue
    Remove-RabbitMQQueue @params -Name $QueueName -VirtualHost /
 
#Remove the Exchange
    Remove-RabbitMQExchange @params -ExchangeName $ExchangeName -VirtualHost /
 
#Verify that the queueu and Exchange are gone:
    Get-RabbitMQExchange @params
    Get-RabbitMQQueue @params

What can I do with it?

There is a set of cmdlets to manage the server, such as:

  • Get-RabbitMQOverview
  • Get-RabbitMQNode
  • Get-RabbitMQConnection
  • Get-RabbitMQChannel
  • Get-RabbitMQVirtualHost, Add-RabbitMQVirtualHost, Remove-RabbitMQVirtualHost
  • Get-RabbitMQExchage, Add-RabbitMQExchange, Remove-RabbitMQExchange
  • Get-RabbitMQQueue, Add-RabbitMQQueue, Remove-RabbitMQQueue
  • Get-RabbitMQMessage

To learn more about a cmdlet, or to see some examples run get-help cmdlet_name

rabbitmqtools's People

Contributors

mariuszwojcik avatar ramblingcookiemonster avatar gpduck avatar mrhockeymonkey avatar atomicblom avatar gaelcolas avatar jakauppila avatar daenks avatar cilerler avatar jgigler avatar sergeytunnik avatar stuartmoore avatar agsar avatar dchristian3188 avatar

Watchers

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.