AMQP

The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for message-oriented middleware. The defining features of AMQP are message orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and security.[1]

Ref. Wikipedia

Client

With bunny

Gem: bunny

No authenticattion, publish a message:

#!/usr/bin/env ruby

require 'bunny'

options = {
  host: '10.10.10.190',
  port: 5672
}
connection = Bunny.new(options)
connection.start

channel = connection.create_channel
exchange = channel.fanout('logs')

message = ARGV.empty? ? 'Hello World!' : ARGV.join(' ')

exchange.publish(message)
puts " [x] Sent #{message}"

connection.close

AMQPLAIN authentication, direct durable exchange, publish a file retrieved via HTTP:

#!/usr/bin/env ruby

require 'bunny'

options = {
  host: '10.0.0.1',
  port: 5672,
  user: 'username',
  password: 'password'
}
connection = Bunny.new(options)
connection.start

channel = connection.create_channel
exchange = channel.direct('my_channel', durable: true)

message = ARGV.empty? ? 'http://127.0.0.1:8080/file.zip' : ARGV.join(' ')

exchange.publish(message)
puts " [x] Sent #{message}"

connection.close

Ref.:

Last updated