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

W/o Durability

-module(activemq_sample).

-export([main/0]).

-import(io, [fwrite/2]).
-import(stomp, [connect/4, disconnect/1, on_message/2, subscribe/2]).

main() ->
  Conn = connect("localhost", 61613, "", ""),

  subscribe("/topic/SampleTopic", Conn),

  F = fun(Msg) -> fwrite("~p~n", [Msg]) end,

  on_message(F, Conn),

  disconnect(Conn).

W/ Durability

-module(activemq_sample).

-export([main/0]).

-import(io, [fwrite/2]).
-import(stomp, [connect/5, disconnect/1, on_message/2, subscribe/3]).

main() ->
  Conn = connect("localhost", 61613, "", "", [{"client-id", "SampleClient"}]),

  subscribe("/topic/SampleTopic", Conn, [{"activemq.subscriptionName", "SampleSubscription"}]),

  F = fun(Msg) -> fwrite("~p~n", [Msg]) end,

  on_message(F, Conn),

  disconnect(Conn).
Advertisements

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.