Posting to IRC using ActiveMQ

Previously I wrote about querying your app using IRC and IRCCat. Well, that's not all IRCCat can be used for. It can also allow your application or platform to talk to you and let you know what's up. A source code commit, a user logging in or a server dying can all be pretty interesting information, and it's really easy to hook these into IRC using IRCCat.

The IRCCat examples of sending notifications to IRC all seem to work around using netcat to pipe data across the network to the IRCCat process. My preference is to use a small Ruby script and a message bus to deliver messages to the process. Of course, I already have ActiveMQ setup so I don't have much extra overhead doing things this way.

#! /usr/bin/env ruby

STDOUT.sync = true

require 'rubygems'
require 'smqueue'
require 'yaml'
require 'socket'

puts "Starting..."

messages = SMQueue(:name => "/queue/irc.outgoing", :host => "mq.domain.com", :reliable => true, :adapter => "StompAdapter")

messages.get do |job|
  message = YAML.parse(job.body).transform
  puts "Posting #{message['text']} in #{message.headers['message-id']}."
  irc = TCPSocket.open('localhost', '12345')
  irc.send("#{message['text']}\r\n", 0)
  irc.close
  puts "Posted #{message.headers['message-id']}."
end

With that running on the same box as IRCCat your other processes can now just put messages onto the IRC queue and they'll be posted to IRC. If IRCCat isn't running, they'll be stored in the queue until it is and then get posted.

I like this approach because the various other processes don't need to know which server / port IRCCat is running on, they just talk to the message queue - which is made easy by SMQueue.

Leave feedback...

  1. Hmm… maybe we could do an SMQueue IRC adapter too? :)

Commenting is closed for this article.

About the boy

A picture of Craig in grayscale

Craig Webster is a software engineer living in London. He usually works with Ruby although sometimes he sneaks in some Erlang or JavaScript. He's into rock climbing, snowboarding, skating, photography and fencing. Yes, this does mean he has a sword.

Near here you'll find Craig's homepage, contact details, PGP key and keysigning policy, and talks.

Licence

The entire content of this blog is public domain. Use it however you fancy. You don't even need to attribute it to me, although it would be nice if you did. Just don't sue me and we'll all be happy.

I Work With Rails

Recommend Me

My Travels

I go places. Do you go places too? Let's meet up!.