stompgem / stomp

A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support.
http://stomp.github.com
Apache License 2.0
152 stars 80 forks source link

Consume existing messages on topic #96

Closed johntdyer closed 10 years ago

johntdyer commented 10 years ago

I am trying to connect to a topic which may already have messages in the queue. I would expect stomp to fetch existing messages from the queue when connecting, however it only seems to process new messages sent after the client started it's connection. This seems to "orphan" these messages which existed prior to the subscription. Perhaps I am misunderstanding something ?

My example is pretty simple.

  client = Stomp::Client.new("admin", "admin", "192.168.56.2", 61613)
  client.subscribe('/topic/VirtualTopic.Provisioning', {:ack => "client", "activemq.prefetchSize" => 1, "activemq.exclusive" => true }) do |msg|
    puts "received: #{message.body} on #{message.headers['destination']}"
    client.ack(message)
  end
  client.join
  client.close

Thanks !

-John

gmallard commented 10 years ago

Hi John - Topics are not queues.

I think there is indeed a misunderstanding on your part about how 'topics' actually work.

With ActiveMQ (and other brokers) you will only receive messages that are published to a 'topic' when there is a currently active 'subscribe'. You will not receive messages that have been previously published. That is normal 'pub-sub' behavior for 'topics'.

For specific ActiveMQ details see:

https://activemq.apache.org/how-does-a-queue-compare-to-a-topic.html

In particular, note the last sentence of the "Topics" section.

Other brokers (Apollo, RabbitMQ) behave similarly.

For a more generalized description of 'pub-sub' see:

http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern

If you are satisfied with this reply, please close this issue. Otherwise reply here.

Regards, Guy

johntdyer commented 10 years ago

Thanks!