#!/bin/bash

# squawk (simple queues using awk)
# 
# Author:  Andrew Birkett <andy@nobugs.org>
# Website: http://www.nobugs.org/developer/squawk
# Date:    10 May 2008
#
# Example:  echo 'my message' | ./produce localhost 61613 /queue/a
#
# .. where stomphost is running ActiveMQ with a stomp listener.
#
# This script succeeds (exit code 0) if the broker acknowledges our
# message, other we fail.

if [[ $# != 3 ]]; then
  echo "Usage: produce stomphost stompport queuename"
  exit 1
fi

MARKER=SomeUniqueishString

(
  echo -ne 'CONNECT\n\n\0000'
  echo -ne "SEND\ndestination:$3\n"
  echo -ne "receipt:$MARKER\n"
  echo -ne "\n"
  cat
  echo -ne "\0000"
  echo -ne "DISCONNECT\n\n\0000"
) | nc $1 $2 | grep $MARKER 2>&1 >/dev/null
