README

README
Last Update: 2015-12-11 10:31:00 +0100

mgp.rb - Interfacing Enterprise Messaging Gateway (EMG) using Ruby

More information

For more information on Enterprise Messaging Gateway (EMG), please visit www.nordicmessaging.se. If you need technical assistance, email support@infoflexconnect.se.

Examples

Example showing how to send a message

require 'mgp'

HOST='127.0.0.1'
PORT=7185
USERNAME='emguser'
PASSWORD='secret'
ROUTE='smsc'
DESTADDR='4612345'
MESSAGE="Hello world"

client = EMG::MGP.new
client.connect(HOST, PORT, :username => USERNAME, :password => PASSWORD) {
      |client|
      sms = EMG::SMS.new( {
              EMG::MGP::OPTION_DESTADDR => DESTADDR,
              EMG::MGP::OPTION_MESSAGE => MESSAGE,
              EMG::MGP::OPTION_ROUTE => ROUTE } )
      (retcode, messageid) = client.send_message(sms)
      if retcode == EMG::MGP::ERR_OK
              puts "id = #{messageid}"
      else
              puts "error #{retcode}"
      end
}

Example showing how to receive a message

require 'mgp'

HOST='127.0.0.1'
PORT=7185
USERNAME='emguser'
PASSWORD='secret'
ROUTE='ebe'
DESTADDR='4612345'
MESSAGE="Hello world"

client = EMG::MGP.new
client.connect(HOST, PORT)
client.logon(USERNAME, PASSWORD) { |client|
      (retcode, queuesize, sms) = client.get_first_message
      if sms.nil?
              puts "No message received, retcode #{retcode}"
      else
              client.confirm_message(sms.messageid, EMG::MGP::ERR_OK)
              puts "id = #{sms.messageid}"
              puts "message = #{sms.options[EMG::MGP::OPTION_MESSAGE]}"
      end
}

Example showing how to perform a simple benchmark test

require 'mgp'

HOST='127.0.0.1'
PORT=7185
USERNAME='emguser'
PASSWORD='secret'
ROUTE='dummy'
DESTADDR='4612345'
MESSAGE="Hello world"

client = EMG::MGP.new
client.connect(HOST, PORT)
client.logon(USERNAME, PASSWORD)
sms = EMG::SMS.new( {
      EMG::MGP::OPTION_DESTADDR => DESTADDR,
      EMG::MGP::OPTION_MESSAGE => MESSAGE,
      EMG::MGP::OPTION_ROUTE => ROUTE } )

iters = 100
start = stop = 0
loop do
      puts "Testing #{iters} messages"
      start = Time.now
      iters.times { (retcode, messageid) = client.send_message(sms) }
      stop = Time.now
      break if stop - start > 4
      iters *= 2
end 
mps = iters * 1.0 / (stop - start)
puts "Messages: #{iters}"
puts "Runtime: #{stop - start} s"
puts "That gives %.0f mps" % mps

client.logoff