Tag Archives: Apache ActiveMQ

How to Receive a Message from an Apache ActiveMQ Topic with Node.js

W/o Durability

const stompit = require('stompit');

stompit.connect({ host: 'localhost', port: 61613 }, (err, client) => {
    client.subscribe({ destination: '/topic/SampleTopic' }, (err, msg) => {
        msg.readString('UTF-8', (err, body) => {
            console.log(body);

            client.disconnect();
          });
      });
  });

W/ Durability

const stompit = require('stompit');

stompit.connect({ 'client-id': 'SampleClient', host: 'localhost', port: 61613 }, (err, client) => {
    client.subscribe({ 'activemq.subscriptionName': 'SampleSubscription', destination: '/topic/SampleTopic' }, (err, msg) => {
        msg.readString('UTF-8', (err, body) => {
            console.log(body);

            client.disconnect();
          });
      });
  });
Advertisements

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;

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

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:SampleQueue\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;

How to Send a Message to an Apache ActiveMQ Topic with Open Dylan

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");

  write(sock, "SEND\ndestination:/topic/SampleTopic\n\nSimples Assim\0");

  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;

  export activemq-sample;
end library;

define module activemq-sample
  use common-dylan;

  use streams;

  use sockets;
end module;

How to Send a Message to an Apache ActiveMQ Queue with Open Dylan

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");

  write(sock, "SEND\ndestination:SampleQueue\n\nSimples Assim\0");

  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;

  export activemq-sample;
end library;

define module activemq-sample
  use common-dylan;

  use streams;

  use sockets;
end module;

How to Receive a Message from an Apache ActiveMQ Topic with JavaScript

W/o Durability

const ws = new WebSocket('ws://localhost:61614', 'stomp');

ws.onopen = () => {
    ws.send('CONNECT\n\n\0');

    ws.send('SUBSCRIBE\ndestination:/topic/SampleTopic\n\nack:auto\n\n\0');

    ws.send('DISCONNECT\n\n\0');
  };

ws.onmessage = (e) => {

    if (e.data.startsWith('MESSAGE'))
      console.log(e.data);

  };

W/ Durability

const ws = new WebSocket('ws://localhost:61614', 'stomp');

ws.onopen = () => {
    ws.send('CONNECT\nclient-id:SampleClient\n\n\0');

    ws.send('SUBSCRIBE\ndestination:/topic/SampleTopic\n\nack:auto\nactivemq.subscriptionName:SampleSubscription\n\n\0');

    ws.send('DISCONNECT\n\n\0');
  };

ws.onmessage = (e) => {

    if (e.data.startsWith('MESSAGE'))
      console.log(e.data);

  };