How to Receive a Message from an Apache ActiveMQ Topic with Open Dylan

W/o Durability

activemq-sample.dylan

module: activemq-sample

define function main (name :: <string>, arguments :: <vector>)
  start-sockets();

  let sock = make(<TCP-socket>, host: "localhost", port: 61613);

  write(sock, "CONNECT\n\n\0");

  force-output(sock;

  let line = read-line(sock);

  ; Skip the CONNECTED frame
  until (string-equal?(line, "\0"))
    line := read-line(sock);
  end until;

  write(sock, "SUBSCRIBE\ndestination:/topic/SampleTopic\n\nack:auto\n\n\0");

  force-output(sock);

  line := read-line(sock);

  ; Seek to the body of the MESSAGE frame
  until (string-equal?(line, ""))
    line := read-line(sock);
  end until;

  format-out("%s\n", read-line(sock));

  write(sock, "DISCONNECT\n\n\0");

  close(sock);
end function;

main(application-name(), application-arguments());

activemq-sample.lid

library: activemq-sample
files: library
       activemq-sample

library.dylan

module: dylan-user

define library activemq-sample
  use common-dylan;

  use io;
  
  use network;

  use strings;
  
  export activemq-sample;
end library;

define module activemq-sample
  use common-dylan;

  use format-out;

  use streams;

  use sockets;

  use strings;
end module;

W/ Durability

activemq-sample.dylan

module: activemq-sample

define function main (name :: <string>, arguments :: <vector>)
  start-sockets();

  let sock = make(<TCP-socket>, host: "localhost", port: 61613);

  write(sock, "CONNECT\nclient-id:SampleClient\n\n\0");

  force-output(sock;

  let line = read-line(sock);

  ; Skip the CONNECTED frame
  until (string-equal?(line, "\0"))
    line := read-line(sock);
  end until;

  write(sock, "SUBSCRIBE\ndestination:/topic/SampleTopic\n\nack:auto\nactivemq.subscriptionName:SampleSubscription\n\n\0");

  force-output(sock);

  line := read-line(sock);

  ; Seek to the body of the MESSAGE frame
  until (string-equal?(line, ""))
    line := read-line(sock);
  end until;

  format-out("%s\n", read-line(sock));

  write(sock, "DISCONNECT\n\n\0");

  close(sock);
end function;

main(application-name(), application-arguments());

activemq-sample.lid

library: activemq-sample
files: library
       activemq-sample

library.dylan

module: dylan-user

define library activemq-sample
  use common-dylan;

  use io;
  
  use network;

  use strings;
  
  export activemq-sample;
end library;

define module activemq-sample
  use common-dylan;

  use format-out;

  use streams;

  use sockets;

  use strings;
end module;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s