4

I am developing a webapp using Spring and there are several other apps that are influenced by the information generated in mine. Basically they want to know when a change has been made in the data I manage. This data can be filtered by a certain A property.

Since the number of apps to "subscribe" to this information is variable, I thought about implementing a JMS publisher/subscriber model in which I create queues according to the filtering A property and then notify of changes to that queue. All subscribers would then receive the notification through their JMS listeners.

Is this scenario even possible? That is, can I embed a JMS queue in my Spring webapp (how?) and can I create these queues dynamically (i.e. I create queues for my A catalogue, then if a new element gets added to that catalogue, a new queue should be created dynamically without human intervention). Or is there any better solution to create this filtering functionality?

MichelReap
  • 5,630
  • 11
  • 37
  • 99
  • 1
    if i am not mistaken you cannot create dynamic queues as and when you want as you create a fixed set of queues on the server machine in any env which you use in your code. thats one drawback for the above design – vikeng21 Jun 16 '14 at 08:42
  • then how would you implement such functionality? Is there a way to filter messages in a single JMS queue? – MichelReap Jun 16 '14 at 08:42

1 Answers1

1

You can use selectors (by property A) instead of creating queue:

http://www.coderanch.com/t/499633/Spring/Configure-Spring-JMS-message-selector

http://docs.oracle.com/cd/E19798-01/821-1841/bncer/index.html

For dynamic queue, see Creating temporary JMS jms topic in Spring

http://docs.oracle.com/javaee/1.4/api/javax/jms/TemporaryQueue.html

Community
  • 1
  • 1
dk14
  • 22,206
  • 4
  • 51
  • 88
  • that seems like the perfect solution I was looking for, I didn't know about the existence of selectors. Does this filering get applied on the server side (i.e. the broker does not send the message that doesn't meet the selector criteria) or on the client side (listener receives all messages then filters those not meeting the selector)? – MichelReap Jun 16 '14 at 09:48
  • yepp, so such selectors cannot be changed after creating listener – dk14 Jun 16 '14 at 10:12
  • im sorry i don't understand your answer in regard to my question – MichelReap Jun 16 '14 at 10:13
  • This filtering applied on the broker side so you have to specify selector when creating listener. If you want to change selector during runtime - you have to create another listener . – dk14 Jun 16 '14 at 10:17
  • Right, but that's a problem of the consuming application ;) Anyway they should be able to recreate listeners in runtime, shouldn't they? i.e. instead of defining a bean they could create a factory and register/unregister the beans dynamically – MichelReap Jun 16 '14 at 10:22