14 Replies Latest reply on May 21, 2009 8:56 AM by cpslo1999

    Multiple clients and message types - selectors?

      I am designing a system that will generate notifications of different types of events and will have different systems subscribed to it. All clients will only be interested in a subset of these events, although overlapping interest between clients is fully expected. Also, I need to add the ability to publish (or re-publish) certain events to individual clients to the exclusion of others that are generally interested the same published events.

      I basically control both the notifying system as well as the client systems so most options are available to me. All of them are currently using EJB3 annotations.

      I had originally thought that I could use a single topic to publish all notifications and have the clients use selectors to select only the event types interesting to each. In order to provide the ability to publish to specific clients, I thought I could use selectors there as well. Unfortunately, it appears that having dynamic or at least a programmatic selector is not possible (at least I haven't found a way to do this yet).

      So the question is two-fold.
      1) Is there a way to set/change a MDB selector programmatically?
      2) Is there a better approach to creating this communication scheme?

      Thanks,

      Josh

        • 1. Re: Multiple clients and message types - selectors?
          clebert.suconic

          I would use a topic and subscribers (durable if is the case) with selectors.

          • 2. Re: Multiple clients and message types - selectors?

            That's where I was headed...

            I need to be able to also (re)send a notification to only one client (preferably using the same mechanism). I had thought I could have a selector that looks for my notifications of interest and/or notifications with a property set to the client's ID, but I don't know if it is possible to configure selectors that way (or better if there is another way to identify specific clients when I send messages).

            Can I do this with topics?

            • 3. Re: Multiple clients and message types - selectors?
              clebert.suconic

              I don' t understand what you are trying to achieve... mainly here:

              - I need to be able to also (re)send a notification to only one client



              Can you try abstracting your business and explain what you are trying to achieve in pure JMS terms?

              • 4. Re: Multiple clients and message types - selectors?

                Sure (and thanks so much for your help!).

                I have what amounts to a store-and-forward system (let's call it the SAF for this discussion). It feeds multiple client systems. The SAF receives a number of files from different, external systems, which it stores and makes available via HTTP. The clients are each interested in some subset of these files (the subsets can and will overlap).

                I am trying to design a communications mechanism that will allow the SAF to send asynchronous notifications to the clients when interesting files arrive. In most cases this will be done as the files arrive (perfect for a topic with client-side selectors), however, I also need to build in the ability to target one particular client from the SAF and re-play the notifications. Say I add a new client system, I need to be able to tell the SAF to send notifications to that new client for files that were received before the client was added (back-filling). Also, if a processing algorithm changes on one of the clients, I may need to send notifications for files that the client had processed once before (re-sending).

                It is really this notion of targeting a single client that has me befuddled. Adding a new queue for each client administratively seems like a tight coupling and a fair amount of manual configuration overhead. Using a pure topic, I can't figure out how to provide this secondary feature of targeted playback.

                Did that clarify the situation enough?

                • 5. Re: Multiple clients and message types - selectors?
                  clebert.suconic

                  I think you need a Topic with subscribers and selectors for the regular day-to-day operation.

                  And you also probably need a request mechanism on receiving the initial information. Maybe the client creates a temporary queue, send a request to receive the initial information, and the initial information comes on that queue.


                  On the day-by-day basis you would have the durable selector receiving the information.


                  I feel like spoiling the surprise suggesting you this :-) , but there is a great JMS example on JBoss Messaging 2 which explains what I' m suggesting to you in terms of Request-Reply:

                  svn co http://anonsvn.jboss.org/repos/messaging/trunk/examples/jms/request-reply


                  Look at the readme.. it bring a lot of information.


                  if you want to run the example:


                  svn co http://anonsvn.jboss.org/repos/messaging/trunk messaging
                  cd messaging
                  ant
                  cd examples/jms/request-reply
                  ant

                  • 6. Re: Multiple clients and message types - selectors?
                    timfox

                    If you want a topic subscriber to receive all messages of a certain type and also receive all messages sent directly to it, can't you assign each subscriber an id and use a selector like:

                    messageType='FOO' OR destinationID=myid
                    


                    • 7. Re: Multiple clients and message types - selectors?

                      clebert:
                      Thanks for the pointer, I've checked out the sample and started to look it over.

                      timfox:
                      If I deploy my app in an .ear file, wouldn't I have to muck around with the embedded deployment descriptors in each client in order to assign the unique IDs? I would love to be able to modify the selector at runtime so I can my application's existing configuration mechanisms, is that possible?

                      • 8. Re: Multiple clients and message types - selectors?
                        clebert.suconic

                         

                        "timfox" wrote:
                        If you want a topic subscriber to receive all messages of a certain type and also receive all messages sent directly to it, can't you assign each subscriber an id and use a selector like:

                        messageType='FOO' OR destinationID=myid
                        


                        It's a good idea but I don't think that would work for cpslo1999.

                        Say you send messageType="A", destinationID=myID

                        The other subsriber with messageType="A" , destinationID=2 will also receive this message, and from what I read this is not what he wanted.

                        It would be an idea though.

                        • 9. Re: Multiple clients and message types - selectors?
                          timfox

                          I guess I'm not understanding what the user is trying to achieve here.

                          Also I don't understand why the selector needs to be dynamic. The id is the client id which can be in the deployment xml.

                          • 10. Re: Multiple clients and message types - selectors?

                            Thank you guys for your help here!

                            timfox: Is there a way to specify the selector outside of the .ear file? I'm hesitant to require that the deployer of my application unzip the ear, change an ID, and rezip it. I would rather use a identical application package on our production and test servers and have other files, descriptors, or database settings tweaked to account for the environment. If that is possible with selectors, then that sounds like the least complicated solution.

                            • 11. Re: Multiple clients and message types - selectors?

                              I think I can use Tim's suggestion (if I can find a way to assign the selector outside the ear).

                              Something like:

                              clientID is NULL AND feed in ('feed1', 'feed2')
                              OR
                              clientID = 'myClientID' AND feed in ('feed1', 'feed2')


                              So is there a way for me to assign the clientID other than in the annotations of the MDB or in the embedded deployment descriptor?

                              • 12. Re: Multiple clients and message types - selectors?
                                timfox

                                Well, as per JMS spec, JBoss Messaging lets you set the client id programmatically after creating a connection, and you can define and set selectors when creating a consumer.

                                However if you're using MDBs it's different, bear in mind MDBs are not part of JBM, they're part of the app server, and follow a different contract defined in the JEE spec. I'm not sure if that is possible, but you're best bet is to ask in the EJB forum.

                                • 13. Re: Multiple clients and message types - selectors?

                                  OK, thanks again for all your help. I'll post over there and see what I can dig up.

                                  • 14. Re: Multiple clients and message types - selectors?