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

W/o Durability

class
  ACTIVEMQ_SAMPLE

create
  make

feature

  make
    local
      socket: NETWORK_STREAM_SOCKET

    do
      create socket.make_client_by_port (61613, "localhost")

      socket.connect

      socket.put_string ("CONNECT%N%N%U")

      -- Skip the CONNECTED frame
      from
        socket.read_line
      until
        socket.last_string.is_equal ("%U")
      loop
        socket.read_line
      end

      socket.put_string ("SUBSCRIBE%Ndestination:/topic/SampleTopic%N%Nack:auto%N%N%U")

      -- Seek to the body of the MESSAGE frame
      from
        socket.read_line
      until
        socket.last_string.is_empty
      loop
        socket.read_line
      end

      socket.read_line

      print (socket.last_string)

      put_new_line

      socket.put_string ("DISCONNECT%N%N%U")

      socket.close
    end

end

W/ Durability

class
  ACTIVEMQ_SAMPLE

create
  make

feature

  make
    local
      socket: NETWORK_STREAM_SOCKET

    do
      create socket.make_client_by_port (61613, "localhost")

      socket.connect

      socket.put_string ("CONNECT%Nclient-id:SampleClient%N%N%U")

      -- Skip the CONNECTED frame
      from
        socket.read_line
      until
        socket.last_string.is_equal ("%U")
      loop
        socket.read_line
      end

      socket.put_string ("SUBSCRIBE%Ndestination:/topic/SampleTopic%N%Nack:auto%Nactivemq.subscriptionName:SampleSubscription%N%N%U")

      -- Seek to the body of the MESSAGE frame
      from
        socket.read_line
      until
        socket.last_string.is_empty
      loop
        socket.read_line
      end

      socket.read_line

      print (socket.last_string)

      put_new_line

      socket.put_string ("DISCONNECT%N%N%U")

      socket.close
    end

end

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