• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Publish/Subscribe with multiple subscribers (like a jms topic)

 
Cameron Dalton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<edit>
It was pointed out that publisher/subscriber is not the right terminology for what I'm describing. Please substitute producer/consumer instead.
</edit>


Good afternoon,

I'm trying to fashion a module following the publish/subscribe methodology. The idea is to publish messages which ALL subscribers will consume (rather than just one subscriber). This is like a JMS topic but without the overhead of JMS.

I've tried doing this with wait()s and notifyAll()s but ran into trouble because synchronization is required to obtain the lock and that limits the messages to being processed by one subscriber.

I also looked into BlockingQueue which is nearly exactly what I want, although again the queue.take() will only alert one subscriber per message.

What do you think? Does anyone have any ideas? I'd like to do this with just one collection or resource if possible, rather than having one queue per subscriber, but I can go to that model if necessary.

Thanks for your ideas.
[ December 15, 2008: Message edited by: Cameron Dalton ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not very knowledgeable on the subject, so take anything I say with a grain of salt.

I thought the whole idea of the publish-subscribe pattern was that you can have many subscribers to a single publisher. Each subscriber registers with the publisher, who maintains a list of who is interested.

Then, when a message comes out, the publisher send a copy of the message to everyone interested.

The way you are describing it, it sounds like your publisher is putting one copy of the message in one spot, and you want each subscriber to come and read that only copy. I think this is wrong.

Each subscriber should have a way to receive the message, just like each subscriber of a magazine has a mail box. It wouldn't make sense for "Time" magazine to only print one copy of the magazine and expect everyone to come to <insert city here> to read the only copy in existance, would it?
 
Cameron Dalton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose a more accurate term might be producer/consumer rather than publisher/subscriber. The scenario I described is what I need because I need the subscribers to block until a message is produced, which excludes the possibility of using an event-type callback function (unless there's something to that I'm not aware of).

Thanks for your input - good catch on my bad terminology.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I ask why you're staying away from JMS? It's designed to do exactly this
 
Cameron Dalton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martijn Verburg:
Can I ask why you're staying away from JMS? It's designed to do exactly this


I'm hoping to avoid all the overhead of JMS connections and all the extra threading that goes along with them. This will only take place on a single server, not across multiple servers.
 
Cameron Dalton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I discovered a solution using wait() and notifyAll() that I overlooked originally.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic